Class: SubCommandBase

Inherits:
Thor
  • Object
show all
Defined in:
lib/takeltau/lib/subcmd.rb

Overview

Thor with subcommands that work correctly with help

Class Method Summary collapse

Class Method Details

Set the subcommand banner. rubocop:disable Style/OptionalBooleanParameter rubocop:disable Lint/EmptyBlock



8
9
10
11
12
13
14
15
# File 'lib/takeltau/lib/subcmd.rb', line 8

def self.banner(command, _namespace = nil, _subcommand = false)
  subcommand = subcommand_prefix
  name = $PROGRAM_NAME
  name = ENV['TAKELAGE_TAU_TAU'] unless ENV['TAKELAGE_TAU_TAU'].nil?
  subcommand.gsub!(/ship\s*/) {} unless ENV['TAKELAGE_TAU_SHIP'].nil?
  name = File.basename(name)
  [name, subcommand, command.usage].reject(&:empty?).join(' ')
end

.subcommand_prefixObject

Set the subcommand prefix.



20
21
22
23
24
# File 'lib/takeltau/lib/subcmd.rb', line 20

def self.subcommand_prefix
  name.gsub(/.*::/, '')
      .gsub(/^[A-Z]/) { |match| match[0].downcase }
      .gsub(/[A-Z]/) { |match| " #{match[0].downcase}" }
end