Add meta command for the config subcommands (#5616)

When using `config` without the `config nu` or `config env` subcommands
introduced by #5607 display basic usage like `str`.
This commit is contained in:
Stefan Holderbach 2022-05-22 19:31:57 +02:00 committed by GitHub
parent d534a89867
commit 6ff717c0ba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 50 additions and 0 deletions

View file

@ -317,6 +317,7 @@ pub fn create_default_context(cwd: impl AsRef<Path>) -> EngineState {
WithEnv,
ConfigNu,
ConfigEnv,
ConfigMeta,
};
// Math

View file

@ -0,0 +1,46 @@
use nu_engine::get_full_help;
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, Stack},
Category, IntoPipelineData, PipelineData, Signature, Value,
};
#[derive(Clone)]
pub struct ConfigMeta;
impl Command for ConfigMeta {
fn name(&self) -> &str {
"config"
}
fn signature(&self) -> Signature {
Signature::build(self.name()).category(Category::Env)
}
fn usage(&self) -> &str {
"Edit nushell configuration files"
}
fn run(
&self,
engine_state: &EngineState,
stack: &mut Stack,
call: &Call,
_input: PipelineData,
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
Ok(Value::String {
val: get_full_help(
&ConfigMeta.signature(),
&ConfigMeta.examples(),
engine_state,
stack,
),
span: call.head,
}
.into_pipeline_data())
}
fn search_terms(&self) -> Vec<&str> {
vec!["options", "setup"]
}
}

View file

@ -1,5 +1,7 @@
mod config_;
mod config_env;
mod config_nu;
mod utils;
pub use config_::ConfigMeta;
pub use config_env::ConfigEnv;
pub use config_nu::ConfigNu;

View file

@ -5,6 +5,7 @@ mod load_env;
mod with_env;
pub use config::ConfigEnv;
pub use config::ConfigMeta;
pub use config::ConfigNu;
pub use env_command::Env;
pub use let_env::LetEnv;