-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): add clap and small cli structure
- add ui sub command
- Loading branch information
Showing
3 changed files
with
283 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,52 @@ | ||
use std::path::PathBuf; | ||
|
||
use clap::{Parser, Subcommand}; | ||
use mms_tui::MMSTuiApplication; | ||
|
||
#[derive(Parser)] | ||
#[command(version, about, long_about = None, bin_name = "mms")] | ||
struct Cli { | ||
/// Sets a custom config file | ||
#[arg(short, long, value_name = "FILE")] | ||
config: Option<PathBuf>, | ||
|
||
/// Turn verbose logging on | ||
#[arg(short, long, action = clap::ArgAction::Count)] | ||
verbose: u8, | ||
|
||
#[command(subcommand)] | ||
command: Option<Commands>, | ||
} | ||
|
||
#[derive(Subcommand)] | ||
enum Commands { | ||
UI {}, | ||
} | ||
|
||
fn main() { | ||
println!("Hello, world!"); | ||
let cli = Cli::parse(); | ||
|
||
if let Some(config_path) = cli.config.as_deref() { | ||
println!("Value for config: {}", config_path.display()); | ||
} | ||
|
||
// You can see how many times a particular flag or argument occurred | ||
// Note, only flags can have multiple occurrences | ||
match cli.verbose { | ||
0 => println!("Debug mode is off"), | ||
1 => println!("Debug mode is kind of on"), | ||
2 => println!("Debug mode is on"), | ||
_ => println!("Don't be crazy"), | ||
} | ||
|
||
// You can check for the existence of subcommands, and if found use their | ||
// matches just as you would the top level cmd | ||
match &cli.command { | ||
Some(Commands::UI {}) => { | ||
println!("start terminal ui"); | ||
let tui = MMSTuiApplication::new().expect("default mms tui application"); | ||
println!("{:?}", tui) | ||
} | ||
None => {} | ||
} | ||
} |