summaryrefslogtreecommitdiff
path: root/helix-term/src/args.rs
diff options
context:
space:
mode:
Diffstat (limited to 'helix-term/src/args.rs')
-rw-r--r--helix-term/src/args.rs26
1 files changed, 14 insertions, 12 deletions
diff --git a/helix-term/src/args.rs b/helix-term/src/args.rs
index 3e50f66f..4f386aea 100644
--- a/helix-term/src/args.rs
+++ b/helix-term/src/args.rs
@@ -1,4 +1,4 @@
-use anyhow::{Error, Result};
+use anyhow::Result;
use helix_core::Position;
use std::path::{Path, PathBuf};
@@ -6,6 +6,8 @@ use std::path::{Path, PathBuf};
pub struct Args {
pub display_help: bool,
pub display_version: bool,
+ pub health: bool,
+ pub health_arg: Option<String>,
pub load_tutor: bool,
pub verbosity: u64,
pub files: Vec<(PathBuf, Position)>,
@@ -14,22 +16,22 @@ pub struct Args {
impl Args {
pub fn parse_args() -> Result<Args> {
let mut args = Args::default();
- let argv: Vec<String> = std::env::args().collect();
- let mut iter = argv.iter();
+ let mut argv = std::env::args().peekable();
- iter.next(); // skip the program, we don't care about that
+ argv.next(); // skip the program, we don't care about that
- for arg in &mut iter {
+ while let Some(arg) = argv.next() {
match arg.as_str() {
"--" => break, // stop parsing at this point treat the remaining as files
"--version" => args.display_version = true,
"--help" => args.display_help = true,
"--tutor" => args.load_tutor = true,
+ "--health" => {
+ args.health = true;
+ args.health_arg = argv.next_if(|opt| !opt.starts_with('-'));
+ }
arg if arg.starts_with("--") => {
- return Err(Error::msg(format!(
- "unexpected double dash argument: {}",
- arg
- )))
+ anyhow::bail!("unexpected double dash argument: {}", arg)
}
arg if arg.starts_with('-') => {
let arg = arg.get(1..).unwrap().chars();
@@ -38,7 +40,7 @@ impl Args {
'v' => args.verbosity += 1,
'V' => args.display_version = true,
'h' => args.display_help = true,
- _ => return Err(Error::msg(format!("unexpected short arg {}", chr))),
+ _ => anyhow::bail!("unexpected short arg {}", chr),
}
}
}
@@ -47,8 +49,8 @@ impl Args {
}
// push the remaining args, if any to the files
- for arg in iter {
- args.files.push(parse_file(arg));
+ for arg in argv {
+ args.files.push(parse_file(&arg));
}
Ok(args)