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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:01:43+00:00 2026-05-25T15:01:43+00:00

My program has a lot of command line options. But I don’t want to

  • 0

My program has a lot of command line options. But I don’t want to overwhelm the user when he types --help. Instead of printing out all options, I’d like to list only the most important ones, printing the rest of them when one types --help=full.

But OptionParser seems to only support printing of the whole list of defined options. I’d like to write my own code that loops over the defined options and prints them out in my way, but OptionParser doesn’t seem to provide any ways to access the options definitions it contains.

Is there a way to access the options in OptionParser that I may have missed? Or is there some good alternative to OptionParser? Or some other approach to this problem?

  • 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-25T15:01:43+00:00Added an answer on May 25, 2026 at 3:01 pm

    You could redefine the option --help for your need.

    require 'optparse'
    
    #create parsers
    opts = OptionParser.new()
    opts.banner = "Usage: example.rb [options]"
    opts.separator("test optparse with --help[=full]")
    opts.on("-v", "--[no-]verbose", "Run verbosely") { |v|
      puts "->Verbose ist #{v.inspect}"
    }
    opts.on("-r", "--repeat REPEAT", "Repeat REPEAT times") { |v|
      puts "->Repeat ist #{v.inspect}"
    }
    
    #Define your own --help
    opts.on("-h", "--help [HELP]", "Help") { |v|
      case v
        when 'full' #write original help
          puts opts.help
        when nil, '' #write script specific help
          puts opts.banner 
          opts.summarize([], opts.summary_width ) { |helpline| 
            #make your own decision on each helpline
            #~ puts helpline #puts each line
            puts helpline unless helpline =~ /-v/ #ignore -v
          }
        else
          puts opts.banner 
          puts <<helpmessage
    Undefined --help option. Please use 'full' or no option
      #{File.basename(__FILE__)} --help
      #{File.basename(__FILE__)} --help=full
    helpmessage
      end
    }
    
    opts.parse!
    

    In this version, --help shows all options, but not -v. You may make your own selection – or write a complete different help.

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

Sidebar

Related Questions

I'm making a simple program in Objective-C. It has one class with a lot
My program has two threads: Main execution thread that handles user input and queues
If a program has literally just deserialized an object (doesn't really matter how, but
The data model in my program has a number of discrete states, but I
I'm refactoring a program that has a lot of nested calls such as ServiceManagement.getGlobalizationService()
I'm making a program that has a lot of constants. I decided to put
Suppose my C++ program has outputted a lot of stuff to the terminal, say
I want to write a warehouse program which has near 80 clients.My program has
I've been working on a command line executable Java program. It's in the testing
I have a lot of if statements in while loop, program has to print

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.