nu_command/filesystem/idx/
export.rs1use super::state::store_snapshot;
2use nu_engine::command_prelude::*;
3#[derive(Clone)]
4pub struct IdxExport;
5
6impl Command for IdxExport {
7 fn name(&self) -> &str {
8 "idx export"
9 }
10
11 fn signature(&self) -> Signature {
12 Signature::build(self.name())
13 .required(
14 "filepath",
15 SyntaxShape::Filepath,
16 "Path where idx snapshot should be stored.",
17 )
18 .input_output_types(vec![(Type::Nothing, Type::record())])
19 .category(Category::FileSystem)
20 }
21
22 fn description(&self) -> &str {
23 "Persist idx state to disk."
24 }
25
26 fn extra_description(&self) -> &str {
27 "The snapshot is stored as a SQLite database. Use `idx import` to reload it."
28 }
29
30 fn examples(&self) -> Vec<Example<'_>> {
31 vec![Example {
32 description: "Save the current idx index to disk",
33 example: "idx export ~/my-index.db",
34 result: None,
35 }]
36 }
37
38 fn run(
39 &self,
40 engine_state: &EngineState,
41 stack: &mut Stack,
42 call: &Call,
43 _input: PipelineData,
44 ) -> Result<PipelineData, ShellError> {
45 let path: Spanned<String> = call.req(engine_state, stack, 0)?;
46 let cwd = engine_state.cwd(Some(stack))?;
47 let abs = nu_path::expand_path_with(path.item, cwd, true);
48 Ok(PipelineData::value(
49 store_snapshot(abs.as_ref(), call.head)?,
50 None,
51 ))
52 }
53}