on master help sign in
Drop clap for pico-args
138787fBlaž Hrastnik
Cargo.lock+7−54
@@ -77,21 +77,6 @@ dependencies = [
77 "winapi",
77 "winapi",
78]
78]
79
79
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−
95[[package]]
80[[package]]
96name = "crossbeam-utils"
81name = "crossbeam-utils"
97version = "0.8.4"
82version = "0.8.4"
@@ -272,17 +257,10 @@ dependencies = [
272 "regex",
257 "regex",
273]
258]
274
259
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−
281[[package]]
260[[package]]
282name = "helix-core"
261name = "helix-core"
283version = "0.1.0"
262version = "0.1.0"
284dependencies = [
263dependencies = [
285− "anyhow",
286 "etcetera",
264 "etcetera",
287 "helix-syntax",
265 "helix-syntax",
288 "once_cell",
266 "once_cell",
@@ -335,7 +313,6 @@ version = "0.1.0"
335dependencies = [
313dependencies = [
336 "anyhow",
314 "anyhow",
337 "chrono",
315 "chrono",
338− "clap",
339 "crossterm",
316 "crossterm",
340 "dirs-next",
317 "dirs-next",
341 "fern",
318 "fern",
@@ -349,6 +326,7 @@ dependencies = [
349 "log",
326 "log",
350 "num_cpus",
327 "num_cpus",
351 "once_cell",
328 "once_cell",
329+ "pico-args",
352 "pulldown-cmark",
330 "pulldown-cmark",
353 "serde",
331 "serde",
354 "serde_json",
332 "serde_json",
@@ -423,16 +401,6 @@ dependencies = [
423 "winapi-util",
401 "winapi-util",
424]
402]
425
403
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−
436[[package]]
404[[package]]
437name = "instant"
405name = "instant"
438version = "0.1.9"
406version = "0.1.9"
@@ -602,12 +570,6 @@ version = "1.7.2"
602source = "registry+https://github.com/rust-lang/crates.io-index"
570source = "registry+https://github.com/rust-lang/crates.io-index"
603checksum = "af8b08b04175473088b46763e51ee54da5f9a164bc162f615b91bc179dbf15a3"
571checksum = "af8b08b04175473088b46763e51ee54da5f9a164bc162f615b91bc179dbf15a3"
604
572
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−
611[[package]]
573[[package]]
612name = "parking_lot"
574name = "parking_lot"
613version = "0.11.1"
575version = "0.11.1"
@@ -645,6 +607,12 @@ version = "2.1.0"
645source = "registry+https://github.com/rust-lang/crates.io-index"
607source = "registry+https://github.com/rust-lang/crates.io-index"
646checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e"
608checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e"
647
609
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+
648[[package]]
616[[package]]
649name = "pin-project-lite"
617name = "pin-project-lite"
650version = "0.2.6"
618version = "0.2.6"
@@ -857,15 +825,6 @@ dependencies = [
857 "utf-8",
825 "utf-8",
858]
826]
859
827
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−
869[[package]]
828[[package]]
870name = "thiserror"
829name = "thiserror"
871version = "1.0.25"
830version = "1.0.25"
@@ -1044,12 +1003,6 @@ version = "0.7.6"
1044source = "registry+https://github.com/rust-lang/crates.io-index"
1003source = "registry+https://github.com/rust-lang/crates.io-index"
1045checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9"
1004checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9"
1046
1005
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−
1053[[package]]
1006[[package]]
1054name = "version_check"
1007name = "version_check"
1055version = "0.9.3"
1008version = "0.9.3"
helix-core/Cargo.toml−1
@@ -11,7 +11,6 @@ license = "MPL-2.0"
11helix-syntax = { path = "../helix-syntax" }
11helix-syntax = { path = "../helix-syntax" }
12
12
13ropey = "1.2"
13ropey = "1.2"
14−anyhow = "1"
15smallvec = "1.4"
14smallvec = "1.4"
16tendril = "0.4.2"
15tendril = "0.4.2"
17unicode-segmentation = "1.6"
16unicode-segmentation = "1.6"
helix-term/Cargo.toml+1−1
@@ -24,7 +24,7 @@ tokio = { version = "1", features = ["full"] }
24num_cpus = "1"
24num_cpus = "1"
25tui = { path = "../helix-tui", package = "helix-tui", default-features = false, features = ["crossterm"] }
25tui = { path = "../helix-tui", package = "helix-tui", default-features = false, features = ["crossterm"] }
26crossterm = { version = "0.19", features = ["event-stream"] }
26crossterm = { 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"
28
28
29futures-util = { version = "0.3", features = ["std", "async-await"], default-features = false }
29futures-util = { version = "0.3", features = ["std", "async-await"], default-features = false }
30
30
helix-term/src/application.rs+3−5
@@ -1,8 +1,6 @@
1−use clap::ArgMatches as Args;
2−
3use helix_view::{document::Mode, Document, Editor, Theme, View};
1use helix_view::{document::Mode, Document, Editor, Theme, View};
4
2
5−use crate::{compositor::Compositor, ui};
3+use crate::{compositor::Compositor, ui, Args};
6
4
7use log::{error, info};
5use log::{error, info};
8
6
@@ -47,8 +45,8 @@ impl Application {
47 let size = compositor.size();
45 let size = compositor.size();
48 let mut editor = Editor::new(size);
46 let mut editor = Editor::new(size);
49
47
50− if let Ok(files) = args.values_of_t::<PathBuf>("files") {
48+ if !args.files.is_empty() {
51− for file in files {
49+ for file in args.files {
52 editor.open(file, Action::VerticalSplit)?;
50 editor.open(file, Action::VerticalSplit)?;
53 }
51 }
54 } else {
52 } else {
helix-term/src/main.rs+41−19
@@ -8,7 +8,6 @@ mod ui;
8
8
9use application::Application;
9use application::Application;
10
10
11−use clap::{App, Arg};
12use std::path::PathBuf;
11use std::path::PathBuf;
13
12
14use anyhow::Error;
13use anyhow::Error;
@@ -48,25 +47,48 @@ fn setup_logging(verbosity: u64) -> Result<(), fern::InitError> {
48 Ok(())
47 Ok(())
49}
48}
50
49
50+pub struct Args {
51+ files: Vec<PathBuf>,
52+}
53+
51fn main() {
54fn main() {
52− let args = clap::app_from_crate!()
55+ let help = format!(
53− .arg(
56+ "\
57+{} {}
58+{}
59+{}
60+
61+USAGE:
54− Arg::new("files")
62+ hx [FLAGS] [files]...
63+
64+ARGS:
55− .about("Sets the input file to use")
65+ <files>... Sets the input file to use
56− .required(false)
66+
57− .multiple(true)
67+FLAGS:
58− .index(1),
68+ -h, --help Prints help information
59− )
60− .arg(
61− Arg::new("verbose")
62− .about("Increases logging verbosity each use for up to 3 times")
69+ -v Increases logging verbosity each use for up to 3 times
63− .short('v')
70+ -V, --version Prints version information
64− .takes_value(false)
71+",
65− .multiple_occurrences(true),
72+ env!("CARGO_PKG_NAME"),
66− )
73+ env!("CARGO_PKG_VERSION"),
67− .get_matches();
74+ env!("CARGO_PKG_AUTHORS"),
68−
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+
69− let verbosity: u64 = args.occurrences_of("verbose");
90+ // let verbosity: u64 = args.occurrences_of("verbose");
91+ let verbosity: u64 = 0;
70
92
71 setup_logging(verbosity).expect("failed to initialize logging.");
93 setup_logging(verbosity).expect("failed to initialize logging.");
72
94