davetron5000 / gli

Make awesome command-line applications the easy way
http://davetron5000.github.io/gli
Apache License 2.0
1.26k stars 102 forks source link

How to create a hyphenized switch ? #224

Closed ghost closed 9 years ago

ghost commented 9 years ago

I want to have a switch called --dry-run. With thor I can add it as :dry_run and thor will convert the underscore to hyphen. How can I achieve the same with GLI ?

davetron5000 commented 9 years ago

I never thought of doing that, but it would be handy.

In the meantime, you can use a string, or ruby's extended symbol syntax:

switch :'dry-run'
# or
switch "dry-run"

GLI should make both the string and symbol version available in the options or global_options hash:

unless options["dry-run"]
  # rm -rf
end
ghost commented 9 years ago

Hey, that works. Thanks a lot. ps: great book you wrote (Building awesome command line applications with ruby 2)

davetron5000 commented 9 years ago

Thanks, and thanks for buying!