From 820d68d5bbec5f3c6a6c66869f63d96a3caa3604 Mon Sep 17 00:00:00 2001 From: Lloyd Bond Date: Mon, 4 Sep 2023 02:19:17 -0400 Subject: [PATCH 1/8] added working path arg to cli and help menu --- helix-term/src/args.rs | 5 +++++ helix-term/src/main.rs | 1 + 2 files changed, 6 insertions(+) diff --git a/helix-term/src/args.rs b/helix-term/src/args.rs index dd787f1fd18c..94e55351ca9c 100644 --- a/helix-term/src/args.rs +++ b/helix-term/src/args.rs @@ -17,6 +17,7 @@ pub struct Args { pub log_file: Option, pub config_file: Option, pub files: Vec<(PathBuf, Position)>, + pub working_path: Option, } impl Args { @@ -59,6 +60,10 @@ impl Args { Some(path) => args.log_file = Some(path.into()), None => anyhow::bail!("--log must specify a path to write"), }, + "-w" | "--working-path" => match argv.next().as_deref() { + Some(path) => args.working_path = Some(path.into()), + None => anyhow::bail!("--working-path must specify an initial working directory"), + }, arg if arg.starts_with("--") => { anyhow::bail!("unexpected double dash argument: {}", arg) } diff --git a/helix-term/src/main.rs b/helix-term/src/main.rs index 542d18e6aa4d..667faa16f151 100644 --- a/helix-term/src/main.rs +++ b/helix-term/src/main.rs @@ -66,6 +66,7 @@ FLAGS: -V, --version Prints version information --vsplit Splits all given files vertically into different windows --hsplit Splits all given files horizontally into different windows + -w, --working-path Specify an initial working directory ", env!("CARGO_PKG_NAME"), VERSION_AND_GIT_HASH, From f3a144a04df1ca46a82c5dade52f7f3932e53bcd Mon Sep 17 00:00:00 2001 From: Lloyd Bond Date: Mon, 4 Sep 2023 03:48:36 -0400 Subject: [PATCH 2/8] improve working path cli arg handling --- helix-term/src/args.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/helix-term/src/args.rs b/helix-term/src/args.rs index 94e55351ca9c..21347e7eb872 100644 --- a/helix-term/src/args.rs +++ b/helix-term/src/args.rs @@ -17,7 +17,7 @@ pub struct Args { pub log_file: Option, pub config_file: Option, pub files: Vec<(PathBuf, Position)>, - pub working_path: Option, + pub working_path: Option, } impl Args { @@ -61,7 +61,7 @@ impl Args { None => anyhow::bail!("--log must specify a path to write"), }, "-w" | "--working-path" => match argv.next().as_deref() { - Some(path) => args.working_path = Some(path.into()), + Some(path) => args.working_path = if Path::new(path).exists() {Some(PathBuf::from(path))} else {None}, None => anyhow::bail!("--working-path must specify an initial working directory"), }, arg if arg.starts_with("--") => { From 0a94462fc4c9c507aeed0067e2eb60fcf6b8f3bb Mon Sep 17 00:00:00 2001 From: Lloyd Bond Date: Mon, 4 Sep 2023 03:49:33 -0400 Subject: [PATCH 3/8] enable hx to set the working path --- helix-term/src/application.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index 0d40fa66f025..789d10503392 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -169,6 +169,10 @@ impl Application { let picker = ui::file_picker(".".into(), &config.load().editor); compositor.push(Box::new(overlaid(picker))); } else { + match args.working_path { + Some(path) => helix_loader::set_current_working_dir(path.clone())?, + None => log::warn!("invalid working path given"), + } let nr_of_files = args.files.len(); for (i, (file, pos)) in args.files.into_iter().enumerate() { if file.is_dir() { From efffcc9402dce0dcc3335ab9744aea9182a0c390 Mon Sep 17 00:00:00 2001 From: Lloyd Bond Date: Sun, 17 Sep 2023 05:21:10 -0400 Subject: [PATCH 4/8] applied cargo formatting --- helix-term/src/args.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/helix-term/src/args.rs b/helix-term/src/args.rs index 21347e7eb872..53800be530a0 100644 --- a/helix-term/src/args.rs +++ b/helix-term/src/args.rs @@ -61,8 +61,16 @@ impl Args { None => anyhow::bail!("--log must specify a path to write"), }, "-w" | "--working-path" => match argv.next().as_deref() { - Some(path) => args.working_path = if Path::new(path).exists() {Some(PathBuf::from(path))} else {None}, - None => anyhow::bail!("--working-path must specify an initial working directory"), + Some(path) => { + args.working_path = if Path::new(path).exists() { + Some(PathBuf::from(path)) + } else { + None + } + } + None => { + anyhow::bail!("--working-path must specify an initial working directory") + } }, arg if arg.starts_with("--") => { anyhow::bail!("unexpected double dash argument: {}", arg) From 574a223d3b2722cfe805e9a4d792fe07b72d0257 Mon Sep 17 00:00:00 2001 From: Lloyd Bond Date: Sun, 17 Sep 2023 17:29:15 -0400 Subject: [PATCH 5/8] improved code from cargo clippy suggestion --- helix-term/src/application.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index d0ed0c19a570..64c574acf172 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -170,7 +170,7 @@ impl Application { compositor.push(Box::new(overlaid(picker))); } else { match args.working_path { - Some(path) => helix_loader::set_current_working_dir(path.clone())?, + Some(path) => helix_loader::set_current_working_dir(path)?, None => log::warn!("invalid working path given"), } let nr_of_files = args.files.len(); From c36adf490d9611bcc3eb77c93bba6cd8ef380dbf Mon Sep 17 00:00:00 2001 From: Lloyd Bond Date: Fri, 29 Sep 2023 05:09:46 -0400 Subject: [PATCH 6/8] improved code from follow up review --- helix-term/src/application.rs | 5 ++--- helix-term/src/args.rs | 12 +++++++----- helix-term/src/main.rs | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index 64c574acf172..c8387eb42c7c 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -169,9 +169,8 @@ impl Application { let picker = ui::file_picker(".".into(), &config.load().editor); compositor.push(Box::new(overlaid(picker))); } else { - match args.working_path { - Some(path) => helix_loader::set_current_working_dir(path)?, - None => log::warn!("invalid working path given"), + if let Some(path) = args.working_directory { + helix_loader::set_current_working_dir(path)? } let nr_of_files = args.files.len(); for (i, (file, pos)) in args.files.into_iter().enumerate() { diff --git a/helix-term/src/args.rs b/helix-term/src/args.rs index 53800be530a0..f782539caa90 100644 --- a/helix-term/src/args.rs +++ b/helix-term/src/args.rs @@ -17,7 +17,7 @@ pub struct Args { pub log_file: Option, pub config_file: Option, pub files: Vec<(PathBuf, Position)>, - pub working_path: Option, + pub working_directory: Option, } impl Args { @@ -60,16 +60,18 @@ impl Args { Some(path) => args.log_file = Some(path.into()), None => anyhow::bail!("--log must specify a path to write"), }, - "-w" | "--working-path" => match argv.next().as_deref() { + "-w" | "--working-dir" => match argv.next().as_deref() { Some(path) => { - args.working_path = if Path::new(path).exists() { + args.working_directory = if Path::new(path).is_dir() { Some(PathBuf::from(path)) } else { - None + anyhow::bail!( + "--working-dir specified does not exist or is not a directory" + ) } } None => { - anyhow::bail!("--working-path must specify an initial working directory") + anyhow::bail!("--working-dir must specify an initial working directory") } }, arg if arg.starts_with("--") => { diff --git a/helix-term/src/main.rs b/helix-term/src/main.rs index 667faa16f151..0955bbe2ea08 100644 --- a/helix-term/src/main.rs +++ b/helix-term/src/main.rs @@ -66,7 +66,7 @@ FLAGS: -V, --version Prints version information --vsplit Splits all given files vertically into different windows --hsplit Splits all given files horizontally into different windows - -w, --working-path Specify an initial working directory + -w, --working-dir Specify an initial working directory ", env!("CARGO_PKG_NAME"), VERSION_AND_GIT_HASH, From ba69ecd8b18a4db18cfec29ff60c2967d9b00a09 Mon Sep 17 00:00:00 2001 From: Lloyd Bond Date: Fri, 29 Sep 2023 05:37:18 -0400 Subject: [PATCH 7/8] fix for -w is set but args.files is empty --- helix-term/src/application.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index c8387eb42c7c..7c23ddfe213f 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -156,6 +156,9 @@ impl Application { let editor_view = Box::new(ui::EditorView::new(Keymaps::new(keys))); compositor.push(editor_view); + if let Some(path) = args.working_directory { + helix_loader::set_current_working_dir(path)? + } if args.load_tutor { let path = helix_loader::runtime_file(Path::new("tutor")); editor.open(&path, Action::VerticalSplit)?; @@ -169,9 +172,6 @@ impl Application { let picker = ui::file_picker(".".into(), &config.load().editor); compositor.push(Box::new(overlaid(picker))); } else { - if let Some(path) = args.working_directory { - helix_loader::set_current_working_dir(path)? - } let nr_of_files = args.files.len(); for (i, (file, pos)) in args.files.into_iter().enumerate() { if file.is_dir() { From c061b20afb10adce7aab1dedd617ebeff2e9127c Mon Sep 17 00:00:00 2001 From: Lloyd Bond Date: Sat, 30 Sep 2023 19:50:53 -0400 Subject: [PATCH 8/8] improved formatting of --help output --- helix-term/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helix-term/src/main.rs b/helix-term/src/main.rs index 0955bbe2ea08..009cbf7f4d7a 100644 --- a/helix-term/src/main.rs +++ b/helix-term/src/main.rs @@ -66,7 +66,7 @@ FLAGS: -V, --version Prints version information --vsplit Splits all given files vertically into different windows --hsplit Splits all given files horizontally into different windows - -w, --working-dir Specify an initial working directory + -w, --working-dir Specify an initial working directory ", env!("CARGO_PKG_NAME"), VERSION_AND_GIT_HASH,