Skip to content

Handle CLI argument parsing failures as exit code 1#18

Merged
Code0x58 merged 1 commit intomasterfrom
codex/fix-exit-code-behavior-in-flag-module
Feb 17, 2026
Merged

Handle CLI argument parsing failures as exit code 1#18
Code0x58 merged 1 commit intomasterfrom
codex/fix-exit-code-behavior-in-flag-module

Conversation

@Code0x58
Copy link
Copy Markdown
Owner

Motivation

  • The default flag package emits its own error and exits with code 2 on parse failures, which prevents the program from controlling exit semantics and conflicts with the desired behavior of using exit code 1 for invalid CLI usage or hard failures.

Description

  • Replace the package-global flag usage with a dedicated flag.NewFlagSet(..., flag.ContinueOnError) so parse errors can be handled by our code.
  • Suppress the flag package automatic output with flags.SetOutput(io.Discard) and explicitly print the parse error and call os.Exit(1) on parse failure.
  • Update all flag accesses from package-global helpers to the local flags instance (Usage, NArg, Args) to keep behavior consistent.
  • Update README.md to document that bad CLI args also return exit code 1.

Testing

  • Ran go test ./... which succeeded (no test files present).
  • Built the binary with go build -o /tmp/gitlab-ci-validate . which succeeded.
  • Executed /tmp/gitlab-ci-validate --not-a-real-flag and confirmed it returns EXIT:1 and prints usage/error as expected.

Codex Task

@Code0x58
Copy link
Copy Markdown
Owner Author

Addresses #2

@Code0x58 Code0x58 merged commit 71a5a0f into master Feb 17, 2026
2 checks passed
@Code0x58 Code0x58 deleted the codex/fix-exit-code-behavior-in-flag-module branch February 17, 2026 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant