Skip to content

Commit

Permalink
add clap as cli argument parser
Browse files Browse the repository at this point in the history
  • Loading branch information
jannikac committed Nov 28, 2024
1 parent 4c6a523 commit a099e22
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 8 deletions.
116 changes: 115 additions & 1 deletion Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ ddc = "0.2"
ddc-hi = "0.4"
rusb = "^0.9"
shell-words = "1.0"
clap = { version = "4.5.21", features = ["derive"] }

[build-dependencies]
vergen-git2 = { version = "1.0.0", features = ["build", "cargo"] }
Expand Down
14 changes: 7 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
extern crate log;

use anyhow::Result;
use std::env;
use clap::Parser;

#[cfg(target_os = "windows")]
use winapi::um::wincon::{AttachConsole, ATTACH_PARENT_PROCESS};
Expand All @@ -21,6 +21,11 @@ mod logging;
mod platform;
mod usb;

#[derive(Parser, Debug)]
#[command(version)]
struct Args {
}

/// On Windows, re-attach the console, if parent process has the console. This allows
/// to see the log output when run from the command line.
fn attach_console() {
Expand All @@ -32,12 +37,7 @@ fn attach_console() {

fn main() -> Result<()> {
attach_console();

let args: Vec<String> = env::args().collect();
if args.len() == 2 && args[1] == "--version" {
println!("{} v{}", env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"));
return Ok(());
}
let args = Args::parse();

let app = app::App::new()?;
app.run()?;
Expand Down

0 comments on commit a099e22

Please sign in to comment.