mirror of
https://github.com/nushell/nushell
synced 2024-12-28 05:53:09 +00:00
allow view-source to view aliases (#6135)
This commit is contained in:
parent
d856ac92f4
commit
b12a3dd0e5
1 changed files with 18 additions and 0 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
use itertools::Itertools;
|
||||||
use nu_engine::CallExt;
|
use nu_engine::CallExt;
|
||||||
use nu_protocol::ast::Call;
|
use nu_protocol::ast::Call;
|
||||||
use nu_protocol::engine::{Command, EngineState, Stack};
|
use nu_protocol::engine::{Command, EngineState, Stack};
|
||||||
|
@ -131,6 +132,15 @@ impl Command for ViewSource {
|
||||||
Vec::new(),
|
Vec::new(),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
} else if let Some(alias_id) = engine_state.find_alias(val.as_bytes(), &[]) {
|
||||||
|
let contents = &mut engine_state.get_alias(alias_id).iter().map(|span| {
|
||||||
|
String::from_utf8_lossy(engine_state.get_span_contents(span)).to_string()
|
||||||
|
});
|
||||||
|
Ok(Value::String {
|
||||||
|
val: contents.join(" "),
|
||||||
|
span: call.head,
|
||||||
|
}
|
||||||
|
.into_pipeline_data())
|
||||||
} else {
|
} else {
|
||||||
Err(ShellError::GenericError(
|
Err(ShellError::GenericError(
|
||||||
"Cannot view value".to_string(),
|
"Cannot view value".to_string(),
|
||||||
|
@ -185,6 +195,14 @@ impl Command for ViewSource {
|
||||||
span: Span::test_data(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
|
Example {
|
||||||
|
description: "View the source of an alias",
|
||||||
|
example: r#"alias hello = echo hi; view-source hello"#,
|
||||||
|
result: Some(Value::String {
|
||||||
|
val: "echo hi".to_string(),
|
||||||
|
span: Span::test_data(),
|
||||||
|
}),
|
||||||
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue