mirror of
https://github.com/nushell/nushell.git
synced 2025-08-18 03:29:57 +02:00
Add plugin CLI argument (#6064)
* Add plugin CLI argument While working on supporting CustomValues in Plugins I stumbled upon the test utilities defined in [nu-test-support][nu-test-support] and thought these will come in handy, but they end up being outdated. They haven't been used or since engine-q's was merged, so they are currently using the old way engine-q handled plugins, where it would just look into a specific folder for plugins and call them without signatures or registration. While fixing that I realized that there is currently no way to tell nushell to load and save signatures into a specific path, and so those integration tests could end up potentially conflicting with each other and with the local plugins the person running them is using. So this adds a new CLI argument to specify where to store and load plugin signatures from I am not super sure of the way I implemented this, mainly I was a bit confused about the distinction between [src/config_files.rs][src/config_files.rs] and [crates/nu-cli/src/config_files.rs][crates/nu-cli/src/config_files.rs]. Should I be moving the plugin loading function from the `nu-cli` one to the root one? [nu-test-support]:9d0be7d96f/crates/nu-test-support/src/macros.rs (L106)
[src/config_files.rs]:9d0be7d96f/src/config_files.rs
[crates/nu-cli/src/config_files.rs]:9d0be7d96f/crates/nu-cli/src/config_files.rs
* Gate new CLI option behind plugin feature * Rename option to plugin-config
This commit is contained in:
42
src/main.rs
42
src/main.rs
@@ -103,6 +103,8 @@ fn main() -> Result<()> {
|
||||
args.next().map(|a| escape_quote_string(&a))
|
||||
}
|
||||
"--config" | "--env-config" => args.next().map(|a| escape_quote_string(&a)),
|
||||
#[cfg(feature = "plugin")]
|
||||
"--plugin-config" => args.next().map(|a| escape_quote_string(&a)),
|
||||
"--log-level" | "--testbin" | "--threads" | "-t" => args.next(),
|
||||
_ => None,
|
||||
};
|
||||
@@ -204,6 +206,7 @@ fn main() -> Result<()> {
|
||||
read_plugin_file(
|
||||
&mut engine_state,
|
||||
&mut stack,
|
||||
binary_args.plugin_file,
|
||||
NUSHELL_FOLDER,
|
||||
is_perf_true(),
|
||||
);
|
||||
@@ -256,6 +259,7 @@ fn main() -> Result<()> {
|
||||
read_plugin_file(
|
||||
&mut engine_state,
|
||||
&mut stack,
|
||||
binary_args.plugin_file,
|
||||
NUSHELL_FOLDER,
|
||||
is_perf_true(),
|
||||
);
|
||||
@@ -304,6 +308,8 @@ fn main() -> Result<()> {
|
||||
setup_config(
|
||||
&mut engine_state,
|
||||
&mut stack,
|
||||
#[cfg(feature = "plugin")]
|
||||
binary_args.plugin_file,
|
||||
binary_args.config_file,
|
||||
binary_args.env_file,
|
||||
binary_args.login_shell.is_some(),
|
||||
@@ -329,12 +335,19 @@ fn main() -> Result<()> {
|
||||
fn setup_config(
|
||||
engine_state: &mut EngineState,
|
||||
stack: &mut Stack,
|
||||
#[cfg(feature = "plugin")] plugin_file: Option<Spanned<String>>,
|
||||
config_file: Option<Spanned<String>>,
|
||||
env_file: Option<Spanned<String>>,
|
||||
is_login_shell: bool,
|
||||
) {
|
||||
#[cfg(feature = "plugin")]
|
||||
read_plugin_file(engine_state, stack, NUSHELL_FOLDER, is_perf_true());
|
||||
read_plugin_file(
|
||||
engine_state,
|
||||
stack,
|
||||
plugin_file,
|
||||
NUSHELL_FOLDER,
|
||||
is_perf_true(),
|
||||
);
|
||||
|
||||
if is_perf_true() {
|
||||
info!("read_config_file {}:{}:{}", file!(), line!(), column!());
|
||||
@@ -398,6 +411,8 @@ fn parse_commandline_args(
|
||||
let commands: Option<Expression> = call.get_flag_expr("commands");
|
||||
let testbin: Option<Expression> = call.get_flag_expr("testbin");
|
||||
let perf = call.has_flag("perf");
|
||||
#[cfg(feature = "plugin")]
|
||||
let plugin_file: Option<Expression> = call.get_flag_expr("plugin-config");
|
||||
let config_file: Option<Expression> = call.get_flag_expr("config");
|
||||
let env_file: Option<Expression> = call.get_flag_expr("env-config");
|
||||
let log_level: Option<Expression> = call.get_flag_expr("log-level");
|
||||
@@ -425,6 +440,8 @@ fn parse_commandline_args(
|
||||
|
||||
let commands = extract_contents(commands)?;
|
||||
let testbin = extract_contents(testbin)?;
|
||||
#[cfg(feature = "plugin")]
|
||||
let plugin_file = extract_contents(plugin_file)?;
|
||||
let config_file = extract_contents(config_file)?;
|
||||
let env_file = extract_contents(env_file)?;
|
||||
let log_level = extract_contents(log_level)?;
|
||||
@@ -455,6 +472,8 @@ fn parse_commandline_args(
|
||||
interactive_shell,
|
||||
commands,
|
||||
testbin,
|
||||
#[cfg(feature = "plugin")]
|
||||
plugin_file,
|
||||
config_file,
|
||||
env_file,
|
||||
log_level,
|
||||
@@ -478,6 +497,8 @@ struct NushellCliArgs {
|
||||
interactive_shell: Option<Spanned<String>>,
|
||||
commands: Option<Spanned<String>>,
|
||||
testbin: Option<Spanned<String>>,
|
||||
#[cfg(feature = "plugin")]
|
||||
plugin_file: Option<Spanned<String>>,
|
||||
config_file: Option<Spanned<String>>,
|
||||
env_file: Option<Spanned<String>>,
|
||||
log_level: Option<Spanned<String>>,
|
||||
@@ -495,7 +516,7 @@ impl Command for Nu {
|
||||
}
|
||||
|
||||
fn signature(&self) -> Signature {
|
||||
Signature::build("nu")
|
||||
let signature = Signature::build("nu")
|
||||
.usage("The nushell language and shell.")
|
||||
.switch("stdin", "redirect the stdin", None)
|
||||
.switch("login", "start as a login shell", Some('l'))
|
||||
@@ -558,7 +579,22 @@ impl Command for Nu {
|
||||
SyntaxShape::String,
|
||||
"parameters to the script file",
|
||||
)
|
||||
.category(Category::System)
|
||||
.category(Category::System);
|
||||
|
||||
#[cfg(feature = "plugin")]
|
||||
{
|
||||
signature.named(
|
||||
"plugin-config",
|
||||
SyntaxShape::String,
|
||||
"start with an alternate plugin signature file",
|
||||
None,
|
||||
)
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "plugin"))]
|
||||
{
|
||||
signature
|
||||
}
|
||||
}
|
||||
|
||||
fn usage(&self) -> &str {
|
||||
|
Reference in New Issue
Block a user