nushell / nushell.github.io

Nushell's main website, blog, book, and more
https://www.nushell.sh/book/
MIT License
162 stars 400 forks source link

[Overlays] Basic example is not usable with latest Nushell #1407

Closed jaudiger closed 1 month ago

jaudiger commented 1 month ago

From the example of chapter Basics: https://www.nushell.sh/book/overlays.html#basics

> module spam {
    export def foo [] {
        "foo"
    }

    export alias bar = "bar"

    export-env {
        load-env { BAZ: "baz" }
    }
}

I got the following error using Nushell 0.93.0:

Error: nu::parser::cant_alias_expression

  × Can't create alias to expression.
   ╭─[entry #1:6:24]
 5 │
 6 │     export alias bar = "bar"
   ·                        ──┬──
   ·                          ╰── aliasing String is not supported
 7 │
   ╰────
  help: Only command calls can be aliased.
fdncred commented 1 month ago

I think this

export alias bar = "bar"

needs to be changed to this

export alias bar = echo "bar"
jaudiger commented 1 month ago

Works like a charm with the modification:

module spam {
    export def foo [] {
        "foo"
    }

    export alias bar = echo "bar"

    export-env {
        load-env { BAZ: "baz" }
    }
}

use spam

spam bar
> bar
jaudiger commented 1 month ago

I could open a PR if you want

fdncred commented 1 month ago

sure, go for it. thx!