Class: Cpl::Cli
Class Method Summary collapse
- .all_base_commands ⇒ Object
- .deprecated_commands ⇒ Object
-
.exit_on_failure? ⇒ Boolean
Needed to silence deprecation warning.
-
.fix_help_option ⇒ Object
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.
-
.is_thor_reserved_word?(word, type) ⇒ Boolean
Needed to be able to use “run” as a command.
- .start(*args) ⇒ Object
Class Method Details
.all_base_commands ⇒ Object
91 92 93 |
# File 'lib/cpl.rb', line 91 def self.all_base_commands ::Command::Base.all_commands.merge(deprecated_commands) end |
.deprecated_commands ⇒ Object
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
66 67 68 |
# File 'lib/cpl.rb', line 66 def self.exit_on_failure? true end |
.fix_help_option ⇒ Object
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
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 |