tendermint_light_node/commands.rs
1//! LightNode Subcommands
2//!
3//! The light client supports the following subcommands:
4//! - `initialize`: subjectively initializes the light node with a given height and hash
5//! - `start`: launches the light client
6//! - `version`: print application version
7//!
8//! See the `impl Configurable` below for how to specify the path to the
9//! application's configuration file.
10
11mod initialize;
12mod start;
13mod version;
14
15use self::{start::StartCmd, version::VersionCmd};
16use crate::commands::initialize::InitCmd;
17use crate::config::LightNodeConfig;
18use abscissa_core::{
19 config::Override, Command, Configurable, FrameworkError, Help, Options, Runnable,
20};
21use std::path::PathBuf;
22
23/// LightNode Configuration Filename
24pub const CONFIG_FILE: &str = "light_node.toml";
25
26/// LightNode Subcommands
27#[derive(Command, Debug, Options, Runnable)]
28pub enum LightNodeCmd {
29 /// The `help` subcommand
30 #[options(help = "get usage information")]
31 Help(Help<Self>),
32
33 /// `intialize` the light node
34 #[options(
35 help = "subjectively initialize the light client with given subjective height and validator set hash"
36 )]
37 Initialize(InitCmd),
38
39 /// `start` the light node
40 #[options(help = "start the light node daemon with the given config or command line params")]
41 Start(StartCmd),
42
43 /// `version` of the light node
44 #[options(help = "display version information")]
45 Version(VersionCmd),
46}
47
48/// This trait allows you to define how application configuration is loaded.
49impl Configurable<LightNodeConfig> for LightNodeCmd {
50 /// Location of the configuration file
51 fn config_path(&self) -> Option<PathBuf> {
52 // Check if the config file exists, and if it does not, ignore it.
53 // If you'd like for a missing configuration file to be a hard error
54 // instead, always return `Some(CONFIG_FILE)` here.
55 let filename = PathBuf::from(CONFIG_FILE);
56
57 if filename.exists() {
58 Some(filename)
59 } else {
60 None
61 }
62 }
63
64 /// Apply changes to the config after it's been loaded, e.g. overriding
65 /// values in a config file using command-line options.
66 ///
67 /// This can be safely deleted if you don't want to override config
68 /// settings from command-line options.
69 fn process_config(&self, config: LightNodeConfig) -> Result<LightNodeConfig, FrameworkError> {
70 match self {
71 LightNodeCmd::Start(cmd) => cmd.override_config(config),
72 _ => Ok(config),
73 }
74 }
75}