Skip to content

Commit

Permalink
add --version flag
Browse files Browse the repository at this point in the history
  • Loading branch information
domenkozar committed Oct 27, 2024
1 parent fa53082 commit d6ff12c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
12 changes: 11 additions & 1 deletion devenv/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::path::PathBuf;
)]
pub struct Cli {
#[command(subcommand)]
pub command: Commands,
pub command: Option<Commands>,

#[command(flatten)]
pub global_options: GlobalOptions,
Expand All @@ -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,

Expand Down Expand Up @@ -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(),
Expand Down
16 changes: 11 additions & 5 deletions devenv/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 =
Expand All @@ -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 {
Expand Down

0 comments on commit d6ff12c

Please sign in to comment.