mirror of
https://github.com/nushell/nushell
synced 2024-12-27 05:23:11 +00:00
Fix view-source command (#4486)
This commit is contained in:
parent
f824388f63
commit
df07e8e410
1 changed files with 10 additions and 6 deletions
|
@ -35,12 +35,16 @@ impl Command for ViewSource {
|
|||
let arg_span = arg.span()?;
|
||||
|
||||
match arg {
|
||||
Value::Block { span, .. } => {
|
||||
let contents = engine_state.get_span_contents(&span);
|
||||
Ok(
|
||||
Value::string(String::from_utf8_lossy(contents), call.head)
|
||||
.into_pipeline_data(),
|
||||
)
|
||||
Value::Block { val: block_id, .. } => {
|
||||
let block = engine_state.get_block(block_id);
|
||||
|
||||
if let Some(span) = block.span {
|
||||
let contents = engine_state.get_span_contents(&span);
|
||||
Ok(Value::string(String::from_utf8_lossy(contents), call.head)
|
||||
.into_pipeline_data())
|
||||
} else {
|
||||
Ok(Value::string("<internal command>", call.head).into_pipeline_data())
|
||||
}
|
||||
}
|
||||
Value::String { val, .. } => {
|
||||
if let Some(decl_id) = engine_state.find_decl(val.as_bytes()) {
|
||||
|
|
Loading…
Reference in a new issue