Subcommands Don't Work with declared arguments #241

ahawkins opened this Issue Jul 24, 2012 · 2 comments


None yet

2 participants

class Child < Thor
  argument :text, :type => string
  def foo
    puts text

  default_task :foo

class Parent < Thor
  subcommand :child, Child
$ ./parent child Hello # does not work as expected

I've added a failing test here: I think the test can be moved into the invoke related tested. Seems the bug is more related to subcommands with declared arguments.

@wycats @indirect can you point in me in a general direction to fix this? If your class declares argument :foo values for those arguments have to be passed into the constructor to be assigned right? The problem here is that those arguments are not passed when the subclass is instantiated (invoked). I'm not familiar enough with the code yet to be sure. That is my initial assessment.

I'd every much like to fix this bug because I need it for a gem I'm writing. I'm not sure if this is a bug or a feature (current code cannot support it).

Update: subcommands with arguments don't work at all.


I'm baffled by this. There are tests that cover subcommands with default arguments. They are in register_spec.

I can't figure out why I have to do this:

require 'iridium/commands/application'
require 'thor/group'

module Iridium
  class CLI < Thor
    class << self
      def subcommand_with_default(subcommand, subcommand_class)
        self.subcommands << subcommand.to_s
        subcommand_class.subcommand_help subcommand

        define_method(subcommand) do |*args|
          args, opts = Thor::Arguments.split(args)
          invoke subcommand_class, [subcommand_class.default_task, args].flatten, opts

    desc "foo", "bar"
    subcommand_with_default "app", Commands::Application
@wycats wycats closed this in 976de90 Oct 18, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment