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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:07:12+00:00 2026-06-09T00:07:12+00:00

This is my Ruby code: require ‘thor’ require ‘thor/group’ module CLI class Greet <

  • 0

This is my Ruby code:

require 'thor'
require 'thor/group'

module CLI

    class Greet < Thor
        desc 'hi', 'Say hi!'
        method_option :name, :type => :string, :description => 'Name to greet', :default => 'there'
        def hi
            puts "Hi, #{options[:name]}!"
        end

        desc 'bye', 'say bye!'
        def bye
            puts "Bye!"
        end
    end


    class Root < Thor
        register CLI::Greet, 'greet', 'greet [COMMAND]', 'Greet with a command'
    end
end


CLI::Root.start

This is the output:

C:\temp>ruby greet.rb help greet
Usage:
  greet.rb greet [COMMAND]

Greet with a command

How do I get that to look something like this?

C:\temp>ruby greet.rb help greet
Usage:
  greet.rb greet [COMMAND]
    --name Name to greet

Greet with a command
  • 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-09T00:07:13+00:00Added an answer on June 9, 2026 at 12:07 am

    You’ve got two things going on here. First, you’ve assigned –name to a method, not to the entire CLI::Greet class. So if you use the command:

    ruby greet.rb greet help hi
    

    you get

    Usage:
      greet.rb hi
    
    Options:
      [--name=NAME]  
                     # Default: there
    
    Say hi!
    

    Which, yes, is wrong– it doesn’t have the subcommand in the help. There’s a bug filed for this in Thor. It, however, is showing the method option properly.

    What it seems like you’re looking for, however, is a class method. This is a method defined for the entire CLI::Greet class, not just for the #hi method.

    You’d do this as such:

    require 'thor'
    require 'thor/group'
    
    module CLI
    
        class Greet < Thor
            desc 'hi', 'Say hi!'
            class_option :number, :type => :string, :description => 'Number to call', :default => '555-1212'
            method_option :name, :type => :string, :description => 'Name to greet', :default => 'there'
            def hi
                puts "Hi, #{options[:name]}! Call me at #{options[:number]}"
            end
    
            desc 'bye', 'say bye!'
            def bye
                puts "Bye! Call me at #{options[:number]}"
            end
        end
    
        class Root < Thor
            register CLI::Greet, 'greet', 'greet [COMMAND]', 'Greet with a command'        
            tasks["greet"].options = CLI::Greet.class_options
        end
    end
    
    CLI::Root.start
    

    With this, ruby greet.rb help greet returns

    Usage:
      greet.rb greet [COMMAND]
    
    Options:
      [--number=NUMBER]  
                         # Default: 555-1212
    
    Greet with a command
    

    Note there is still a hack needed here: the tasks["greet"].options = CLI::Greet.class_options line in CLI::Root. There’s a bug filed for this in Thor, too.

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

Sidebar

Related Questions

require 'coderay' puts CodeRay.scan('puts Hello, world!', :ruby).page This code will print full HTML page
I'm trying to upload image to Amazon S3 with this Ruby code: require 'net/http/post/multipart'
This ruby code works great: require 'soap/wsdlDriver' wsdl_url = 'http://www.weather.gov/forecasts/xml/DWMLgen/wsdl/ndfdXML.wsdl' proxy = SOAP::WSDLDriverFactory.new(wsdl_url).create_rpc_driver print
I am beginner in Ruby and having trouble understanding this code require_relative 'custom_page' module
i have this code: require 'java' require 'iText-5.0.6.jar' module Pdf include_package com.itextpdf.text.pdf include_package java.io
I am using the Mongo Ruby driver and have this block of Ruby code
I have some ruby code like this: my_hash = { key1: value, key2: value
I have a DSL - like piece of Ruby code that looks like this:
this week I'm having problems logging in LinkedIn using ruby mechanize. My code is
Im new to ruby, wrote this code and works but i know is not

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.