mirror of
https://github.com/nushell/nushell.git
synced 2025-08-18 00:39:54 +02:00
Add tags command and fix source_map transfer
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
use crate::commands::command::Sink;
|
||||
use crate::context::SourceMap;
|
||||
use crate::parser::{registry::Args, TokenNode};
|
||||
use crate::prelude::*;
|
||||
use bytes::{BufMut, BytesMut};
|
||||
@@ -113,7 +112,6 @@ impl SinkCommand {
|
||||
crate struct InternalCommand {
|
||||
crate command: Arc<dyn Command>,
|
||||
crate name_span: Option<Span>,
|
||||
crate source_map: SourceMap,
|
||||
crate args: Args,
|
||||
}
|
||||
|
||||
@@ -135,7 +133,7 @@ impl InternalCommand {
|
||||
let result = context.run_command(
|
||||
self.command,
|
||||
self.name_span.clone(),
|
||||
self.source_map,
|
||||
context.source_map.clone(),
|
||||
self.args,
|
||||
objects,
|
||||
)?;
|
||||
|
32
src/commands/tags.rs
Normal file
32
src/commands/tags.rs
Normal file
@@ -0,0 +1,32 @@
|
||||
use crate::errors::ShellError;
|
||||
use crate::object::{TaggedDictBuilder, Value};
|
||||
use crate::prelude::*;
|
||||
|
||||
pub fn tags(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let source_map = args.call_info.source_map.clone();
|
||||
Ok(args
|
||||
.input
|
||||
.values
|
||||
.map(move |v| {
|
||||
let mut tags = TaggedDictBuilder::new(v.span());
|
||||
{
|
||||
let span = v.span();
|
||||
let mut dict = TaggedDictBuilder::new(v.span());
|
||||
dict.insert("start", Value::int(span.start as i64));
|
||||
dict.insert("end", Value::int(span.end as i64));
|
||||
match span.source.map(|x| source_map.get(&x)).flatten() {
|
||||
Some(SpanSource::File(source)) => {
|
||||
dict.insert("source", Value::string(source));
|
||||
}
|
||||
Some(SpanSource::Url(source)) => {
|
||||
dict.insert("source", Value::string(source));
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
tags.insert_tagged("span", dict.into_tagged_value());
|
||||
}
|
||||
|
||||
tags.into_tagged_value()
|
||||
})
|
||||
.to_output_stream())
|
||||
}
|
Reference in New Issue
Block a user