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

Stop switch doesn't seem to work? #262

Closed camertron closed 3 years ago

camertron commented 7 years ago

I'm trying to write a subcommand with a stop switch (i.e. --) but GLI always spits out an error saying I've provided too many arguments:

command :deploy do |d|
  d.command :exec do |subcmd|
    subcmd.desc '0-based instance index'
    subcmd.default_value 0
    subcmd.arg_name 'INSTANCE'
    subcmd.flag [:n, :instance], type: Fixnum

    subcmd.action do |global_options, options, args|
      # assumed one of these arguments would include the rest of the command
    end
  end
end
$> bin/executable deploy exec -n 0 -- ls
error: Too many arguments for command

What am I doing wrong?

davetron5000 commented 7 years ago

Weird. This works for me. Can you post a fuller example that I can try locally to debug?

camertron commented 7 years ago

Yep :) Here's a repo I put together that demonstrates the issue.

davetron5000 commented 7 years ago

OK, figured it out. You have arguments :strict (which I think the generator uses by default), which means that if you don't specify an arg for a command, it will error out.

diff --git a/bin/executable b/bin/executable
index d9bb7c3..e7b3798 100755
--- a/bin/executable
+++ b/bin/executable
@@ -19,6 +19,7 @@ end

 desc 'Testing testing foo bar'
 command :deploy do |d|
+  d.arg "blah", :optional
   d.command :exec do |subcmd|
     subcmd.desc '0-based instance index'
     subcmd.default_value 0
@@ -29,6 +30,7 @@ command :deploy do |d|
     subcmd.arg_name 'TARGET'
     subcmd.flag [:t, :target], type: Symbol
     subcmd.action do |global_options, options, args|
       puts 'fooooo'
     end

It's weird, but to set the arg for subcmd, you set it on d, but if you do this, it does work.

camertron commented 7 years ago

Huh ok thanks! Might be worth a mention in the README :)