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

Unknown option when alias begins with other alias #82

Closed
arichiardi opened this issue Feb 21, 2024 · 10 comments
Closed

Unknown option when alias begins with other alias #82

arichiardi opened this issue Feb 21, 2024 · 10 comments

Comments

@arichiardi
Copy link
Contributor

Hi there!

I have the following :spec:

:verbose {:desc "Enable verbose output." :alias :v}
   :very-verbose {:desc "Enable very verbose output." :alias :vv}

That when I cli/parse-args returns the unknown option error (via the :error-fn):

{:spec {:verbose {:desc "Enable verbose output.", :alias :v}
        :very-verbosd {:desc "Enable very verbose output.", :alias :vv}}
 :type :org.babashka/cli, :cause :restrict, :msg "Unknown option:" :e
 :restrict #{:check :verbose :fix :very-verbosd}, :option :e}

I could reproduce it only when :vv is used as :alias.

Using bb --version babashka v1.3.186.

@borkdude
Copy link
Contributor

Can you please post a full repro, not just some fragments? I'm not sure how to reproduce your problem. What arguments are you parsing for example.

@borkdude
Copy link
Contributor

borkdude commented Feb 22, 2024

I assume that this is your full repro:

(require '[babashka.cli :as cli] :reload)

(prn
 (cli/parse-opts
  ["-vv"]
  {:spec {:verbose {:desc "Enable verbose output.", :alias :v}
          :very-verbosd {:desc "Enable very verbose output.", :alias :vv}}
   :closed true}))

@borkdude
Copy link
Contributor

borkdude commented Feb 22, 2024

One way to allow multiple aliases to be used is this:

(prn
 (cli/parse-opts
  ["-vv"]
  {:spec {:verbose {:coerce []
                    :desc "Enable verbose output.", :alias :v}}
   :closed true}))

which results into this:

{:verbose [true true]}

@borkdude
Copy link
Contributor

I do consider the above as a bug which I'll fix though

@arichiardi
Copy link
Contributor Author

Just woke up on this side of the world with awesome news thank you! Next time I'll make a repro sorry about that.

@borkdude
Copy link
Contributor

Also released a new bb version. Perhaps it would be good to document that above usage of -vv?

@arichiardi
Copy link
Contributor Author

I can do that

@borkdude
Copy link
Contributor

Thanks very much!

@arichiardi
Copy link
Contributor Author

@borkdude while checking the docs I noticed this

Flags may be combined into a single short option (since 0.7.51):

(cli/parse-opts ["-abc"])
;;=> {:a true :b true :c true}

And I was wondering if the following is also a (smaller) bug:

 (prn (cli/parse-opts ["-vvv"]))           
 {:v true}

I can change the docs to say that only "single letter" flags behave that way. Thoughts?

@borkdude
Copy link
Contributor

Yes, only single letter flags behave that way, it's UNIX convention I believe. But if you add {:spec {:v {:coerce []}}} the booleans will be collected in a vector instead of overwritten, which is the way you should use it for your purpose.

arichiardi added a commit to arichiardi/cli that referenced this issue Feb 22, 2024
Here is a bit of docs around the use cases described in babashka#82.
borkdude pushed a commit that referenced this issue Feb 22, 2024
Here is a bit of docs around the use cases described in #82.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants