Skip to content

stop parsing flags when -- is provided in command line #734

Description

@hojerst

Description

Currently the argument parser doesn't honor a -- in the command line which might be necessary to allow "flag like arguments" to be parsed. (i.e. a regular argument which starts with a -; for example a file name -x).

If this breaks existing behaviour I'd like to have this as an option in the settings.yml at least, although i don't see much reason why this shouldn't be enabled by default as most gnu based cli's already work this way.

Activity

  1. DannyBen commented on Sep 25, 2026

    @DannyBen
    Member

    Have you tried catch_all?

    bahsly.yml

    name: download
    help: Sample minimal application without commands
    version: 0.1.0
    
    catch_all: true   # <= this
    
    args:
    - name: source
      required: true
      help: URL to download from
    - name: target
      help: "Target filename (default: same as source)"
    
    flags:
    - long: --force
      short: -f
      help: Overwrite existing files
    
    examples:
    - download example.com
    - download example.com ./output -f
    

    output

    $ ./download src dest -f -- -anything -else can be here
    args:
    - ${args[--force]} = 1
    - ${args[source]} = src
    - ${args[target]} = dest
    
    other_args:
    - ${other_args[*]} = -anything -else can be here
    - ${other_args[0]} = -anything
    - ${other_args[1]} = -else
    - ${other_args[2]} = can
    - ${other_args[3]} = be
    - ${other_args[4]} = here
  2. hojerst commented on Sep 25, 2026

    @hojerst
    Author

    actually i wasn't aware of this flag (or forgot about it). it would help in cases where the author of the script intentionally wants to grab for example a bash command that should be called (like docker run image cmd... does). however my described usecase is slightly different.

    example:

    name: inspect
    help: Sample minimal application without commands
    version: 0.1.0
    
    args:
    - name: filename
      required: true
      help: a file on your disk
    
    examples:
    - inspect file.txt

    sometimes regular arguments look like flags as they begin with a - (for example a actual file which is called -x.yml.). Those files might be created intentionally or by accident sometimes. for something like cat you would just write cat -- -x.yml. So I'm not talking about having additional args in a other_args array, but actually having ${args[filename]}="-x.yml"

    what i mean is: in most clis -- means: stop parsing flags at all and consider everything from here a regular argument and not a flag

  3. DannyBen commented on Sep 25, 2026

    @DannyBen
    Member

    I see. Assuming I can implement it without changing the catch_all behavior - would you be able to test it for your use case using a pre-release / source build?

  4. added this to the 2.0.0 milestone on Sep 25, 2026
  5. hojerst commented on Sep 26, 2026

    @hojerst
    Author

    Sure. I'm glad if I can help. Bashly is a great framework I use quite a lot.

  6. DannyBen commented on Sep 26, 2026

    @DannyBen
    Member

    It is implemented in #735

    Assuming you have Ruby installed, you can build from source (from the feature branch)

    git clone --depth 1 --branch add/end-of-options-delimiter \
       https://github.com/bashly-framework/bashly.git
    cd bashly
    bundle install
    bundle exec run gem install

    This installs the branch version of Bashly locally.

    If you are uncomfortable with this, I will release a pre-release gem.

  7. hojerst commented on Sep 26, 2026

    @hojerst
    Author

    i ran everything in a ruby docker container and generated my project with it. every worked as i would expect it.

  8. DannyBen commented on Sep 26, 2026

    @DannyBen
    Member

    Excellent. Thanks.

    I will merge it, and it will be a part of the 2.0.0 release that comes hopefully soon.
    Once I merge you can use the dannyben/bashly:edge image if you want.

  9. DannyBen commented on Sep 27, 2026

    @DannyBen
    Member

    Version 2.0.0 released. Thanks for this issue.

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

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions