Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'helix-term/src/args.rs')
-rw-r--r--helix-term/src/args.rs78
1 files changed, 7 insertions, 71 deletions
diff --git a/helix-term/src/args.rs b/helix-term/src/args.rs
index 090c1192..e0f0af00 100644
--- a/helix-term/src/args.rs
+++ b/helix-term/src/args.rs
@@ -1,7 +1,5 @@
use anyhow::Result;
use helix_core::Position;
-use helix_view::tree::Layout;
-use indexmap::IndexMap;
use std::path::{Path, PathBuf};
#[derive(Default)]
@@ -13,31 +11,15 @@ pub struct Args {
pub load_tutor: bool,
pub fetch_grammars: bool,
pub build_grammars: bool,
- pub split: Option<Layout>,
pub verbosity: u64,
- pub log_file: Option<PathBuf>,
- pub config_file: Option<PathBuf>,
- pub files: IndexMap<PathBuf, Vec<Position>>,
- pub working_directory: Option<PathBuf>,
+ pub files: Vec<(PathBuf, Position)>,
+ pub edit_config: bool,
}
impl Args {
pub fn parse_args() -> Result<Args> {
let mut args = Args::default();
let mut argv = std::env::args().peekable();
- let mut line_number = 0;
-
- let mut insert_file_with_position = |file_with_position: &str| {
- let (filename, position) = parse_file(file_with_position);
-
- // Before setting the working directory, resolve all the paths in args.files
- let filename = helix_stdx::path::canonicalize(filename);
-
- args.files
- .entry(filename)
- .and_modify(|positions| positions.push(position))
- .or_insert_with(|| vec![position]);
- };
argv.next(); // skip the program, we don't care about that
@@ -47,14 +29,7 @@ impl Args {
"--version" => args.display_version = true,
"--help" => args.display_help = true,
"--tutor" => args.load_tutor = true,
- "--vsplit" => match args.split {
- Some(_) => anyhow::bail!("can only set a split once of a specific type"),
- None => args.split = Some(Layout::Vertical),
- },
- "--hsplit" => match args.split {
- Some(_) => anyhow::bail!("can only set a split once of a specific type"),
- None => args.split = Some(Layout::Horizontal),
- },
+ "--edit-config" => args.edit_config = true,
"--health" => {
args.health = true;
args.health_arg = argv.next_if(|opt| !opt.starts_with('-'));
@@ -66,28 +41,6 @@ impl Args {
anyhow::bail!("--grammar must be followed by either 'fetch' or 'build'")
}
},
- "-c" | "--config" => match argv.next().as_deref() {
- Some(path) => args.config_file = Some(path.into()),
- None => anyhow::bail!("--config must specify a path to read"),
- },
- "--log" => match argv.next().as_deref() {
- Some(path) => args.log_file = Some(path.into()),
- None => anyhow::bail!("--log must specify a path to write"),
- },
- "-w" | "--working-dir" => match argv.next().as_deref() {
- Some(path) => {
- args.working_directory = if Path::new(path).is_dir() {
- Some(PathBuf::from(path))
- } else {
- anyhow::bail!(
- "--working-dir specified does not exist or is not a directory"
- )
- }
- }
- None => {
- anyhow::bail!("--working-dir must specify an initial working directory")
- }
- },
arg if arg.starts_with("--") => {
anyhow::bail!("unexpected double dash argument: {}", arg)
}
@@ -102,30 +55,13 @@ impl Args {
}
}
}
- "+" => line_number = usize::MAX,
- arg if arg.starts_with('+') => {
- match arg[1..].parse::<usize>() {
- Ok(n) => line_number = n.saturating_sub(1),
- _ => insert_file_with_position(arg),
- };
- }
- arg => insert_file_with_position(arg),
+ arg => args.files.push(parse_file(arg)),
}
}
// push the remaining args, if any to the files
for arg in argv {
- insert_file_with_position(&arg);
- }
-
- if line_number != 0 {
- if let Some(first_position) = args
- .files
- .first_mut()
- .and_then(|(_, positions)| positions.first_mut())
- {
- first_position.row = line_number;
- }
+ args.files.push(parse_file(&arg));
}
Ok(args)
@@ -147,7 +83,7 @@ pub(crate) fn parse_file(s: &str) -> (PathBuf, Position) {
///
/// Does not validate if file.rs is a file or directory.
fn split_path_row_col(s: &str) -> Option<(PathBuf, Position)> {
- let mut s = s.trim_end_matches(':').rsplitn(3, ':');
+ let mut s = s.rsplitn(3, ':');
let col: usize = s.next()?.parse().ok()?;
let row: usize = s.next()?.parse().ok()?;
let path = s.next()?.into();
@@ -159,7 +95,7 @@ fn split_path_row_col(s: &str) -> Option<(PathBuf, Position)> {
///
/// Does not validate if file.rs is a file or directory.
fn split_path_row(s: &str) -> Option<(PathBuf, Position)> {
- let (path, row) = s.trim_end_matches(':').rsplit_once(':')?;
+ let (path, row) = s.rsplit_once(':')?;
let row: usize = row.parse().ok()?;
let path = path.into();
let pos = Position::new(row.saturating_sub(1), 0);