New: add --version
flag
This commit is contained in:
parent
e85421609e
commit
acfacc690b
15
src/main.rs
15
src/main.rs
@ -1,13 +1,18 @@
|
|||||||
use eyre::{eyre, Result};
|
use eyre::{eyre, Result};
|
||||||
use gumdrop::Options;
|
use gumdrop::Options;
|
||||||
use obsidian_export::{ExportError, Exporter, FrontmatterStrategy, WalkOptions};
|
use obsidian_export::{ExportError, Exporter, FrontmatterStrategy, WalkOptions};
|
||||||
use std::path::PathBuf;
|
use std::{env, path::PathBuf};
|
||||||
|
|
||||||
|
const VERSION: &'static str = env!("CARGO_PKG_VERSION");
|
||||||
|
|
||||||
#[derive(Debug, Options)]
|
#[derive(Debug, Options)]
|
||||||
struct Opts {
|
struct Opts {
|
||||||
#[options(help = "Display program help")]
|
#[options(help = "Display program help")]
|
||||||
help: bool,
|
help: bool,
|
||||||
|
|
||||||
|
#[options(help = "Display version information")]
|
||||||
|
version: bool,
|
||||||
|
|
||||||
#[options(help = "Source file containing reference", free, required)]
|
#[options(help = "Source file containing reference", free, required)]
|
||||||
source: Option<PathBuf>,
|
source: Option<PathBuf>,
|
||||||
|
|
||||||
@ -50,6 +55,14 @@ fn frontmatter_strategy_from_str(input: &str) -> Result<FrontmatterStrategy> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
// Due to the use of free arguments in Opts, we must bypass Gumdrop to determine whether the
|
||||||
|
// version flag was specified. Without this, "missing required free argument" would get printed
|
||||||
|
// when no other args are specified.
|
||||||
|
if env::args().any(|arg| arg == "-v" || arg == "--version") {
|
||||||
|
println!("obsidian-export {}", VERSION);
|
||||||
|
std::process::exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
let args = Opts::parse_args_default_or_exit();
|
let args = Opts::parse_args_default_or_exit();
|
||||||
let source = args.source.unwrap();
|
let source = args.source.unwrap();
|
||||||
let destination = args.destination.unwrap();
|
let destination = args.destination.unwrap();
|
||||||
|
Loading…
Reference in New Issue
Block a user