nu_command/debug/
view_files.rs1use nu_engine::command_prelude::*;
2
3#[derive(Clone)]
4pub struct ViewFiles;
5
6impl Command for ViewFiles {
7 fn name(&self) -> &str {
8 "view files"
9 }
10
11 fn description(&self) -> &str {
12 "View the files registered in nushell's EngineState memory."
13 }
14
15 fn extra_description(&self) -> &str {
16 "These are files parsed and loaded at runtime."
17 }
18
19 fn signature(&self) -> nu_protocol::Signature {
20 Signature::build("view files")
21 .input_output_types(vec![(
22 Type::Nothing,
23 Type::Table(
24 [
25 ("filename".into(), Type::String),
26 ("start".into(), Type::Int),
27 ("end".into(), Type::Int),
28 ("size".into(), Type::Int),
29 ]
30 .into(),
31 ),
32 )])
33 .category(Category::Debug)
34 }
35
36 fn run(
37 &self,
38 engine_state: &EngineState,
39 _stack: &mut Stack,
40 call: &Call,
41 _input: PipelineData,
42 ) -> Result<PipelineData, ShellError> {
43 let mut records = vec![];
44
45 for file in engine_state.files() {
46 let start = file.covered_span.start;
47 let end = file.covered_span.end;
48 records.push(Value::record(
49 record! {
50 "filename" => Value::string(&*file.name, call.head),
51 "start" => Value::int(start as i64, call.head),
52 "end" => Value::int(end as i64, call.head),
53 "size" => Value::int(end as i64 - start as i64, call.head),
54 },
55 call.head,
56 ));
57 }
58
59 Ok(Value::list(records, call.head).into_pipeline_data())
60 }
61
62 fn examples(&self) -> Vec<Example> {
63 vec![
64 Example {
65 description: "View the files registered in Nushell's EngineState memory",
66 example: r#"view files"#,
67 result: None,
68 },
69 Example {
70 description: "View how Nushell was originally invoked",
71 example: r#"view files | get 0"#,
72 result: None,
73 },
74 ]
75 }
76}