There is a way to register command with arguments, options and subcommands.
This helps to implement complex nested logic.
Arguments and options can be defined for parent both commands and child commands.
Note
If you call a command with an argument equal to the name of the subcommand, it will call the subcommand instead of the parent command.
#!/usr/bin/env ruby
extend Dry::CLI::Registry
desc 'Information about account'
argument :format, default: "short", values: %w[long short], desc: "Output format"
puts "Information about account in format."
end
desc 'Information about account users'
puts "Information about account users."
end
end
end
register "account", Account
register "account users", Account::Users
end
end
end
Dry::CLI.new(Foo::CLI::Commands).call
$ foo account -h
Command:
foo account
Usage:
foo account [FORMAT] | foo account SUBCOMMAND
Description:
Information about account
Subcommands:
users # Information about account users
Arguments:
FORMAT # Output format: (long/short)
Options:
--help, -h # Print this help
# Information about account in short format.
# Information about account in long format.
# Information about account users.