Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): add clap and small cli structure #25

Merged
merged 2 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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" }
51 changes: 50 additions & 1 deletion crates/mms/src/main.rs
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 => {}
}
}
4 changes: 3 additions & 1 deletion crates/mms_tui/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#[derive(Debug)]
pub struct MMSTuiApplication {}

impl MMSTuiApplication {
fn new() -> Result<MMSTuiApplication, ()> {
pub fn new() -> Result<MMSTuiApplication, ()> {
Ok(MMSTuiApplication {})
}
}
Expand Down