With Thor one can use method_option to set the options for a particular task. To set the options for all tasks in a class one can use class_option
. But what about t
I would just use a superclass like this:
require 'thor'
class CliBase < Thor
def self.shared_options
method_option :verbose,
:aliases => '-v',
:type => :boolean,
:desc => 'Verbose',
:default => false,
:required => false
end
end
... then subclass as follows:
require 'cli_base'
class Cli < CliBase
desc 'task1', 'Task 1'
shared_options
def task1
end
desc 'task2', 'Task 2'
shared_options
method_option :value, :type => :numeric
def task2
end
desc 'task3', 'Task 3'
method_option :colors, :type => :boolean, :aliases => '-c'
def task3
end
end
Cli.start(ARGV)