-
Notifications
You must be signed in to change notification settings - Fork 2.1k
"help main" in a script that has some sort of top level import/use shows the wrong help message #10499
Description
Describe the bug
I have a script file, which contains a bunch of commands like a root level def main and some def "main sub" etc. The script has an import of std log, i.e. a line containing import std log at the top. In my main definition, i have a --version flag, which if passed shows the version, else it shows the help command, this is what most of the in-built commands of nu does, that is show help command when no args are passed.
But this does not work. When no args is passed, i do help main, but instead of showing help message for the main command, it shows the help message of the imported log module from std log.
Running nu script.nu --help works fine, but doing nu script.nu which invokes help main in the script file does not work.
How to reproduce
Here's a reproducable script
use std log
# Root command
def main [
--version(-v)
] {
if $version {
log info "printing version"
print "version"
}
help main
}
# a subcommand
def "main sub" [
--some-flag?: string
] {
print "something to do here"
}Screenshots have been attached below
Expected behavior
Show help for the script file instead of showing help for the log module.
Screenshots
--help command works fine:

Does not work when no args are passed

Configuration
| key | value |
|---|---|
| version | 0.85.0 |
| branch | |
| commit_hash | a6f62e0 |
| build_os | windows-x86_64 |
| build_target | x86_64-pc-windows-msvc |
| rust_version | rustc 1.70.0 (90c541806 2023-05-31) |
| rust_channel | 1.70.0-x86_64-pc-windows-msvc |
| cargo_version | cargo 1.70.0 (ec8a8a0ca 2023-04-25) |
| build_time | 2023-09-19 19:00:31 +00:00 |
| build_rust_channel | release |
| allocator | mimalloc |
| features | default, sqlite, trash, which, zip |
| installed_plugins |
Additional context
No response