Files
ubicloud/cli-commands/help.rb
Jeremy Evans 984345b32a Do not show usage for commands with subcommands in help -ru
When listing recursive usage, it's best to limit the output only
to actual commands you can run.
2025-02-19 10:25:42 -08:00

48 lines
1.2 KiB
Ruby

# frozen_string_literal: true
UbiCli.on("help") do
options("ubi help [options] [command [subcommand]]") do
on("-r", "--recursive", "also show documentation for all subcommands of command")
on("-u", "--usage", "only show usage")
end
args(0..)
run do |argv, opts|
orig_command = command = UbiCli.command
argv.each do |arg|
break unless (command = command.subcommand(arg) || command.post_subcommand(arg))
orig_command = command
end
usage = opts[:usage]
if command
if opts[:recursive]
body = []
command.each_subcommand do |_, cmd|
if usage
next unless cmd.subcommands.empty? && cmd.post_subcommands.empty?
cmd.option_parsers.each do |op|
body << op.banner << "\n"
end
else
body << cmd.options_text << "\n\n"
end
end
response(body)
elsif usage
body = []
command.option_parsers.each do |op|
body << op.banner << "\n"
end
response(body)
else
response(command.options_text)
end
else
orig_command.raise_failure("invalid command: #{argv.join(" ")}")
end
end
end