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 7979131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:41:33+00:00 2026-06-04T09:41:33+00:00

In my gem I’d like to have a an executable command with args like

  • 0

In my gem I’d like to have a an executable command with args like so:

foo generate project
foo generate config
foo say_hi

So I made

foo/bin/foo

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

And the Foo file in foo/lib/thor/foo.rb

module Foo 
  class Foo < Thor

    desc "generate [WHAT]"
    def generate(*args)

    end

    desc "say_hi"
    def say_hi(*args)
       ....
    end

  end
end

And foo/lib/thor/generators/project.rb
And foo/lib/thor/generators/config.rb

Where I’d like to specify classes inherited from Thor::Group like katz examples …

module Foo
  module Generators
    class Project < Thor::Group
      include Thor::Actions
      ....
    end
  end
end

So my question is: How do I set things up so that I can call those generators from the executable like:

foo generate config

Am I on the right track even? Ideally, typing foo on its own should give help for say_hi and for all the generators.

  • 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-06-04T09:41:34+00:00Added an answer on June 4, 2026 at 9:41 am

    I had trouble getting this to work at first, too. Here’s the pattern that I’ve started using:

    $ cat cli.rb

    #!/usr/bin/env ruby
    require 'rubygems'
    require 'thor'
    require 'thor/group'
    
    module CLI
      class Greeter < Thor::Group
        def say_hi
          say "Hi"
        end
        def say_goodbye
          say "Goodbye"
        end
      end
    end
    
    module CLI
      class Crud < Thor
        desc 'create', 'Creates a sub-thing'
        def create
          say "Creating a sub-thing"
        end
    
        desc 'delete', 'Deletes a sub-thing'
        def delete
          say "Deleting a sub-thing"
        end
    
      end
    end
    
    module CLI
      class Root < Thor
        register CLI::Greeter, 'greet', 'greet', 'Executes a multi-step subtask'
        register CLI::Crud, 'crud', 'crud [COMMAND]', 'Delegates to a sub-command'
      end
    end
    
    CLI::Root.start
    

    $ ./cli.rb

    Tasks:
      cli.rb crud [COMMAND]  # Delegates to a sub-command
      cli.rb greet           # Executes a multi-step subtask
      cli.rb help [TASK]     # Describe available tasks or one specific task
    

    $ ./cli.rb greet

    Hi
    Goodbye
    

    $ ./cli.rb crud

    Tasks:
      cli.rb crud create          # Creates a sub-thing
      cli.rb crud delete          # Deletes a sub-thing
      cli.rb crud help [COMMAND]  # Describe subcommands or one specific subcommand
    

    $ ./cli.rb crud create

    Creating a sub-thing
    

    $ ./cli.rb crud delete

    Deleting a sub-thing
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

WhenI run (as root) gem install pg -v '0.12.0' -- --with-pg-config=/usr/pgsql-9.1/bin/pg_config I get the
sudo gem install mysql — –with-mysql-config=/usr/local/mysql/bin/mysql_config /usr/local/lib/ruby/1.9.1/optparse.rb:1262: warning: regexp match /.../n against to UTF-8
Gemfile gem wicked_pdf gem wkhtmltopdf-binary the error: RuntimeError in CarsController#show Failed to execute: /usr/bin/wkhtmltopdf
I have ran gem install mysql2, added the lib file to the bin folder
I have a rails gem that uses a snippet like: components = [] components
In my GEM file i have: gem 'shoulda' But I would like to use
I have installed gem jquery-rails in Rails 3.1 app. But line below rails generate
gem install heroku failed with following message and I have tried the solution here
Problem: gem generate fails because it's missing XML Builder. $ gem generate ERROR: While
sudo gem install perftools.rb -p http://10.10.10.10:3128 ... /usr/local/lib/ruby/1.9.1/net/http.rb:762:in initialize: Connection refused - connect(2) (Errno::ECONNREFUSED)

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.