Skip to content

Commit d85cb25

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

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

moss/src/cli/mod.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@ fn command() -> Command {
2626
Command::new("moss")
2727
.about("Next generation package manager")
2828
.arg(
29-
Arg::new("version")
29+
Arg::new("verbose")
3030
.short('v')
31-
.long("version")
31+
.long("verbose")
32+
.global(true)
33+
.help("Prints additional information about what moss is doing")
3234
.action(ArgAction::SetTrue),
3335
)
3436
.arg(
@@ -77,9 +79,13 @@ pub fn process() -> Result<(), Error> {
7779
let args = replace_aliases(env::args());
7880
let matches = command().get_matches_from(args);
7981

80-
if matches.get_flag("version") {
81-
version::print();
82-
return Ok(());
82+
// Print the version, but not if the user is using the version subcommand
83+
if matches.get_flag("verbose") {
84+
if let Some(command) = matches.subcommand_name() {
85+
if command != "version" {
86+
version::print();
87+
}
88+
}
8389
}
8490

8591
let root = matches.get_one::<PathBuf>("root").unwrap();
@@ -105,8 +111,8 @@ pub fn process() -> Result<(), Error> {
105111
Some(("search", args)) => search::handle(args, installation).map_err(Error::Search),
106112
Some(("state", args)) => state::handle(args, installation).map_err(Error::State),
107113
Some(("sync", args)) => sync::handle(args, installation).map_err(Error::Sync),
108-
Some(("version", _)) => {
109-
version::print();
114+
Some(("version", args)) => {
115+
version::handle(args);
110116
Ok(())
111117
}
112118
None => {

moss/src/cli/version.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,30 @@
22
//
33
// SPDX-License-Identifier: MPL-2.0
44

5-
use clap::Command;
5+
use clap::{arg, ArgMatches, Command};
66

77
/// Construct the Version command
88
pub fn command() -> Command {
9-
Command::new("version").about("Display version and exit")
9+
Command::new("version")
10+
.about("Display version and exit")
11+
.arg(arg!(-f --"full" "Print the full build and version info").action(clap::ArgAction::SetTrue))
12+
}
13+
14+
pub fn handle(args: &ArgMatches) {
15+
let show_full = args.get_flag("full");
16+
if show_full {
17+
print_full()
18+
} else {
19+
print()
20+
}
1021
}
1122

1223
/// Print program version
1324
pub fn print() {
1425
println!("moss {}", serpent_buildinfo::get_simple_version());
1526
}
27+
28+
/// Print additional build information
29+
pub fn print_full() {
30+
println!("moss {}", serpent_buildinfo::get_full_version());
31+
}

0 commit comments

Comments
 (0)