Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merging 1135 fix flag parsing #1356

Merged
merged 3 commits into from Apr 21, 2022
Merged

Merging 1135 fix flag parsing #1356

merged 3 commits into from Apr 21, 2022

Commits on May 14, 2020

  1. Fix regression in handling flag-values starting with hyphen

    Fix for a regression between v1.22.1 and v1.22.2, where
    flag values starting with a hyphen would be parsed as a flag:
    
        runc update test_update --memory-swap -1
        Incorrect Usage: flag provided but not defined: -1
    
    This problem was caused by `reorderArgs()` not properly checking
    if the next arg in the list was a value for the flag (and not
    the next flag);
    
    Before this patch:
    
        args before reordering: --opt,--opt-value,arg1
        args after reordering:  --opt,arg1,--opt-value
        args before reordering: --opt,--opt-value,arg1,arg2
        args after reordering:  --opt,arg1,--opt-value,arg2
        args before reordering: arg1,--opt,--opt-value,arg2
        args after reordering:  --opt,arg2,arg1,--opt-value
    
    After this patch is applied:
    
        args before reordering: --opt,--opt-value,arg1
        args after reordering:  --opt,--opt-value,arg1
        args before reordering: --opt,--opt-value,arg1,arg2
        args after reordering:  --opt,--opt-value,arg1,arg2
        args before reordering: arg1,--opt,--opt-value,arg2
        args after reordering:  --opt,--opt-value,arg1,arg2
    
    Co-authored-by: lynn (they) <lynncyrin@gmail.com>
    Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
    thaJeztah and coilysiren committed May 14, 2020
    Copy the full SHA
    464c242 View commit details
    Browse the repository at this point in the history
  2. Fix handling of -- delimiter

    If a `--` delimiter is encountered, any remaining _non-option-value_
    arguments must be handled as argument.
    
    From the POSIX spec (emphasis mine)
    https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html#tag_12_0):
    
    > The first -- argument that *is not an option-argument* should be accepted
    > as a delimiter indicating the end of options. Any following arguments
    > should be treated as operands, even if they begin with the '-' character.
    
    There was a corner-case scenario, where a `--flag` followed by a `--` did
    not use `--` as value for the flag, but instead considered it as delimiter.
    
    As a result;
    
        foo test arg1 --opt -- arg2
    
    Would be reordered as:
    
       foo test --opt arg1 arg2
    
    Which caused `arg1` to be used as value for `--opt`, instead of `--`,
    which is the actual value.
    
    Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
    thaJeztah committed May 14, 2020
    Copy the full SHA
    3358e6f View commit details
    Browse the repository at this point in the history

Commits on Apr 21, 2022

  1. Merge branch 'fix_flag_parsing' of ssh://github.com/thaJeztah/urfave-…

    …cli into thaJeztah-fix_flag_parsing
    meatballhat committed Apr 21, 2022
    Copy the full SHA
    ee629c5 View commit details
    Browse the repository at this point in the history