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

  • Home
  • SEARCH
  • 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 6382113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:28:50+00:00 2026-05-25T02:28:50+00:00

When calling thor commands on the command line, the methods are namespaced by their

  • 0

When calling thor commands on the command line, the methods are namespaced by their module/class structure, e.g.

class App < Thor
  desc 'hello', 'prints hello'
  def hello
    puts 'hello'
  end
end

would be run with the command

thor app:hello

However, if you make that self executable by putting

App.start

at the bottom you can run the command like:

app hello

Is there any way to namespace those commands? So that you could call, for example

app say:hello
app say:goodbye
  • 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-25T02:28:50+00:00Added an answer on May 25, 2026 at 2:28 am

    Another way of doing this is to use register:

    class CLI < Thor
      register(SubTask, 'sub', 'sub <command>', 'Description.')
    end
    
    class SubTask < Thor
      desc "bar", "..."
      def bar()
        # ...
      end
    end
    
    CLI.start
    

    Now – assuming your executable is called foo – you can call:

    $ foo sub bar
    

    In the current thor version (0.15.0.rc2) there is a bug though, which causes the help texts to skip the namespace of sub commands:

    $ foo sub
    Tasks:
       foo help [COMMAND]  # Describe subcommands or one specific subcommand
       foo bar             #
    

    You can fix that by overriding self.banner and explicitly setting the namespace.

    class SubTask < Thor
      namespace :sub
    
      def bar ...
    
      def self.banner(task, namespace = true, subcommand = false)
        "#{basename} #{task.formatted_usage(self, true, subcommand)}"
      end
    end
    

    The second parameter of formatted_usage is the only difference to the original implemtation of banner. You can also do this once and have other sub command thor classes inherit from SubTask. Now you get:

    $ foo sub
    Tasks:
       foo sub help [COMMAND]  # Describe subcommands or one specific subcommand
       foo sub bar             #
    

    Hope that helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When calling methods on a base class from a derived class, should the 'base'
When calling DirectoryInfo.GetDirectories(.) on an instance of a DirectoryInfo class which points to a
Calling the javascript gurus out there. Basically my question is regarding how you structure
Calling a GUI app using [DllImport( advapi32.dll, EntryPoint = CreateProcessAsUser, SetLastError = true, CharSet
Calling setNoRender() or indeed any methods on the viewRenderer helper seem to have no
Calling the function MakeTree(4, gameboard) does not work properly, it only prints out the
When calling page methods or web services with either jquery or MSAjax, the Session
Calling this powershell command and getting an error. Driving me nuts. Prompt> get-childitem -recurse
Calling: Intent i = new Intent(Timer.this,TimerService.class); i.putExtra(ms, ms); startService(i); code: public class TimerService extends
Calling Validate() on an XmlDocument requires passing in a ValidationEventHandler delegate. That event function

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.