Class: Cpl::Cli

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

Class Method Summary collapse

Class Method Details

.all_base_commandsObject



91
92
93
# File 'lib/cpl.rb', line 91

def self.all_base_commands
  ::Command::Base.all_commands.merge(deprecated_commands)
end

.deprecated_commandsObject



77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/cpl.rb', line 77

def self.deprecated_commands
  @deprecated_commands ||= begin
    deprecated_commands_file_path = "#{__dir__}/deprecated_commands.json"
    deprecated_commands_data = File.binread(deprecated_commands_file_path)
    deprecated_commands = JSON.parse(deprecated_commands_data)
    deprecated_commands.to_h do |old_command_name, new_command_name|
      file_name = new_command_name.gsub(/[^A-Za-z]/, "_")
      class_name = file_name.split("_").map(&:capitalize).join

      [old_command_name, Object.const_get("::Command::#{class_name}")]
    end
  end
end

.exit_on_failure?Boolean

Needed to silence deprecation warning

Returns:

  • (Boolean)


66
67
68
# File 'lib/cpl.rb', line 66

def self.exit_on_failure?
  true
end

.fix_help_optionObject

This is so that we’re able to run ‘cpl COMMAND –help` to print the help (it basically changes it to `cpl –help COMMAND`, which Thor recognizes) Based on stackoverflow.com/questions/49042591/how-to-add-help-h-flag-to-thor-command



56
57
58
59
60
61
62
63
# File 'lib/cpl.rb', line 56

def self.fix_help_option
  help_mappings = Thor::HELP_MAPPINGS + ["help"]
  matches = help_mappings & ARGV
  matches.each do |match|
    ARGV.delete(match)
    ARGV.unshift(match)
  end
end

.is_thor_reserved_word?(word, type) ⇒ Boolean

Needed to be able to use “run” as a command

Returns:

  • (Boolean)


71
72
73
74
75
# File 'lib/cpl.rb', line 71

def self.is_thor_reserved_word?(word, type) # rubocop:disable Naming/PredicateName
  return false if word == "run"

  super(word, type)
end

.start(*args) ⇒ Object



47
48
49
50
51
# File 'lib/cpl.rb', line 47

def self.start(*args)
  fix_help_option

  super(*args)
end