mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 14:15:53 +02:00
Add example for enter, shells and view-source, update some docs (#4604)
This commit is contained in:
@ -2,7 +2,8 @@ use nu_engine::CallExt;
|
||||
use nu_protocol::ast::Call;
|
||||
use nu_protocol::engine::{Command, EngineState, Stack};
|
||||
use nu_protocol::{
|
||||
Category, IntoPipelineData, PipelineData, ShellError, Signature, SyntaxShape, Value,
|
||||
Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, SyntaxShape,
|
||||
Value,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
@ -99,4 +100,41 @@ impl Command for ViewSource {
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
vec![
|
||||
Example {
|
||||
description: "View the source of a code block",
|
||||
example: r#"let abc = { echo 'hi' }; view-source $abc"#,
|
||||
result: Some(Value::String {
|
||||
val: "{ echo 'hi' }".to_string(),
|
||||
span: Span::test_data(),
|
||||
}),
|
||||
},
|
||||
Example {
|
||||
description: "View the source of a custom command",
|
||||
example: r#"def hi [] { echo 'Hi!' }; view-source hi"#,
|
||||
result: Some(Value::String {
|
||||
val: "{ echo 'Hi!' }".to_string(),
|
||||
span: Span::test_data(),
|
||||
}),
|
||||
},
|
||||
Example {
|
||||
description: "View the source of a custom command, which participates in the caller environment",
|
||||
example: r#"def-env foo [] { let-env BAR = 'BAZ' }; view-source foo"#,
|
||||
result: Some(Value::String {
|
||||
val: "{ let-env BAR = 'BAZ' }".to_string(),
|
||||
span: Span::test_data(),
|
||||
}),
|
||||
},
|
||||
Example {
|
||||
description: "View the source of a module",
|
||||
example: r#"module mod-foo { export env FOO_ENV { 'BAZ' } }; view-source mod-foo"#,
|
||||
result: Some(Value::String {
|
||||
val: " export env FOO_ENV { 'BAZ' }".to_string(),
|
||||
span: Span::test_data(),
|
||||
}),
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
use nu_engine::{current_dir, CallExt};
|
||||
use nu_protocol::ast::Call;
|
||||
use nu_protocol::engine::{Command, EngineState, Stack};
|
||||
use nu_protocol::{Category, PipelineData, ShellError, Signature, SyntaxShape, Value};
|
||||
use nu_protocol::{Category, Example, PipelineData, ShellError, Signature, SyntaxShape, Value};
|
||||
|
||||
/// Source a file for environment variables.
|
||||
#[derive(Clone)]
|
||||
@ -105,4 +105,12 @@ impl Command for Enter {
|
||||
|
||||
Ok(PipelineData::new(call.head))
|
||||
}
|
||||
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
vec![Example {
|
||||
description: "Enter a new shell at path '../dir-foo'",
|
||||
example: r#"enter ../dir-foo"#,
|
||||
result: None,
|
||||
}]
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ use nu_engine::current_dir;
|
||||
use nu_protocol::ast::Call;
|
||||
use nu_protocol::engine::{Command, EngineState, Stack};
|
||||
use nu_protocol::{
|
||||
Category, IntoInterruptiblePipelineData, PipelineData, ShellError, Signature, Value,
|
||||
Category, Example, IntoInterruptiblePipelineData, PipelineData, ShellError, Signature, Value,
|
||||
};
|
||||
|
||||
/// Source a file for environment variables.
|
||||
@ -69,4 +69,19 @@ impl Command for Shells {
|
||||
|
||||
Ok(output.into_pipeline_data(None))
|
||||
}
|
||||
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
vec![
|
||||
Example {
|
||||
description: "Enter a new shell at parent path '..' and show all opened shells",
|
||||
example: r#"enter ..; shells"#,
|
||||
result: None,
|
||||
},
|
||||
Example {
|
||||
description: "Show currently active shell",
|
||||
example: r#"shells | where active == $true"#,
|
||||
result: None,
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user