From 2e68a48cb09ff3064258c12eee0bff33403cb47c Mon Sep 17 00:00:00 2001 From: Serg Tereshchenko Date: Fri, 10 Dec 2021 20:45:36 +0200 Subject: [PATCH] refactor: Use neovim_args for passing files to open --- src/bridge/mod.rs | 3 +-- src/cmd_line.rs | 21 +++++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/bridge/mod.rs b/src/bridge/mod.rs index d5163ff..ca61906 100644 --- a/src/bridge/mod.rs +++ b/src/bridge/mod.rs @@ -124,8 +124,7 @@ pub fn create_nvim_command() -> Command { let mut cmd = build_nvim_cmd(); cmd.arg("--embed") - .args(SETTINGS.get::().neovim_args.iter()) - .args(SETTINGS.get::().files_to_open.iter()); + .args(SETTINGS.get::().neovim_args.iter()); info!("Starting neovim with: {:?}", cmd); diff --git a/src/cmd_line.rs b/src/cmd_line.rs index 034a493..658d3da 100644 --- a/src/cmd_line.rs +++ b/src/cmd_line.rs @@ -7,7 +7,6 @@ use clap::{App, Arg}; pub struct CmdLineSettings { // Pass through arguments pub neovim_args: Vec, - pub files_to_open: Vec, // Command-line arguments only pub geometry: Dimensions, pub verbosity: u64, @@ -32,7 +31,6 @@ impl Default for CmdLineSettings { Self { // Pass through arguments neovim_args: vec![], - files_to_open: vec![], // Command-line arguments only geometry: DEFAULT_WINDOW_GEOMETRY, verbosity: 0, @@ -152,6 +150,16 @@ pub fn handle_command_line_arguments(args: Vec) -> Result<(), String> { ); let matches = clapp.get_matches_from(args); + let mut neovim_args: Vec = matches + .values_of("neovim_args") + .map(|opt| opt.map(|v| v.to_owned()).collect()) + .unwrap_or_default(); + neovim_args.extend::>( + matches + .values_of("files_to_open") + .map(|opt| opt.map(|v| v.to_owned()).collect()) + .unwrap_or_default(), + ); /* * Integrate Environment Variables as Defaults to the command-line ones. @@ -160,14 +168,7 @@ pub fn handle_command_line_arguments(args: Vec) -> Result<(), String> { */ SETTINGS.set::(&CmdLineSettings { // Pass through arguments - neovim_args: matches - .values_of("neovim_args") - .map(|opt| opt.map(|v| v.to_owned()).collect()) - .unwrap_or_default(), - files_to_open: matches - .values_of("files_to_open") - .map(|opt| opt.map(|v| v.to_owned()).collect()) - .unwrap_or_default(), + neovim_args: neovim_args, // Command-line arguments only verbosity: matches.occurrences_of("verbosity"), geometry: parse_window_geometry(matches.value_of("geometry").map(|i| i.to_owned()))?,