Repository: nushell/nushell
File: crates/nu-cmd-lang/src/core_commands/overlay/list.rs (Rust)

Code before:
    fn extra_description(&self) -> &str {
        "The overlays are listed in the order they were activated."
    }

    fn run(
        &self,
        engine_state: &EngineState,
        stack: &mut Stack,
        call: &Call,
        _input: PipelineData,
    ) -> Result<PipelineData, ShellError> {
        let show_hidden = call.has_flag(engine_state, stack, "hidden")?;

        let overlays: Vec<Value> = if show_hidden {
            // Show all overlays from engine state (including hidden ones)
            engine_state
                .scope
                .overlays
                .iter()
                .filter_map(|(name, _)| {
                    let overlay_name = String::from_utf8_lossy(name);
                    stack
                        .active_overlays
                        .iter()
                        .all(|name| name.as_str() != overlay_name) // filter already existing overlays
                        .then_some(Value::string(overlay_name, call.head))
                })
                .collect()
        } else {
            // Show only active overlays from stack
            stack
                .active_overlays
                .iter()
                .map(|s| Value::string(s, call.head))
                .collect()
        };

        Ok(Value::list(overlays, call.head).into_pipeline_data())
    }

    fn examples(&self) -> Vec<Example> {
        vec![
            Example {
                description: "Get the last activated overlay",
                example: r#"module spam { export def foo [] { "foo" } }
    overlay use spam
    overlay list | last"#,
                result: Some(Value::test_string("spam")),
            },
            Example {
                description: "List all overlays including hidden ones",

Review comment (suggestion):
Is `--hidden` supposed to show all overlays, or just hidden overlays? The comment above implies all, but this section filters out the active overlays

Maybe instead `overlay list` should output `table<name: string, active: bool>`? Then we don't need a flag, and you could get hidden overlays with `overlay list | where not active`

Code after:
                        ("name".to_string(), Type::String),
                        ("active".to_string(), Type::Bool),
                    ]
                    .into(),
                ),
            )])
    }

    fn extra_description(&self) -> &str {
        "The overlays are listed in the order they were activated. Hidden overlays are listed first, followed by active overlays listed in the order that they were activated. `last` command will always give the top active overlay"
    }

    fn run(
        &self,
        engine_state: &EngineState,
        stack: &mut Stack,
        call: &Call,
        _input: PipelineData,
    ) -> Result<PipelineData, ShellError> {
        // get active overlay iterator
        let active_overlays = stack
            .active_overlays
            .iter()
            .map(|overlay| (overlay.clone(), true));

        // Get all overlay names from engine state
        let output_rows: Vec<Value> = engine_state
            .scope
            .overlays
            .iter()
            .filter_map(|(name, _)| {
                let name = String::from_utf8_lossy(name).to_string();
                if stack
                    .active_overlays
                    .iter()
                    .any(|active_name| active_name == &name)
                {
                    None
                } else {
                    Some((name, false))
                }
            })
            .chain(active_overlays)
            .map(|(name, active)| {
                Value::record(
                    record! {
                        "name" => Value::string(name.to_owned(), call.head),
                        "active" => Value::bool(active, call.head),
                    },
                    call.head,
                )