Class: Chronicle::ETL::CLI::SubcommandBase
- Defined in:
- lib/chronicle/etl/cli/subcommand_base.rb
Overview
Base class for CLI subcommands. Overrides Thor methods so we can use command:subcommand syntax
Direct Known Subclasses
Class Method Summary collapse
-
.banner(command, _namespace = nil, _subcommand = false) ⇒ Object
Show docs with command:subcommand pattern.
-
.help(shell, subcommand = false) ⇒ Object
Print usage instructions for a subcommand.
-
.subcommand_prefix ⇒ Object
Use subcommand classname to derive display name for subcommand.
Class Method Details
.banner(command, _namespace = nil, _subcommand = false) ⇒ Object
Show docs with command:subcommand pattern.
For help
command, don't use colon
22 23 24 25 26 27 28 |
# File 'lib/chronicle/etl/cli/subcommand_base.rb', line 22 def self.(command, _namespace = nil, _subcommand = false) if command.name == 'help' "#{subcommand_prefix} #{command.usage}" else "#{subcommand_prefix}:#{command.usage}" end end |
.help(shell, subcommand = false) ⇒ Object
Print usage instructions for a subcommand
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/chronicle/etl/cli/subcommand_base.rb', line 7 def self.help(shell, subcommand = false) list = printable_commands(true, subcommand) ::Thor::Util.thor_classes_in(self).each do |klass| list += klass.printable_commands(false) end list.sort! { |a, b| a[0] <=> b[0] } shell.say 'COMMANDS'.bold shell.print_table(list, indent: 2, truncate: true) shell.say (shell) end |
.subcommand_prefix ⇒ Object
Use subcommand classname to derive display name for subcommand
31 32 33 34 35 |
# File 'lib/chronicle/etl/cli/subcommand_base.rb', line 31 def self.subcommand_prefix name.gsub(/.*::/, '').gsub(/^[A-Z]/) do |match| match[0].downcase end.gsub(/[A-Z]/) { |match| "-#{match[0].downcase}" } end |