diff options
author | Blaž Hrastnik | 2021-05-31 08:07:43 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2021-05-31 08:07:43 +0000 |
commit | 138787f76e39f208f3a9a757d12b58d86504d1de (patch) | |
tree | dd6dda7f0174fdfe85e8e7c8a441d2c25b156492 /helix-term/src | |
parent | 1132c5122fe8a325b2b762cf920cc5e54e91991e (diff) |
Drop clap for pico-args
We barely have any flags so it's not worth the compilation time or
binary size to use clap.
Diffstat (limited to 'helix-term/src')
-rw-r--r-- | helix-term/src/application.rs | 8 | ||||
-rw-r--r-- | helix-term/src/main.rs | 60 |
2 files changed, 44 insertions, 24 deletions
diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index 42a46f1e..5ea6be2b 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -1,8 +1,6 @@ -use clap::ArgMatches as Args; - use helix_view::{document::Mode, Document, Editor, Theme, View}; -use crate::{compositor::Compositor, ui}; +use crate::{compositor::Compositor, ui, Args}; use log::{error, info}; @@ -47,8 +45,8 @@ impl Application { let size = compositor.size(); let mut editor = Editor::new(size); - if let Ok(files) = args.values_of_t::<PathBuf>("files") { - for file in files { + if !args.files.is_empty() { + for file in args.files { editor.open(file, Action::VerticalSplit)?; } } else { diff --git a/helix-term/src/main.rs b/helix-term/src/main.rs index 386c2333..9ca5b067 100644 --- a/helix-term/src/main.rs +++ b/helix-term/src/main.rs @@ -8,7 +8,6 @@ mod ui; use application::Application; -use clap::{App, Arg}; use std::path::PathBuf; use anyhow::Error; @@ -48,25 +47,48 @@ fn setup_logging(verbosity: u64) -> Result<(), fern::InitError> { Ok(()) } +pub struct Args { + files: Vec<PathBuf>, +} + fn main() { - let args = clap::app_from_crate!() - .arg( - Arg::new("files") - .about("Sets the input file to use") - .required(false) - .multiple(true) - .index(1), - ) - .arg( - Arg::new("verbose") - .about("Increases logging verbosity each use for up to 3 times") - .short('v') - .takes_value(false) - .multiple_occurrences(true), - ) - .get_matches(); - - let verbosity: u64 = args.occurrences_of("verbose"); + let help = format!( + "\ +{} {} +{} +{} + +USAGE: + hx [FLAGS] [files]... + +ARGS: + <files>... Sets the input file to use + +FLAGS: + -h, --help Prints help information + -v Increases logging verbosity each use for up to 3 times + -V, --version Prints version information +", + env!("CARGO_PKG_NAME"), + env!("CARGO_PKG_VERSION"), + env!("CARGO_PKG_AUTHORS"), + env!("CARGO_PKG_DESCRIPTION"), + ); + + let mut pargs = pico_args::Arguments::from_env(); + + // Help has a higher priority and should be handled separately. + if pargs.contains(["-h", "--help"]) { + print!("{}", help); + std::process::exit(0); + } + + let args = Args { + files: pargs.finish().into_iter().map(|arg| arg.into()).collect(), + }; + + // let verbosity: u64 = args.occurrences_of("verbose"); + let verbosity: u64 = 0; setup_logging(verbosity).expect("failed to initialize logging."); |