Skip to content

Commit

Permalink
feat(cli): add clap and small cli structure
Browse files Browse the repository at this point in the history
- add ui sub command
  • Loading branch information
naxmefy committed Jul 2, 2024
1 parent a5ca62f commit 50aa98b
Show file tree
Hide file tree
Showing 3 changed files with 284 additions and 2 deletions.
231 changes: 231 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion crates/mms/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ edition.workspace = true
authors.workspace = true
description.workspace = true
documentation.workspace = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
clap = { version = "4.5.8", features = ["derive"] }
mms_tui = { path = "../mms_tui" }
52 changes: 51 additions & 1 deletion crates/mms/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,53 @@
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 => {}
}
}

0 comments on commit 50aa98b

Please sign in to comment.