Default will never be printed for `flag_bool` with `def`=`false`

Open Beginner friendly
#14 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
1/5
Estimated time
Under an hour
Newbie friendliness
68/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
c
Domain
cli

Research direction

Start in flag.h at lines 877-879 and inspect how boolean defaults are included in the help output. Reproduce the output for a flag_bool whose default is false, then verify that the displayed default matches the configured value, including false.

Written by the indexing model from the issue text.

Description

I was copying over the library and renaming some things and came acorss the following lines in flag.h:

if (flag->def.as_bool) {
    fprintf(stream, "        Default: %s\n", flag->def.as_bool ? "true" : "false");
}

As you can see, the ternary operator there will always result in "true", since we just checked that it's non-zero in the if above it...

Maybe instead we can just always print the default for booleans?

Dominant language
C
Stars
295
Forks
20
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from tsoding/flag.h

All issues in tsoding/flag.h

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.