on master help sign in
Drop clap for pico-args

We barely have any flags so it's not worth the compilation time or binary size to use clap.

commit138787f76e39f208f3a9a757d12b58d86504d1de authorBlaž Hrastnik <blaz@mxxn.io> dateMon 31 May 2021, 17:07 (5 years ago) parent1132c51
5 files changed+52−80
Cargo.lock+7−54 helix-core/Cargo.toml−1 helix-term/Cargo.toml+1−1 helix-term/src/application.rs+3−5 helix-term/src/main.rs+41−19
Cargo.lock+7−54
@@ -77,21 +77,6 @@ dependencies = [
7777 "winapi",
7878]
7979
80−[[package]]
81−name = "clap"
82−version = "3.0.0-beta.2"
83−source = "registry+https://github.com/rust-lang/crates.io-index"
84−checksum = "4bd1061998a501ee7d4b6d449020df3266ca3124b941ec56cf2005c3779ca142"
85−dependencies = [
86− "bitflags",
87− "indexmap",
88− "lazy_static",
89− "os_str_bytes",
90− "textwrap",
91− "unicode-width",
92− "vec_map",
93−]
94−
9580[[package]]
9681name = "crossbeam-utils"
9782version = "0.8.4"
@@ -272,17 +257,10 @@ dependencies = [
272257 "regex",
273258]
274259
275−[[package]]
276−name = "hashbrown"
277−version = "0.9.1"
278−source = "registry+https://github.com/rust-lang/crates.io-index"
279−checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04"
280−
281260[[package]]
282261name = "helix-core"
283262version = "0.1.0"
284263dependencies = [
285− "anyhow",
286264 "etcetera",
287265 "helix-syntax",
288266 "once_cell",
@@ -335,7 +313,6 @@ version = "0.1.0"
335313dependencies = [
336314 "anyhow",
337315 "chrono",
338− "clap",
339316 "crossterm",
340317 "dirs-next",
341318 "fern",
@@ -349,6 +326,7 @@ dependencies = [
349326 "log",
350327 "num_cpus",
351328 "once_cell",
329+ "pico-args",
352330 "pulldown-cmark",
353331 "serde",
354332 "serde_json",
@@ -423,16 +401,6 @@ dependencies = [
423401 "winapi-util",
424402]
425403
426−[[package]]
427−name = "indexmap"
428−version = "1.6.2"
429−source = "registry+https://github.com/rust-lang/crates.io-index"
430−checksum = "824845a0bf897a9042383849b02c1bc219c2383772efcd5c6f9766fa4b81aef3"
431−dependencies = [
432− "autocfg",
433− "hashbrown",
434−]
435−
436404[[package]]
437405name = "instant"
438406version = "0.1.9"
@@ -602,12 +570,6 @@ version = "1.7.2"
602570source = "registry+https://github.com/rust-lang/crates.io-index"
603571checksum = "af8b08b04175473088b46763e51ee54da5f9a164bc162f615b91bc179dbf15a3"
604572
605−[[package]]
606−name = "os_str_bytes"
607−version = "2.4.0"
608−source = "registry+https://github.com/rust-lang/crates.io-index"
609−checksum = "afb2e1c3ee07430c2cf76151675e583e0f19985fa6efae47d6848a3e2c824f85"
610−
611573[[package]]
612574name = "parking_lot"
613575version = "0.11.1"
@@ -645,6 +607,12 @@ version = "2.1.0"
645607source = "registry+https://github.com/rust-lang/crates.io-index"
646608checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e"
647609
610+[[package]]
611+name = "pico-args"
612+version = "0.4.1"
613+source = "registry+https://github.com/rust-lang/crates.io-index"
614+checksum = "7d7afeb98c5a10e0bffcc7fc16e105b04d06729fac5fd6384aebf7ff5cb5a67d"
615+
648616[[package]]
649617name = "pin-project-lite"
650618version = "0.2.6"
@@ -857,15 +825,6 @@ dependencies = [
857825 "utf-8",
858826]
859827
860−[[package]]
861−name = "textwrap"
862−version = "0.12.1"
863−source = "registry+https://github.com/rust-lang/crates.io-index"
864−checksum = "203008d98caf094106cfaba70acfed15e18ed3ddb7d94e49baec153a2b462789"
865−dependencies = [
866− "unicode-width",
867−]
868−
869828[[package]]
870829name = "thiserror"
871830version = "1.0.25"
@@ -1044,12 +1003,6 @@ version = "0.7.6"
10441003source = "registry+https://github.com/rust-lang/crates.io-index"
10451004checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9"
10461005
1047−[[package]]
1048−name = "vec_map"
1049−version = "0.8.2"
1050−source = "registry+https://github.com/rust-lang/crates.io-index"
1051−checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
1052−
10531006[[package]]
10541007name = "version_check"
10551008version = "0.9.3"
helix-core/Cargo.toml−1
@@ -11,7 +11,6 @@ license = "MPL-2.0"
1111helix-syntax = { path = "../helix-syntax" }
1212
1313ropey = "1.2"
14−anyhow = "1"
1514smallvec = "1.4"
1615tendril = "0.4.2"
1716unicode-segmentation = "1.6"
helix-term/Cargo.toml+1−1
@@ -24,7 +24,7 @@ tokio = { version = "1", features = ["full"] }
2424num_cpus = "1"
2525tui = { path = "../helix-tui", package = "helix-tui", default-features = false, features = ["crossterm"] }
2626crossterm = { version = "0.19", features = ["event-stream"] }
27−clap = { version = "3.0.0-beta.2 ", default-features = false, features = ["std", "cargo"] }
27+pico-args = "0.4"
2828
2929futures-util = { version = "0.3", features = ["std", "async-await"], default-features = false }
3030
helix-term/src/application.rs+3−5
@@ -1,8 +1,6 @@
1−use clap::ArgMatches as Args;
2−
31use helix_view::{document::Mode, Document, Editor, Theme, View};
42
5−use crate::{compositor::Compositor, ui};
3+use crate::{compositor::Compositor, ui, Args};
64
75use log::{error, info};
86
@@ -47,8 +45,8 @@ impl Application {
4745 let size = compositor.size();
4846 let mut editor = Editor::new(size);
4947
50− if let Ok(files) = args.values_of_t::<PathBuf>("files") {
51− for file in files {
48+ if !args.files.is_empty() {
49+ for file in args.files {
5250 editor.open(file, Action::VerticalSplit)?;
5351 }
5452 } else {
helix-term/src/main.rs+41−19
@@ -8,7 +8,6 @@ mod ui;
88
99use application::Application;
1010
11−use clap::{App, Arg};
1211use std::path::PathBuf;
1312
1413use anyhow::Error;
@@ -48,25 +47,48 @@ fn setup_logging(verbosity: u64) -> Result<(), fern::InitError> {
4847 Ok(())
4948}
5049
50+pub struct Args {
51+ files: Vec<PathBuf>,
52+}
53+
5154fn main() {
52− let args = clap::app_from_crate!()
53− .arg(
54− Arg::new("files")
55− .about("Sets the input file to use")
56− .required(false)
57− .multiple(true)
58− .index(1),
59− )
60− .arg(
61− Arg::new("verbose")
62− .about("Increases logging verbosity each use for up to 3 times")
63− .short('v')
64− .takes_value(false)
65− .multiple_occurrences(true),
66− )
67− .get_matches();
68−
69− let verbosity: u64 = args.occurrences_of("verbose");
55+ let help = format!(
56+ "\
57+{} {}
58+{}
59+{}
60+
61+USAGE:
62+ hx [FLAGS] [files]...
63+
64+ARGS:
65+ <files>... Sets the input file to use
66+
67+FLAGS:
68+ -h, --help Prints help information
69+ -v Increases logging verbosity each use for up to 3 times
70+ -V, --version Prints version information
71+",
72+ env!("CARGO_PKG_NAME"),
73+ env!("CARGO_PKG_VERSION"),
74+ env!("CARGO_PKG_AUTHORS"),
75+ env!("CARGO_PKG_DESCRIPTION"),
76+ );
77+
78+ let mut pargs = pico_args::Arguments::from_env();
79+
80+ // Help has a higher priority and should be handled separately.
81+ if pargs.contains(["-h", "--help"]) {
82+ print!("{}", help);
83+ std::process::exit(0);
84+ }
85+
86+ let args = Args {
87+ files: pargs.finish().into_iter().map(|arg| arg.into()).collect(),
88+ };
89+
90+ // let verbosity: u64 = args.occurrences_of("verbose");
91+ let verbosity: u64 = 0;
7092
7193 setup_logging(verbosity).expect("failed to initialize logging.");
7294