Repository information in version

This commit is contained in:
John Doty 2024-08-07 12:14:04 -07:00
parent 8a60f89110
commit b8fe678ff0
2 changed files with 134 additions and 6 deletions

View file

@ -2,6 +2,8 @@
use indoc::indoc;
const VERSION: &str = env!("CARGO_PKG_VERSION");
const REV: &str = env!("REPO_REV");
const DIRTY: &str = env!("REPO_DIRTY");
fn usage() {
println!(indoc! {"
@ -85,13 +87,21 @@ fn parse_args(args: Vec<String>) -> Args {
if rest.len() == 2 {
Args::Browse(rest[1].to_string())
} else if rest.len() == 1 {
Args::Client(rest[0].to_string(), sudo.unwrap_or(false), log_filter.unwrap_or("warn".to_owned()))
Args::Client(
rest[0].to_string(),
sudo.unwrap_or(false),
log_filter.unwrap_or("warn".to_owned()),
)
} else {
Args::Error
}
} else if rest[0] == "clip" {
if rest.len() == 1 {
Args::Client(rest[0].to_string(), sudo.unwrap_or(false), log_filter.unwrap_or("warn".to_owned()))
Args::Client(
rest[0].to_string(),
sudo.unwrap_or(false),
log_filter.unwrap_or("warn".to_owned()),
)
} else if rest.len() == 2 {
Args::Clip(rest[1].to_string())
} else {
@ -131,7 +141,7 @@ async fn main() {
usage();
}
Args::Version => {
println!("fwd {VERSION}");
println!("fwd {VERSION} (rev {REV}{DIRTY})");
}
Args::Server => {
fwd::run_server().await;
@ -193,7 +203,7 @@ mod tests {
#[test]
fn client() {
assert_arg_parse!(&["foo.com"], Args::Client( _, false, _));
assert_arg_parse!(&["foo.com"], Args::Client(_, false, _));
assert_arg_parse!(&["a"], Args::Client(_, false, _));
assert_arg_parse!(&["browse"], Args::Client(_, false, _));
assert_arg_parse!(&["clip"], Args::Client(_, false, _));
@ -205,10 +215,20 @@ mod tests {
assert_client_parse(&["a"], "a", false, "warn");
assert_client_parse(&["a", "--log-filter", "info"], "a", false, "info");
assert_client_parse(&["a", "--log-filter=info"], "a", false, "info");
assert_client_parse(&["a", "--sudo", "--log-filter=info"], "a", true, "info");
assert_client_parse(
&["a", "--sudo", "--log-filter=info"],
"a",
true,
"info",
);
}
fn assert_client_parse(x: &[&str], server: &str, sudo: bool, log_filter: &str) {
fn assert_client_parse(
x: &[&str],
server: &str,
sudo: bool,
log_filter: &str,
) {
let args = parse_args(args(x));
assert_matches!(args, Args::Client(_, _, _));
if let Args::Client(s, sdo, lf) = args {