Module: Jets::Command
- Extended by:
- ActiveSupport::Autoload
- Includes:
- Behavior
- Defined in:
- lib/jets/command.rb,
lib/jets/command/base.rb,
lib/jets/command/help.rb,
lib/jets/command/actions.rb,
lib/jets/command/behavior.rb,
lib/jets/command/api_helpers.rb,
lib/jets/command/aws_helpers.rb,
lib/jets/command/rake_decorate.rb,
lib/jets/command/helpers/editor.rb,
lib/jets/commands/dev/dev_command.rb,
lib/jets/commands/new/new_command.rb,
lib/jets/commands/url/url_command.rb,
lib/jets/commands/call/call_command.rb,
lib/jets/commands/gems/gems_command.rb,
lib/jets/commands/help/help_command.rb,
lib/jets/commands/logs/logs_command.rb,
lib/jets/commands/rake/rake_command.rb,
lib/jets/command/environment_argument.rb,
lib/jets/commands/build/build_command.rb,
lib/jets/commands/clean/clean_command.rb,
lib/jets/commands/notes/notes_command.rb,
lib/jets/commands/delete/delete_command.rb,
lib/jets/commands/deploy/deploy_command.rb,
lib/jets/commands/dotenv/dotenv_command.rb,
lib/jets/commands/plugin/plugin_command.rb,
lib/jets/commands/routes/routes_command.rb,
lib/jets/commands/runner/runner_command.rb,
lib/jets/commands/server/server_command.rb,
lib/jets/commands/stacks/stacks_command.rb,
lib/jets/commands/status/status_command.rb,
lib/jets/commands/console/console_command.rb,
lib/jets/commands/version/version_command.rb,
lib/jets/commands/generate/generate_command.rb,
lib/jets/commands/projects/projects_command.rb,
lib/jets/commands/releases/releases_command.rb,
lib/jets/commands/rollback/rollback_command.rb,
lib/jets/commands/configure/configure_command.rb,
lib/jets/commands/dbconsole/dbconsole_command.rb,
lib/jets/commands/encrypted/encrypted_command.rb,
lib/jets/commands/degenerate/degenerate_command.rb,
lib/jets/commands/application/application_command.rb,
lib/jets/commands/credentials/credentials_command.rb,
lib/jets/commands/db/system/change/change_command.rb,
lib/jets/commands/initializers/initializers_command.rb
Defined Under Namespace
Modules: Actions, ApiHelpers, AwsHelpers, Behavior, Db, EnvironmentArgument, Helpers, RakeDecorate Classes: ApplicationCommand, Base, BuildCommand, CallCommand, CleanCommand, ConfigureCommand, Console, ConsoleCommand, CredentialsCommand, DbconsoleCommand, DegenerateCommand, Delete, DeleteCommand, DeployCommand, DevCommand, DotenvCommand, EncryptedCommand, GemsCommand, GenerateCommand, Help, HelpCommand, InitializersCommand, LogsCommand, NewCommand, NotesCommand, PluginCommand, ProjectsCommand, RakeCommand, Release, ReleasesCommand, Rollback, RollbackCommand, RoutesCommand, RunnerCommand, ServerCommand, StacksCommand, StatusCommand, Url, UrlCommand, VersionCommand
Constant Summary collapse
- HELP_MAPPINGS =
%w(-h -? --help)
- PRO_COMMANDS =
%w( projects stacks releases rollback )
Class Method Summary collapse
- .commands ⇒ Object
-
.environment ⇒ Object
:nodoc:.
-
.find_by_namespace(namespace, command_name = nil) ⇒ Object
Jets finds namespaces similar to Thor, it only adds one rule:.
-
.hidden_commands ⇒ Object
:nodoc:.
-
.invoke(full_namespace, args = [], **config) ⇒ Object
Receives a namespace, arguments, and the behavior to invoke the command.
- .jets_new_with_no_path?(args) ⇒ Boolean
-
.print_commands ⇒ Object
:nodoc:.
-
.root ⇒ Object
Returns the root of the Jets engine or app running the command.
Class Method Details
.commands ⇒ Object
122 123 124 125 126 |
# File 'lib/jets/command.rb', line 122 def commands lookup! visible_commands = (subclasses - hidden_commands).flat_map(&:printing_commands) (visible_commands - COMMANDS_IN_USAGE - PRO_COMMANDS).sort end |
.environment ⇒ Object
:nodoc:
27 28 29 |
# File 'lib/jets/command.rb', line 27 def environment # :nodoc: ENV["JETS_ENV"].presence || ENV["RACK_ENV"].presence || "development" end |
.find_by_namespace(namespace, command_name = nil) ⇒ Object
Jets finds namespaces similar to Thor, it only adds one rule:
Command names must end with “_command.rb”. This is required because Jets looks in load paths and loads the command just before it’s going to be used.
find_by_namespace :webrat, :integration
Will search for the following commands:
"webrat", "webrat:integration", "jets:webrat", "jets:webrat:integration"
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/jets/command.rb', line 77 def find_by_namespace(namespace, command_name = nil) # :nodoc: lookups = [ namespace ] lookups << "#{namespace}:#{command_name}" if command_name lookups.concat lookups.map { |lookup| "jets:#{lookup}" } lookup(lookups) namespaces = subclasses.index_by(&:namespace) namespaces[(lookups & namespaces.keys).first] end |
.hidden_commands ⇒ Object
:nodoc:
23 24 25 |
# File 'lib/jets/command.rb', line 23 def hidden_commands # :nodoc: @hidden_commands ||= [] end |
.invoke(full_namespace, args = [], **config) ⇒ Object
Receives a namespace, arguments, and the behavior to invoke the command.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/jets/command.rb', line 32 def invoke(full_namespace, args = [], **config) namespace = full_namespace = full_namespace.to_s Jets::Command.original_cli_command = full_namespace if char = namespace =~ /:(\w+)$/ command_name, namespace = $1, namespace.slice(0, char) else command_name = namespace end command_name, namespace = "help", "help" if command_name.blank? || HELP_MAPPINGS.include?(command_name) command_name, namespace, args = "application", "application", ["--help"] if jets_new_with_no_path?(args) command_name, namespace = "version", "version" if %w( -v --version ).include?(command_name) original_argv = ARGV.dup ARGV.replace(args) command = find_by_namespace(namespace, command_name) if command && command.all_commands[command_name] command.perform(full_namespace, command_name, args, config) else # Decorate the rake [] method in order to rescue the error and print out # a user friendly message. This works to catch rake errors but # unsure why cannot just rescue RuntimeError here. # More details in the RakeDecorate module. require "rake/application" Rake::Application.send(:include, RakeDecorate) args = ["--describe", full_namespace] if HELP_MAPPINGS.include?(args[0]) find_by_namespace("rake").perform(full_namespace, args, config) end ensure ARGV.replace(original_argv) end |
.jets_new_with_no_path?(args) ⇒ Boolean
118 119 120 |
# File 'lib/jets/command.rb', line 118 def jets_new_with_no_path?(args) args == ["new"] end |
.print_commands ⇒ Object
:nodoc:
97 98 99 |
# File 'lib/jets/command.rb', line 97 def print_commands # :nodoc: commands.each { |command| puts(" #{command}") } end |