Skip to content

Fix CLI argument handling and exit codes - #76

Merged
mapitman merged 1 commit into
mainfrom
bugfix/cli-arguments
Oct 14, 2026
Merged

mapitman merged 1 commit into
mainfrom
bugfix/cli-arguments

Conversation

@mapitman

Copy link
Copy Markdown
Owner
  • Flags work before or after the filename (mdview file.md -o out.html). -- ends flag parsing.
  • More than one filename is an error (exit 1) instead of being ignored.
  • -h and -help print usage to stdout and exit 0. A missing filename still exits 1 with usage on stderr.
  • mdview - fails with a message when stdin is a terminal, instead of blocking.
  • Updates CLAUDE.md.

Adds table-driven tests for parseFlags. I also checked the exit codes and the stdin cases against the built binary.

Closes #67

Flags after the filename were silently ignored because flag.Parse stops at the first positional argument. Parse repeatedly so flags work on either side of the filename, and honor -- as the end of flags. Reject more than one filename instead of ignoring the extras.

Explicit -h and -help now print usage to stdout and exit 0. A missing filename still prints usage to stderr and exits 1. Reading from - now fails with a message when standard input is a terminal, instead of blocking.

Closes #67
@mapitman
mapitman merged commit 1a8c2b5 into main Oct 14, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix CLI argument handling and exit codes

1 participant