Skip to content

Commit c8e6d12

Browse files
committed
boulder: Standardize version handling
Signed-off-by: Reilly Brogan <[email protected]>
1 parent d85cb25 commit c8e6d12

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

boulder/src/cli.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ mod build;
1111
mod chroot;
1212
mod profile;
1313
mod recipe;
14+
mod version;
1415

1516
#[derive(Debug, Parser)]
16-
#[command(version = serpent_buildinfo::get_simple_version())]
1717
pub struct Command {
1818
#[command(flatten)]
1919
pub global: Global,
@@ -23,6 +23,14 @@ pub struct Command {
2323

2424
#[derive(Debug, Args)]
2525
pub struct Global {
26+
#[arg(
27+
short,
28+
long = "verbose",
29+
help = "Prints additional information about what boulder is doing",
30+
default_value = "false",
31+
global = true
32+
)]
33+
pub verbose: bool,
2634
#[arg(long, global = true)]
2735
pub cache_dir: Option<PathBuf>,
2836
#[arg(long, global = true)]
@@ -39,19 +47,28 @@ pub enum Subcommand {
3947
Chroot(chroot::Command),
4048
Profile(profile::Command),
4149
Recipe(recipe::Command),
50+
Version(version::Command),
4251
}
4352

4453
pub fn process() -> Result<(), Error> {
4554
let args = replace_aliases(std::env::args());
4655
let Command { global, subcommand } = Command::parse_from(args);
4756

57+
if global.verbose {
58+
match subcommand {
59+
Subcommand::Version(_) => (),
60+
_ => version::print(),
61+
}
62+
}
63+
4864
let env = Env::new(global.cache_dir, global.config_dir, global.data_dir, global.moss_root)?;
4965

5066
match subcommand {
5167
Subcommand::Build(command) => build::handle(command, env)?,
5268
Subcommand::Chroot(command) => chroot::handle(command, env)?,
5369
Subcommand::Profile(command) => profile::handle(command, env)?,
5470
Subcommand::Recipe(command) => recipe::handle(command, env)?,
71+
Subcommand::Version(command) => version::handle(command),
5572
}
5673

5774
Ok(())

boulder/src/cli/version.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// SPDX-FileCopyrightText: Copyright © 2020-2024 Serpent OS Developers
2+
//
3+
// SPDX-License-Identifier: MPL-2.0
4+
5+
use clap::Parser;
6+
7+
#[derive(Debug, Parser)]
8+
#[command(about = "Print version info and exit")]
9+
pub struct Command {
10+
#[arg(
11+
long = "full",
12+
help = "Print the full build and version info",
13+
default_value = "false"
14+
)]
15+
full: bool,
16+
}
17+
18+
pub fn handle(command: Command) {
19+
if command.full {
20+
print_full()
21+
} else {
22+
print()
23+
}
24+
}
25+
26+
/// Print program version
27+
pub fn print() {
28+
println!("boulder {}", serpent_buildinfo::get_simple_version());
29+
}
30+
31+
/// Print additional build information
32+
pub fn print_full() {
33+
println!("boulder {}", serpent_buildinfo::get_full_version());
34+
}

0 commit comments

Comments
 (0)