Skip to content

fix #409: add a else case to report unknown command clearly to the usr#412

Open
pepedinho wants to merge 1 commit intozenc-lang:mainfrom
pepedinho:409-fix-unknown-cmd-behaviour
Open

fix #409: add a else case to report unknown command clearly to the usr#412
pepedinho wants to merge 1 commit intozenc-lang:mainfrom
pepedinho:409-fix-unknown-cmd-behaviour

Conversation

@pepedinho
Copy link
Copy Markdown
Contributor

@pepedinho pepedinho commented Apr 24, 2026

Description

I just add a check in the else branch of argument parsing to catch unknown commands,
This changes fixes #409

before:

zenc\lang> zc test simple-test.zc
   Compiling simple-test.zc
    Finished build in 0.19s
zenc\lang>

after:

zenc/lang> ./zc test simple-test.zc                                  
error: unknown command 'test'
usage: zc [-v | -h | -q | -V] [-I | -L | -l | -D <path/macro>] [--cc <c>] [-O<l>] [-g]
          [--release] [--json] [--paths] [--zen] <command> [<args>]

common commands:
  build, run          Compile program (default / run immediately)
  check, transpile    Type check only / generate C code
  repl, lsp           Start REPL / Language Server

common options:
  -o <f>, --cc <c>    Set output name / backend compiler
  -I, -L, -l <p>      Include/Library paths and linking
  -D <n>, -O<l>       Define macro / Set optimization level
  -g, -g0, --release  Debug info (on/off) or Release mode
  -v, --verbose       Show granular compiler phases
  -q, --quiet         Suppress all non-error output
  --json              Emit structured JSON diagnostics

language & advanced:
  --check, --free     Borrow checker / No standard library
  --misra             Generate strictly MISRA C compliant code
  -Wpedantic          Enable pedantic warnings
  --cpp, --cuda       C++ or CUDA compatibility modes
  -c, -S, -E, -shared
                      Compile/Asm/Preprocess only / DLL

'zc -h' for help, 'zc --version' for version. See 'zc help <command>' for info.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the zc CLI command parsing to explicitly reject unknown subcommands (e.g., zc test ...) instead of silently falling back to the default compile flow, addressing issue #409.

Changes:

  • Add an explicit else branch in main command parsing to detect unknown commands.
  • Print a clear error message, show usage, and exit with a non-zero status for unknown commands.

Comment thread src/main.c
Comment thread src/main.c
Comment on lines +188 to +194
else
{
fprintf(stderr, COLOR_BOLD COLOR_RED "error" COLOR_RESET ": unknown command '%s'\n",
command);
print_usage();
return 1;
}
Copy link

Copilot AI Apr 24, 2026

Choose a reason for hiding this comment

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

This change fixes a CLI parsing bug, but there doesn’t appear to be an automated regression test that asserts zc <unknown> exits non-zero and reports the unknown command. Adding a small integration test (e.g., in tests/scripts/ or similar harness) would help prevent this from regressing again.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure where I should write this test; should I create a new script for it?

@pepedinho pepedinho changed the title fix: add a else case to report unknown command clearly to the usr fix #409: add a else case to report unknown command clearly to the usr Apr 27, 2026
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.

[BUG] zc doesn't report error when executing the unknown command zc test

2 participants