mirror of
https://github.com/nushell/nushell.git
synced 2025-07-14 05:15:23 +02:00
This commit extracts Tag, Span, Text, as well as source-related debug facilities into a new crate called nu_source. This change is much bigger than one might have expected because the previous code relied heavily on implementing inherent methods on `Tagged<T>` and `Spanned<T>`, which is no longer possible. As a result, this change creates more concrete types instead of using `Tagged<T>`. One notable example: Tagged<Value> became Value, and Value became UntaggedValue. This change clarifies the intent of the code in many places, but it does make it a big change.
42 lines
916 B
Rust
42 lines
916 B
Rust
use crate::commands::WholeStreamCommand;
|
|
use crate::prelude::*;
|
|
|
|
pub struct Debug;
|
|
|
|
#[derive(Deserialize)]
|
|
pub struct DebugArgs {}
|
|
|
|
impl WholeStreamCommand for Debug {
|
|
fn name(&self) -> &str {
|
|
"debug"
|
|
}
|
|
|
|
fn signature(&self) -> Signature {
|
|
Signature::build("debug")
|
|
}
|
|
|
|
fn usage(&self) -> &str {
|
|
"Print the Rust debug representation of the values"
|
|
}
|
|
|
|
fn run(
|
|
&self,
|
|
args: CommandArgs,
|
|
registry: &CommandRegistry,
|
|
) -> Result<OutputStream, ShellError> {
|
|
args.process(registry, debug_value)?.run()
|
|
}
|
|
}
|
|
|
|
fn debug_value(
|
|
_args: DebugArgs,
|
|
RunnableContext { input, .. }: RunnableContext,
|
|
) -> Result<impl ToOutputStream, ShellError> {
|
|
Ok(input
|
|
.values
|
|
.map(|v| {
|
|
ReturnSuccess::value(UntaggedValue::string(format!("{:?}", v)).into_untagged_value())
|
|
})
|
|
.to_output_stream())
|
|
}
|