aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src/args.rs
diff options
context:
space:
mode:
authorLloyd Bond2023-10-03 01:18:27 +0000
committerGitHub2023-10-03 01:18:27 +0000
commit75c0a5ceb32d8a503915a93ccc1b64c8ad1cba8b (patch)
treec563d1c0bd86d816f21e450e990b2c90ab1aa1b5 /helix-term/src/args.rs
parent1756ba443631b0eb6d93c089d3b13b13cd8ef28f (diff)
enable starting hx with a working directory (#8223)
* added working path arg to cli and help menu * improve working path cli arg handling * enable hx to set the working path * applied cargo formatting * improved code from cargo clippy suggestion * improved code from follow up review * fix for -w <path> is set but args.files is empty * improved formatting of --help output
Diffstat (limited to 'helix-term/src/args.rs')
-rw-r--r--helix-term/src/args.rs15
1 files changed, 15 insertions, 0 deletions
diff --git a/helix-term/src/args.rs b/helix-term/src/args.rs
index dd787f1f..f782539c 100644
--- a/helix-term/src/args.rs
+++ b/helix-term/src/args.rs
@@ -17,6 +17,7 @@ pub struct Args {
pub log_file: Option<PathBuf>,
pub config_file: Option<PathBuf>,
pub files: Vec<(PathBuf, Position)>,
+ pub working_directory: Option<PathBuf>,
}
impl Args {
@@ -59,6 +60,20 @@ impl Args {
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)
}