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::new(self.name())
14            .input_output_type(
15                Type::Nothing,
16                Type::Table(Box::from([
17                    (String::from("identifier"), Type::String),
18                    (String::from("enabled"), Type::Bool),
19                    (String::from("status"), Type::String),
20                    (String::from("description"), Type::String),
21                    (String::from("since"), Type::String),
22                    (String::from("issue"), Type::String),
23                ])),
24            )
25            .add_help()
26            .category(Category::Debug)
27    }
28
29    fn description(&self) -> &str {
30        "Show all experimental options."
31    }
32
33    fn run(
34        &self,
35        _engine_state: &EngineState,
36        _stack: &mut Stack,
37        call: &Call,
38        _input: PipelineData,
39    ) -> Result<PipelineData, ShellError> {
40        Ok(PipelineData::value(
41            Value::list(
42                nu_experimental::ALL
43                    .iter()
44                    .map(|option| {
45                        Value::record(
46                            nu_protocol::record! {
47                                "identifier" => Value::string(option.identifier(), call.head),
48                                "enabled" => Value::bool(option.get(), call.head),
49                                "status" => Value::string(match option.status() {
50                                    Status::OptIn => "opt-in",
51                                    Status::OptOut => "opt-out",
52                                    Status::DeprecatedDiscard => "deprecated-discard",
53                                    Status::DeprecatedDefault => "deprecated-default"
54                                }, call.head),
55                                "description" => Value::string(option.description(), call.head),
56                                "since" => Value::string({
57                                    let (major, minor, patch) = option.since();
58                                    format!("{major}.{minor}.{patch}")
59                                }, call.head),
60                                "issue" => Value::string(option.issue_url(), call.head)
61                            },
62                            call.head,
63                        )
64                    })
65                    .collect(),
66                call.head,
67            ),
68            None,
69        ))
70    }
71}