Subcommand fails silently when main is not specified
Open
Nobody has claimed this yet.
A:error-silent-fail
A:scoping/name-resolution
status:needs-triage
- Dominant language
- Rust
- Stars
- 40.5k
- Forks
- 2.3k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 85
Description
Describe the bug
If you create a script with a subcommand but does not specify an empty main then then running the subcommand has no effect. It should either succeed or fail explicitly.
How to reproduce
- Given the
repro.nuscript below
#!/usr/bin/env nu
# def main [] { }
def 'main subcommand' [] {
print x
}
- Run
nu repro.nu - x does not get printed to the screen. If you uncomment the
# def main [] {}line then x gets printed to the screen.
Expected behavior
I expected nushell to either print x or generate a failure saying that a main needs to be specified.
Configuration
| key | value |
|---|---|
| version | 0.98.0 |
| major | 0 |
| minor | 98 |
| patch | 0 |
| branch | main |
| commit_hash | 25a15d56f171313dd9e6170d427ba4c580c69ee4 |
| build_os | macos-aarch64 |
| build_target | aarch64-apple-darwin |
| rust_version | rustc 1.81.0-nightly (eeb90cda1 2024-09-04) (built from a source tarball) |
| cargo_version | cargo 1.64.0 |
| build_time | 2024-09-18 04:03:30 -04:00 |
| build_rust_channel | release |
| allocator | mimalloc |
| features | default, sqlite, trash |
| installed_plugins |
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the behavior with the provided repro.nu script, comparing runs with and without the empty main definition. Trace how Nushell dispatches scripts containing only a subcommand, then add coverage showing that execution either invokes the subcommand or reports that a main is required.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust, shell
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100