Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7513715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T00:16:15+00:00 2026-05-30T00:16:15+00:00

This question started out here . But changed significantly as I learned more about

  • 0

This question started out here. But changed significantly as I learned more about Thor.

I’m trying to make a Thor::Group subcommand that takes an argument. Oddly, it works if there are no arguments.

Can I use a Thor::Group as a sub-command?

This works when I type: foo counter

foo/bin/foo

module Foo
  class CLI < Thor
    register(Counter, 'counter', 'counter', 'Count up from the 1.')
  end

  class Counter < Thor::Group
    desc "Prints 1 2"

    def one
      puts 1
    end

    def two
      puts 2
    end

  end

end

Foo::CLI.start

But this doesn’t work when I type: foo counter 5

module Foo
  class CLI < Thor
    register(Counter, 'counter', 'counter <number>', 'Count up from the input.')
  end

  class Counter < Thor::Group
    argument :number, :type => :numeric, :desc => "The number to start counting"
    desc "Prints 2 numbers based on input"

    def one
      puts number + 0
    end

    def two
      puts number + 1
    end

  end


end

Foo::CLI.start

It replies: counter was called incorrectly. Call as foo counter number

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T00:16:17+00:00Added an answer on May 30, 2026 at 12:16 am

    I have a solution. Instead of using Thor::Group I’m using Invocations

    bin/foo looks like this:

    #!/usr/bin/env ruby
    
    require 'foo'
    
    Foo::CLI.start
    

    lib/cli.rb – registers ‘generate’ as a subtask of of the base command, foo:

    module Foo
      class CLI < Thor
        register(Generate, 'generate', 'generate [something]', 'Type foo generate for more help.')
      end
    end
    

    lib/generate.rb looks like this:

    module Foo
    
      class Generate < Thor
    
        desc "project [name]", "Prints the project making step"
        def project(name)
          puts "making first project file #{name}"
          invoke :config
          invoke :project_sub
        end
    
        desc "config [name]", "Prints the config making step"
        def config(name)
          puts "making first config file #{name}"
          invoke :project_sub
        end
    
        desc "project_sub [name]", "Prints the project_sub making step"
        def project_sub(name)
          puts "making subsystem file #{name}"
        end
    
        def self.banner(task, namespace = false, subcommand = true)
           task.formatted_usage(self, true, subcommand).split(':').join(' ')
        end
    
      end
    
    end
    

    Now I can type: foo generate project fred

    and it will output:

    > making first project file fred
    > making first config file fred
    > making subsystem file fred
    

    Notice the banner override. It means that typing: foo generate project with invalid or missing args will give the correct help message:

    "project" was called incorrectly. Call as "foo generate project [name]".
    

    as opposed to

    "project" was called incorrectly. Call as "foo project [name]".
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I started the question differently, about a collection_select, but I found out that is
I originally started this question in another thread, but that thread was sorta, kinda
I've started to become a Good Citizen, as per this question here: Domain compatibility:
This post started as a question on ServerFault ( https://serverfault.com/questions/131156/user-receiving-partial-downloads ) but I determined
This started as a question, but turned into a solution as I did some
This is not a programming question per se, but here it goes. I am
Since I started writing this question, I think I figured out the answers to
I started out with this question , which I sort of answered there ,
Ok, I ran into this tree question which LOOKED simple, but started driving me
I've started this question Named route with nested resources , and it lead me

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.