-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dealing with HelpNeeded #73
Comments
@ioquatix maybe something like this hack of the sub-command example? #!/bin/env ruby
require 'trollop'
SUB_COMMANDS = %w(delete copy)
global_opts = Trollop::options do
banner "magic file deleting and copying utility"
opt :dry_run, "Don't actually do anything", :short => "-n"
stop_on SUB_COMMANDS
end
cmd = ARGV.shift # get the subcommand
cmd_opts = case cmd
when "delete" # parse delete options
Trollop::options do
banner "Different banner for delete command"
opt :force, "Force deletion"
opt :help, "Customized other help message for delete"
end
when "copy" # parse copy options
Trollop::options do
banner "Yet another banner for copy command"
opt :double, "Copy twice for safety's sake"
end
else
Trollop::die "unknown subcommand #{cmd.inspect}, should be one of #{SUB_COMMANDS}"
end
puts "Global options: #{global_opts.inspect}"
puts "Subcommand: #{cmd.inspect}"
puts "Subcommand options: #{cmd_opts.inspect}"
puts "Remaining arguments: #{ARGV.inspect}" |
@nanobowers Thanks so much for a useful example. In the end, my needs were too great for trollop, a library which I really loved. I still think it's an awesome library, but I ended up reinventing the wheel, and the results have been great so far. https://github.com/ioquatix/samovar It's still a work in progress. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi.
I want to implement help for sub-commands, e.g.
The best way I can see to do this is to somehow override the exception handling but I was wondering if there was a better way?
The text was updated successfully, but these errors were encountered: