Class: Jets::Command::Base
- Inherits:
-
Thor
- Object
- Thor
- Jets::Command::Base
- Extended by:
- Memoist
- Includes:
- Actions, ApiHelpers, AwsHelpers
- Defined in:
- lib/jets/command/base.rb
Direct Known Subclasses
ApplicationCommand, BuildCommand, CallCommand, CleanCommand, ConfigureCommand, ConsoleCommand, CredentialsCommand, Db::System::ChangeCommand, DbconsoleCommand, DeleteCommand, DeployCommand, DevCommand, DotenvCommand, EncryptedCommand, GemsCommand, GenerateCommand, HelpCommand, InitializersCommand, LogsCommand, NewCommand, NotesCommand, PluginCommand, ProjectsCommand, RakeCommand, ReleasesCommand, RollbackCommand, RoutesCommand, RunnerCommand, ServerCommand, StacksCommand, StatusCommand, UrlCommand, VersionCommand
Defined Under Namespace
Classes: CorrectableError, Error
Class Method Summary collapse
-
.banner ⇒ Object
Use Jets’ default banner.
-
.base_name ⇒ Object
Sets the base_name taking into account the current class namespace.
-
.command_name ⇒ Object
Return command name without namespaces.
-
.default_command_root ⇒ Object
Default file root to place extra files a command might need, placed one folder above the command file.
-
.desc(usage = nil, description = nil, options = {}) ⇒ Object
Tries to get the description from a USAGE file one folder above the command root.
-
.engine? ⇒ Boolean
Returns true when the app is a Jets engine.
- .executable ⇒ Object
-
.exit_on_failure? ⇒ Boolean
:nodoc:.
-
.hide_command! ⇒ Object
Convenience method to hide this command from the available ones when running jets command.
-
.inherited(base) ⇒ Object
:nodoc:.
- .long_desc(long_description, options = {}) ⇒ Object
-
.namespace(name = nil) ⇒ Object
Convenience method to get the namespace from the class name.
-
.perform(full_namespace, command, args, config) ⇒ Object
:nodoc:.
- .printing_commands ⇒ Object
-
.usage_path ⇒ Object
Path to lookup a USAGE description in a file.
Instance Method Summary collapse
Methods included from ApiHelpers
#check_for_error_message!, #no_token_exit!, #paging_params
Methods included from AwsHelpers
Methods included from AwsServices
#apigateway, #aws_lambda, #aws_options, #cfn, #dynamodb, #logs, #s3, #s3_resource, #sns, #sqs, #sts
Methods included from AwsServices::StackStatus
#lookup, #stack_exists?, #stack_in_progress?
Methods included from AwsServices::GlobalMemoist
Methods included from Actions
#load_generators, #load_tasks, #require_application!, #require_application_and_environment!, #set_application_directory!
Class Method Details
.banner ⇒ Object
Use Jets’ default banner.
113 114 115 116 117 118 119 |
# File 'lib/jets/command/base.rb', line 113 def (*) command_name = full_namespace ? full_namespace.split(':').last : command_name command = commands[command_name] = '[options]' unless command && command..empty? output = "#{executable} #{arguments.map(&:usage).join(' ')} #{options_arg}".squish " #{output}" # add 2 more spaces in front end |
.base_name ⇒ Object
Sets the base_name taking into account the current class namespace.
Jets::Command::TestCommand.base_name # => 'jets'
124 125 126 127 128 |
# File 'lib/jets/command/base.rb', line 124 def base_name @base_name ||= if base = name.to_s.split("::").first base.underscore end end |
.command_name ⇒ Object
Return command name without namespaces.
Jets::Command::TestCommand.command_name # => 'test'
133 134 135 136 137 138 |
# File 'lib/jets/command/base.rb', line 133 def command_name @command_name ||= if command = name.to_s.split("::").last command.chomp!("Command") command.underscore end end |
.default_command_root ⇒ Object
Default file root to place extra files a command might need, placed one folder above the command file.
For a Jets::Command::TestCommand placed in jets/command/test_command.rb would return jets/test.
153 154 155 156 |
# File 'lib/jets/command/base.rb', line 153 def default_command_root path = File.(relative_command_path, __dir__) path if File.exist?(path) end |
.desc(usage = nil, description = nil, options = {}) ⇒ Object
Tries to get the description from a USAGE file one folder above the command root.
62 63 64 65 66 67 68 |
# File 'lib/jets/command/base.rb', line 62 def desc(usage = nil, description = nil, = {}) if usage super else @desc ||= ERB.new(File.read(usage_path), trim_mode: "-").result(binding) if usage_path end end |
.engine? ⇒ Boolean
Returns true when the app is a Jets engine.
56 57 58 |
# File 'lib/jets/command/base.rb', line 56 def engine? defined?(ENGINE_ROOT) end |
.executable ⇒ Object
108 109 110 |
# File 'lib/jets/command/base.rb', line 108 def executable "jets #{full_namespace || command_name}" end |
.exit_on_failure? ⇒ Boolean
:nodoc:
51 52 53 |
# File 'lib/jets/command/base.rb', line 51 def exit_on_failure? # :nodoc: false end |
.hide_command! ⇒ Object
Convenience method to hide this command from the available ones when running jets command.
83 84 85 |
# File 'lib/jets/command/base.rb', line 83 def hide_command! Jets::Command.hidden_commands << self end |
.inherited(base) ⇒ Object
:nodoc:
87 88 89 90 91 92 93 |
# File 'lib/jets/command/base.rb', line 87 def inherited(base) # :nodoc: super if base.name && !base.name.end_with?("Base") Jets::Command.subclasses << base end end |
.long_desc(long_description, options = {}) ⇒ Object
46 47 48 49 |
# File 'lib/jets/command/base.rb', line 46 def long_desc(long_description, = {}) [:wrap] = false super end |
.namespace(name = nil) ⇒ Object
Convenience method to get the namespace from the class name. It’s the same as Thor default except that the Command at the end of the class is removed.
73 74 75 76 77 78 79 |
# File 'lib/jets/command/base.rb', line 73 def namespace(name = nil) if name super else @namespace ||= super.chomp("_command").sub(/:command:/, ":") end end |
.perform(full_namespace, command, args, config) ⇒ Object
:nodoc:
95 96 97 98 99 100 101 102 |
# File 'lib/jets/command/base.rb', line 95 def perform(full_namespace, command, args, config) # :nodoc: if Jets::Command::HELP_MAPPINGS.include?(args.first) command, args = "help", [] self.full_namespace = full_namespace # store for help. clean:log => log end dispatch(command, args.dup, nil, config) end |
.printing_commands ⇒ Object
104 105 106 |
# File 'lib/jets/command/base.rb', line 104 def printing_commands namespaced_commands end |
.usage_path ⇒ Object
Path to lookup a USAGE description in a file.
141 142 143 144 145 146 |
# File 'lib/jets/command/base.rb', line 141 def usage_path if default_command_root path = File.join(default_command_root, "USAGE") path if File.exist?(path) end end |
Instance Method Details
#help ⇒ Object
192 193 194 195 196 197 198 199 200 201 |
# File 'lib/jets/command/base.rb', line 192 def help if full_namespace = self.class.full_namespace command_name = full_namespace.split(':').last # clean:log => log self.class.command_help(shell, command_name) elsif command_name = self.class.command_name self.class.command_help(shell, command_name) else super end end |