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.
118 119 120 121 122 123 124 |
# File 'lib/jets/command/base.rb', line 118 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(' ')} #{}".squish " #{output}" # add 2 more spaces in front end |
.base_name ⇒ Object
129 130 131 132 133 |
# File 'lib/jets/command/base.rb', line 129 def base_name @base_name ||= if base = name.to_s.split("::").first base.underscore end end |
.command_name ⇒ Object
138 139 140 141 142 143 |
# File 'lib/jets/command/base.rb', line 138 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
.
158 159 160 161 |
# File 'lib/jets/command/base.rb', line 158 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
113 114 115 |
# File 'lib/jets/command/base.rb', line 113 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 103 104 105 106 107 |
# 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) rescue Thor::InvocationError => e puts e..color(:red) # message already has ERROR prefix self.full_namespace = full_namespace # store for help. clean:log => log dispatch("help", [], nil, config) exit 1 end |
.printing_commands ⇒ Object
109 110 111 |
# File 'lib/jets/command/base.rb', line 109 def printing_commands namespaced_commands end |
Instance Method Details
#help ⇒ Object
197 198 199 200 201 202 203 204 205 206 |
# File 'lib/jets/command/base.rb', line 197 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 |