jwaldrip / admiral.cr

A robust DSL for writing command line interfaces written in Crystal.
https://jwaldrip.github.com/admiral.cr
MIT License
135 stars 14 forks source link

Nested subcommands? #10

Closed voobscout closed 4 years ago

voobscout commented 6 years ago

Couldn't get this to work, what am I missing?

# hello.cr
require "admiral"

class Hello < Admiral::Command
  class Planetary < Admiral::Command
    def run
      puts "Hello World"
    end
  end

  class Municipality < Admiral::Command
    define_help description: "City"

    class Zip < Admiral::Command
      def run
        puts "Hello City, Zip!"
      end
    end

    def run
      puts help
    end

    register_sub_command zip : Zip, description: "Nested subcommand"
  end

  register_sub_command planet : Planetary, description: ""
  register_sub_command city : Municipality, description: ""

  define_help description: "Testing subcommands"

  def run
    puts help
  end
end

Hello.run

In words, the expectation was to see:

./hello city zip
# Hello City, Zip!

But it never hits the Zip class.

bararchy commented 6 years ago

@voobscout Same issue for me

jwaldrip commented 6 years ago

I’ll look at it today. Thanks for reporting, are you on the latest version? On Mon, Apr 16, 2018 at 8:29 AM Bar Hofesh notifications@github.com wrote:

@voobscout https://github.com/voobscout Same issue for me

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/jwaldrip/admiral.cr/issues/10#issuecomment-381617982, or mute the thread https://github.com/notifications/unsubscribe-auth/AAConDIKdIePyUOtq2L5lN95SmM7kbpBks5tpKqwgaJpZM4TKvfy .

bararchy commented 6 years ago

I'm using branch: HEAD in my shard.yaml

voobscout commented 6 years ago

Using master, head as well

voobscout commented 6 years ago

imho this can be closed...

I would appreciate the ability to do this as well:

# hello.cr
require "admiral"

class Planetary < Admiral::Command
  def run
    puts "Hello World"
  end
end

class Municipality < Admiral::Command
  define_help description: "City"

  class Zip < Admiral::Command
    def run
      puts "Hello City, Zip!"
    end
  end

  def run
    puts help
  end

  register_sub_command zip : Zip, description: "Nested subcommand"
end

class Hello < Admiral::Command

  register_sub_command planet : Planetary, description: ""
  register_sub_command city : Municipality, description: ""

  define_help description: "Testing subcommands"

  def run
    puts help
  end
end

Hello.run

Not sure even if it is possible to achieve, since i'm a crystal noob, but the ability to just inherit from Admiral::Command and stick that class as a subcommand of any other Admiral::Command sound quite awesome!

atm protected method 'parse_and_run' called for <classname> appears when trying to run the above..