Add --version command line flag
parent
d3c658cf00
commit
2a1bf37e69
3
meli.1
3
meli.1
|
@ -26,6 +26,7 @@
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.Nm meli
|
.Nm meli
|
||||||
.Op Fl -help | h
|
.Op Fl -help | h
|
||||||
|
.Op Fl -version | v
|
||||||
.Op Fl -create-config Op Ar path
|
.Op Fl -create-config Op Ar path
|
||||||
.Op Fl -config Ar path
|
.Op Fl -config Ar path
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
|
@ -33,6 +34,8 @@ Experimental terminal mail client
|
||||||
.Bl -tag -width flag -offset indent
|
.Bl -tag -width flag -offset indent
|
||||||
.It Fl -help, h
|
.It Fl -help, h
|
||||||
Show help message and exit.
|
Show help message and exit.
|
||||||
|
.It Fl -version, v
|
||||||
|
Show version and exit.
|
||||||
.It Fl -create-config Op Ar path
|
.It Fl -create-config Op Ar path
|
||||||
Create configuration file in
|
Create configuration file in
|
||||||
.Pa path
|
.Pa path
|
||||||
|
|
23
src/bin.rs
23
src/bin.rs
|
@ -47,7 +47,7 @@ use xdg;
|
||||||
|
|
||||||
macro_rules! error_and_exit {
|
macro_rules! error_and_exit {
|
||||||
($($err:expr),*) => {{
|
($($err:expr),*) => {{
|
||||||
println!($($err),*);
|
eprintln!($($err),*);
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
@ -57,6 +57,7 @@ struct CommandLineArguments {
|
||||||
create_config: Option<String>,
|
create_config: Option<String>,
|
||||||
config: Option<String>,
|
config: Option<String>,
|
||||||
help: bool,
|
help: bool,
|
||||||
|
version: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
@ -70,6 +71,7 @@ fn main() {
|
||||||
create_config: None,
|
create_config: None,
|
||||||
config: None,
|
config: None,
|
||||||
help: false,
|
help: false,
|
||||||
|
version: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
for i in std::env::args().skip(1) {
|
for i in std::env::args().skip(1) {
|
||||||
|
@ -88,10 +90,12 @@ fn main() {
|
||||||
Some(CreateConfig) => error_and_exit!("Duplicate value for flag `--create-config`"),
|
Some(CreateConfig) => error_and_exit!("Duplicate value for flag `--create-config`"),
|
||||||
Some(Config) => error_and_exit!("invalid value for flag `--config`"),
|
Some(Config) => error_and_exit!("invalid value for flag `--config`"),
|
||||||
},
|
},
|
||||||
"--help" | "-h" => match prev {
|
"--help" | "-h" => {
|
||||||
Some(_) => {}
|
args.help = true;
|
||||||
None => args.help = true,
|
}
|
||||||
},
|
"--version" | "-v" => {
|
||||||
|
args.version = true;
|
||||||
|
}
|
||||||
e => match prev {
|
e => match prev {
|
||||||
None => error_and_exit!("error: value without command {}", e),
|
None => error_and_exit!("error: value without command {}", e),
|
||||||
Some(CreateConfig) if args.create_config.is_none() => {
|
Some(CreateConfig) if args.create_config.is_none() => {
|
||||||
|
@ -111,13 +115,20 @@ fn main() {
|
||||||
if args.help {
|
if args.help {
|
||||||
println!("usage:\tmeli [--create-config[ PATH]] [--config[ PATH]|-c[ PATH]]");
|
println!("usage:\tmeli [--create-config[ PATH]] [--config[ PATH]|-c[ PATH]]");
|
||||||
println!("\tmeli --help");
|
println!("\tmeli --help");
|
||||||
|
println!("\tmeli --version");
|
||||||
println!("");
|
println!("");
|
||||||
println!("\t--help\t\t\tshow this message and exit");
|
println!("\t--help, -h\t\tshow this message and exit");
|
||||||
|
println!("\t--version, -v\t\tprint version and exit");
|
||||||
println!("\t--create-config[ PATH]\tCreate a sample configuration file with available configuration options. If PATH is not specified, meli will try to create it in $XDG_CONFIG_HOME/meli/config");
|
println!("\t--create-config[ PATH]\tCreate a sample configuration file with available configuration options. If PATH is not specified, meli will try to create it in $XDG_CONFIG_HOME/meli/config");
|
||||||
println!("\t--config PATH, -c PATH\tUse specified configuration file");
|
println!("\t--config PATH, -c PATH\tUse specified configuration file");
|
||||||
std::process::exit(0);
|
std::process::exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if args.version {
|
||||||
|
println!("meli {}", option_env!("CARGO_PKG_VERSION").unwrap_or("0.0"));
|
||||||
|
std::process::exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
match prev {
|
match prev {
|
||||||
None => {}
|
None => {}
|
||||||
Some(CreateConfig) if args.create_config.is_none() => args.create_config = Some("".into()),
|
Some(CreateConfig) if args.create_config.is_none() => args.create_config = Some("".into()),
|
||||||
|
|
Loading…
Reference in New Issue