Skip to main content

nu_command/filesystem/idx/
files.rs

1use super::state::stream_files;
2use nu_engine::command_prelude::*;
3
4#[derive(Clone)]
5pub struct IdxFiles;
6
7impl Command for IdxFiles {
8    fn name(&self) -> &str {
9        "idx files"
10    }
11
12    fn signature(&self) -> Signature {
13        Signature::build(self.name())
14            .optional(
15                "path",
16                SyntaxShape::String,
17                "Optional path to lookup in index.",
18            )
19            .input_output_types(vec![(Type::Nothing, Type::List(Box::new(Type::record())))])
20            .category(Category::FileSystem)
21    }
22
23    fn description(&self) -> &str {
24        "List indexed files, or lookup a specific indexed path."
25    }
26
27    fn examples(&self) -> Vec<Example<'_>> {
28        vec![
29            Example {
30                description: "List all indexed files",
31                example: "idx files",
32                result: None,
33            },
34            Example {
35                description: "Lookup a specific file path in the index",
36                example: "idx files src/main.rs",
37                result: None,
38            },
39        ]
40    }
41
42    fn run(
43        &self,
44        engine_state: &EngineState,
45        stack: &mut Stack,
46        call: &Call,
47        _input: PipelineData,
48    ) -> Result<PipelineData, ShellError> {
49        let path = call.opt::<String>(engine_state, stack, 0)?;
50        let signals = engine_state.signals();
51        stream_files(path, call.head, signals)
52    }
53}