Skip to content

flags: interaction between default_missing and allow_negative_numbers #1316

Closed

Description

@muzimuzhi

It seems

  • allow_negative_numbers is enabled by default for flags (see --apps flag)
  • but if default_missing is specified, then allow_negative_numbers becomes disabled (see --jobs flag), unless allow_negative_numbers is enabled manually (see --kids flag).
#!/usr/bin/env -S usage bash

#USAGE name "flag-test"
#USAGE flag "--apps <N>"
#USAGE flag "--jobs <N>" default_missing="default missing"
#USAGE flag "--kids <N>" default_missing="default missing" allow_negative_numbers=#true

set -euo pipefail

echo "usage_apps=${usage_apps:-unset}"
echo "usage_jobs=${usage_jobs:-unset}"
echo "usage_kids=${usage_kids:-unset}"
$ ./flag-test.sh --apps -1
usage_apps=-1
usage_jobs=unset
usage_kids=unset

$ ./flag-test.sh --jobs -1
Error: unexpected word: -1

$ ./flag-test.sh --kids -1
usage_apps=unset
usage_jobs=unset
usage_kids=-1

Activity

  1. muzimuzhi commented on Aug 25, 2026

    @muzimuzhi
    ContributorAuthor

    The usage explain output

    $ usage explain -f flag-test.sh -- ./flag-test.sh --apps -1
    ./flag-test.sh --apps -1
    command
    
    tokens
      [0]  ./flag-test.sh  program
      [1]  --apps          flag --apps
      [2]  -1              value of apps = "-1"
    
    values
      flag  --apps  -1  argv [2]
    
    $ usage explain -f flag-test.sh -- ./flag-test.sh --jobs -1
    ./flag-test.sh --jobs -1
    
    the parse stopped before the environment and defaults were applied,
    so only what argv bound is shown
    
    tokens
      [0]  ./flag-test.sh  program
      [1]  --jobs          flag --jobs
      [2]  -1              refused, no declaration takes this word
    
    refused
      unexpected word: -1
    
    $ usage explain -f flag-test.sh -- ./flag-test.sh --kids -1
    ./flag-test.sh --kids -1
    command
    
    tokens
      [0]  ./flag-test.sh  program
      [1]  --kids          flag --kids
      [2]  -1              value of kids = "-1"
    
    values
      flag  --kids  -1  argv [2]
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions