btrfs-progs icon indicating copy to clipboard operation
btrfs-progs copied to clipboard

bug: `unrecognized option '--help'`

Open major0 opened this issue 1 year ago • 2 comments

Various sub-commands to btrfs claim --help is an unrecognized option if there are any other options on the CLI.

Examples of --help being unrecognized.

btrfs filesystem defragment -v --help
btrfs filesystem defragment: unrecognized option '--help'
Try 'btrfs filesystem defragment --help' for more information
btrfs balance start -v --help
btrfs balabtrfs balance start -v --help
btrfs balance start: unrecognized option '--help'
Try 'btrfs balance start --help' for more information

Alternatively, some sub-commands support --help even if there are extra options on the CLI:

btrfs filesystem df -v --help
usage: btrfs filesystem df [options] <path>

    Show space usage information for a mount point

    -b|--raw                  raw numbers in bytes 
    -h|--human-readable       human friendly numbers, base 1024 (default) 
    -H                        human friendly numbers, base 1000 
    --iec                     use 1024 as a base (KiB, MiB, GiB, TiB) 
    --si                      use 1000 as a base (kB, MB, GB, TB) 
    -k|--kbytes               show sizes in KiB, or kB with --si 
    -m|--mbytes               show sizes in MiB, or MB with --si 
    -g|--gbytes               show sizes in GiB, or GB with --si 
    -t|--tbytes               show sizes in TiB, or TB with --si 
    
    Global options:
    --format TYPE             where TYPE is: text

major0 avatar Sep 11 '24 21:09 major0

It seems to also depend on the order, because btrfs fi defrat --help -v works

kdave avatar Sep 17 '24 12:09 kdave

handle_help_options_next_level() checks only the first argument if it's --help.

kdave avatar Sep 17 '24 12:09 kdave

The best fix seems to be to properly detect the unrecognized options, in this case it's -v for filesystem df, no matter if --help is there or not. Getting output of --help will now also work if there's a known option.

$ btrfs fi df -v --help /
btrfs filesystem df: invalid option 'v'
Try 'btrfs filesystem df --help' for more information

$ btrfs fi df -H --help /
usage: btrfs filesystem df [options] <path>

    Show space usage information for a mount point

    -b|--raw                  raw numbers in byte
...

kdave avatar Jan 28 '25 14:01 kdave