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