Skip to content

Switch from BoolVar to UnNegatableBoolVar everywhere to avoid confusion #1418

@alexbozhenko

Description

@alexbozhenko

Proposed change

BoolVar may confuse: Is the flag on or off by default? If it is on by default, the flag to enable is meaningless.

# nats audit gather -h                                                                                                        
...
      --[no-]progress           Display progress messages during gathering
      --[no-]server-endpoints   Capture monitoring endpoints for each server

There are 36 total cases where BoolVar is used, arcoss 16 commands.

# rg   'Default\("true"\).*BoolVar'     | less -N
# rg -l  'Default\("true"\).*BoolVar'    | sort | uniq | wc -l
16

from @jnmoyne in slack:

so, just to nail this down once and for all and make sure we are on the same page, let’s say taking for a simple example --no-progress in nats bench which right now is:

Flag("progress", "Enable or disable the progress bar").Default("true").BoolVar(&c.progressBar)

and therefore shows in the help as

      --[no-]progress           Enable or disable the progress bar

The right way that we want to change to at some point would be to:

  1. rename the var to noProgressBar
  2. Change to Flag("no-progress", "Enable or disable the progress bar").UnNegatableBoolVar(&c.noProgressBar)
  3. switch the logic around in the code, i.e. from if (c.progressBar) to if(!c.noProgressBar

We already have 8 places where we use UnNegatableBoolVar like this.

# rg 'Flag.*no-.*BoolVar' | less -NS
8

This would be a change similar to
#1417 and #506.
When this is done, all the ambiguity around bool flags will be gone: we will have either --thing or --no-thing flags.

Use case

Added consistency and clarity.

Contribution

I can.

Sub-issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    proposalEnhancement idea or proposal

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions