Browse Source

Add --version command line flag

tags/pre-alpha-0.2.0
Manos Pitsidianakis 3 weeks ago
parent
commit
2a1bf37e69
No known key found for this signature in database
2 changed files with 20 additions and 6 deletions
  1. 3
    0
      meli.1
  2. 17
    6
      src/bin.rs

+ 3
- 0
meli.1 View File

@@ -26,6 +26,7 @@
.Sh SYNOPSIS
.Nm meli
.Op Fl -help | h
.Op Fl -version | v
.Op Fl -create-config Op Ar path
.Op Fl -config Ar path
.Sh DESCRIPTION
@@ -33,6 +34,8 @@ Experimental terminal mail client
.Bl -tag -width flag -offset indent
.It Fl -help, h
Show help message and exit.
.It Fl -version, v
Show version and exit.
.It Fl -create-config Op Ar path
Create configuration file in
.Pa path

+ 17
- 6
src/bin.rs View File

@@ -47,7 +47,7 @@ use xdg;

macro_rules! error_and_exit {
($($err:expr),*) => {{
println!($($err),*);
eprintln!($($err),*);
std::process::exit(1);
}}
}
@@ -57,6 +57,7 @@ struct CommandLineArguments {
create_config: Option<String>,
config: Option<String>,
help: bool,
version: bool,
}

fn main() {
@@ -70,6 +71,7 @@ fn main() {
create_config: None,
config: None,
help: false,
version: false,
};

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(Config) => error_and_exit!("invalid value for flag `--config`"),
},
"--help" | "-h" => match prev {
Some(_) => {}
None => args.help = true,
},
"--help" | "-h" => {
args.help = true;
}
"--version" | "-v" => {
args.version = true;
}
e => match prev {
None => error_and_exit!("error: value without command {}", e),
Some(CreateConfig) if args.create_config.is_none() => {
@@ -111,13 +115,20 @@ fn main() {
if args.help {
println!("usage:\tmeli [--create-config[ PATH]] [--config[ PATH]|-c[ PATH]]");
println!("\tmeli --help");
println!("\tmeli --version");
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--config PATH, -c PATH\tUse specified configuration file");
std::process::exit(0);
}

if args.version {
println!("meli {}", option_env!("CARGO_PKG_VERSION").unwrap_or("0.0"));
std::process::exit(0);
}

match prev {
None => {}
Some(CreateConfig) if args.create_config.is_none() => args.create_config = Some("".into()),

Loading…
Cancel
Save