diff --git a/devenv/src/cli.rs b/devenv/src/cli.rs index 761ddc949..fc1b5de0d 100644 --- a/devenv/src/cli.rs +++ b/devenv/src/cli.rs @@ -12,7 +12,7 @@ use std::path::PathBuf; )] pub struct Cli { #[command(subcommand)] - pub command: Commands, + pub command: Option, #[command(flatten)] pub global_options: GlobalOptions, @@ -29,6 +29,15 @@ impl Cli { #[derive(Clone, Debug, Parser)] pub struct GlobalOptions { + #[arg( + short = 'V', + long, + global = true, + help = "Print version information", + long_help = "Print version information and exit" + )] + pub version: bool, + #[arg(short, long, global = true, help = "Enable debug log level.")] pub verbose: bool, @@ -129,6 +138,7 @@ pub struct GlobalOptions { impl Default for GlobalOptions { fn default() -> Self { Self { + version: false, verbose: false, quiet: false, max_jobs: max_jobs(), diff --git a/devenv/src/main.rs b/devenv/src/main.rs index 259b89559..c2cfc557c 100644 --- a/devenv/src/main.rs +++ b/devenv/src/main.rs @@ -9,14 +9,20 @@ use miette::Result; async fn main() -> Result<()> { let cli = Cli::parse_and_resolve_options(); - if let Commands::Version { .. } = cli.command { + let print_version = || { println!( "devenv {} ({})", crate_version!(), cli.global_options.system ); - return Ok(()); - } + Ok(()) + }; + + let command = match cli.command { + None => return print_version(), + Some(Commands::Version { .. }) => return print_version(), + Some(cmd) => cmd, + }; let level = if cli.global_options.verbose { log::Level::Debug @@ -43,7 +49,7 @@ async fn main() -> Result<()> { // we let Drop delete the dir after all commands have ran let _tmpdir = if let Commands::Test { dont_override_dotfile, - } = cli.command + } = command { let pwd = std::env::current_dir().expect("Failed to get current directory"); let tmpdir = @@ -62,7 +68,7 @@ async fn main() -> Result<()> { let mut devenv = Devenv::new(options).await; - match cli.command { + match command { Commands::Shell { cmd, args } => devenv.shell(&cmd, &args, true).await, Commands::Test { .. } => devenv.test().await, Commands::Container {