Skip to main content

nu_command/debug/
experimental_options.rs

1use nu_engine::command_prelude::*;
2use nu_experimental::Status;
3
4#[derive(Clone)]
5pub struct DebugExperimentalOptions;
6
7impl Command for DebugExperimentalOptions {
8    fn name(&self) -> &str {
9        "debug experimental-options"
10    }
11
12    fn signature(&self) -> Signature {
13        Signature::build(self.name())
14            .input_output_type(
15                Type::Nothing,
16                Type::Table(
17                    vec![
18                        (String::from("identifier"), Type::String),
19                        (String::from("enabled"), Type::Bool),
20                        (String::from("status"), Type::String),
21                        (String::from("description"), Type::String),
22                        (String::from("since"), Type::String),
23                        (String::from("issue"), Type::String),
24                    ]
25                    .into(),
26                ),
27            )
28            .category(Category::Debug)
29    }
30
31    fn description(&self) -> &str {
32        "Show all experimental options."
33    }
34
35    fn run(
36        &self,
37        _engine_state: &EngineState,
38        _stack: &mut Stack,
39        call: &Call,
40        _input: PipelineData,
41    ) -> Result<PipelineData, ShellError> {
42        Ok(PipelineData::value(
43            Value::list(
44                nu_experimental::ALL
45                    .iter()
46                    .map(|option| {
47                        Value::record(
48                            nu_protocol::record! {
49                                "identifier" => Value::string(option.identifier(), call.head),
50                                "enabled" => Value::bool(option.get(), call.head),
51                                "status" => Value::string(match option.status() {
52                                    Status::OptIn => "opt-in",
53                                    Status::OptOut => "opt-out",
54                                    Status::DeprecatedDiscard => "deprecated-discard",
55                                    Status::DeprecatedDefault => "deprecated-default"
56                                }, call.head),
57                                "description" => Value::string(option.description(), call.head),
58                                "since" => Value::string({
59                                    let (major, minor, patch) = option.since();
60                                    format!("{major}.{minor}.{patch}")
61                                }, call.head),
62                                "issue" => Value::string(option.issue_url(), call.head)
63                            },
64                            call.head,
65                        )
66                    })
67                    .collect(),
68                call.head,
69            ),
70            None,
71        ))
72    }
73}