Skip to content

feat(help): add --help to builtins and extend help command#129

Merged
matt-dz merged 10 commits intomainfrom
matt-dz/add-help-flags
Mar 19, 2026
Merged

feat(help): add --help to builtins and extend help command#129
matt-dz merged 10 commits intomainfrom
matt-dz/add-help-flags

Conversation

@matt-dz
Copy link
Copy Markdown
Collaborator

@matt-dz matt-dz commented Mar 19, 2026

Summary

  • Added `--help` to `break`, `continue`, `exit` — matches bash builtin behaviour (stdout, exit code 2, byte-for-byte verified against debian:bookworm-slim)
  • Extended `help` builtin to support `help ` — displays detailed help for any command
    • For commands with `--help` (cat, grep, etc.): dynamically invokes the command and captures output — no static strings to maintain
    • For commands without `--help` (echo, true, false): uses a static `Help` field on the `Command` struct
  • Kept `echo`, `true`, `false` matching bash builtin behaviour — these ignore `--help` silently, matching bash
  • Added `Help` field to `Command` and `CommandMeta` structs for fallback help text
  • `help` with no args still lists all commands; `help ` shows detailed help; extra operands are rejected

Test plan

  • All unit tests pass (`go test -race ./...`)
  • All scenario tests pass (`go test ./tests/ -run TestShellScenarios`)
  • Bash comparison tests pass byte-for-byte (`RSHELL_BASH_TEST=1 go test ./tests/ -run TestShellScenariosAgainstBash`)
  • `break --help`, `continue --help`, `exit --help` output matches bash exactly
  • `exit --help` does not exit the shell
  • `echo --help` prints literal "--help" (bash compat)
  • `true --help` / `false --help` are silent no-ops (bash compat)
  • `help echo` / `help true` / `help false` show help via static field
  • `help cat` / `help grep` etc. show help via dynamic capture
  • `help nonexistent` shows error
  • `help echo typo` rejects extra operands
  • CI passes

🤖 Generated with Claude Code

- break, continue, exit: match bash builtin behaviour (stderr, exit code 2)
- echo, true, false: match GNU coreutils behaviour (stdout, exit code 0)
- Add scenario tests for all 6 commands
- Update existing tests that expected --help to be ignored

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@matt-dz
Copy link
Copy Markdown
Collaborator Author

matt-dz commented Mar 19, 2026

@codex conduct a comprehensive security and code review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 678dd226cf

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread builtins/false/false.go Outdated
Comment thread builtins/echo/echo.go Outdated
Comment thread builtins/true/true.go Outdated
matt-dz and others added 3 commits March 19, 2026 09:44
false is a guaranteed failure primitive and should always exit non-zero,
even when displaying help text.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
echo is a shell builtin — bash's builtin echo treats --help as literal
text, not a flag. Reverts to bash-compatible behaviour.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
true and false are shell builtins — bash ignores all arguments silently.
Reverts to bash-compatible behaviour where --help is a no-op.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@matt-dz
Copy link
Copy Markdown
Collaborator Author

matt-dz commented Mar 19, 2026

@codex conduct a comprehensive security and code review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a1a49073cd

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread builtins/break/break.go Outdated
Comment thread tests/scenarios/cmd/exit/help.yaml Outdated
matt-dz and others added 3 commits March 19, 2026 10:14
Add per-command help text to all 26 builtins via a new Help field on the
Command struct. Running 'help <command>' now displays detailed usage for
that command, matching the output of '<command> --help' where supported.

This is especially useful for builtins like echo, true, and false that
don't support --help (matching bash builtin behaviour).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Bash emits builtin --help output on stdout. Our break, continue, and
exit builtins incorrectly wrote to stderr, breaking patterns like
'break --help | head' and 'break --help >file'.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Re-enable bash comparison assertions for break, continue, and exit
help scenarios. Add trailing spaces on blank lines to match bash's
exact output format. All three scenarios now pass byte-for-byte
against debian:bookworm-slim bash.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@matt-dz
Copy link
Copy Markdown
Collaborator Author

matt-dz commented Mar 19, 2026

@codex conduct a comprehensive security and code review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 16731f760d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread builtins/help/help.go
matt-dz and others added 2 commits March 19, 2026 10:49
…trings

Replace static Help field strings on 23 commands with dynamic invocation:
help <command> now calls the command's handler with --help and captures
the output. Only echo, true, and false retain static Help text since
they don't handle --help (matching bash builtin behaviour).

This eliminates 418 lines of duplicated help text that would drift
out of sync whenever flags are added or changed.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
help echo typo now prints usage and exits 1 instead of silently
ignoring the extra argument.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@matt-dz
Copy link
Copy Markdown
Collaborator Author

matt-dz commented Mar 19, 2026

@codex conduct a comprehensive security and code review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@matt-dz matt-dz marked this pull request as ready for review March 19, 2026 15:06
@matt-dz matt-dz changed the title feat: add --help to break, continue, exit, echo, true, false feat(help): add --help to builtins and extend help command Mar 19, 2026
@matt-dz matt-dz enabled auto-merge March 19, 2026 15:09
Comment thread builtins/continue/continue.go Outdated
Replace single-line escaped strings with multi-line string constants
for break, continue, and exit --help output. Easier to read and maintain.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@matt-dz matt-dz requested a review from AlexandreYang March 19, 2026 15:20
@matt-dz matt-dz added this pull request to the merge queue Mar 19, 2026
Merged via the queue into main with commit 448c492 Mar 19, 2026
31 checks passed
@matt-dz matt-dz deleted the matt-dz/add-help-flags branch March 19, 2026 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants