Class: Ufo::Command
- Extended by:
- Utils::Logging
- Defined in:
- lib/ufo/command.rb
Direct Known Subclasses
CLI, Ufo::CLI::Central, Ufo::CLI::Docker, Ufo::CLI::New, Ufo::CLI::Tasks, Ufo::CLI::Upgrade
Class Method Summary collapse
- .alter_command_description(command) ⇒ Object
- .check_project!(args) ⇒ Object
-
.command_help(shell, command_name) ⇒ Object
Override command_help to include the description at the top of the long_description.
-
.configure_dsl_evaluator ⇒ Object
Uses Ufo.logger and Ufo.root which loads Ufo.config.
- .dispatch(m, args, options, config) ⇒ Object
-
.exit_on_failure? ⇒ Boolean
github.com/erikhuda/thor/issues/244 Deprecation warning: Thor exit with status 0 on errors.
- .help_flags ⇒ Object
- .subcommand? ⇒ Boolean
-
.website ⇒ Object
meant to be overriden.
Methods included from Utils::Logging
Class Method Details
.alter_command_description(command) ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/ufo/command.rb', line 110 def alter_command_description(command) return unless command # Add description to beginning of long_description long_desc = if command.long_description "#{command.description}\n\n#{command.long_description}" else command.description end # add reference url to end of the long_description unless website.empty? full_command = [command.ancestor_name, command.name].compact.join('-') url = "#{website}/reference/ufo-#{full_command}" long_desc += "\n\nHelp also available at: #{url}" end command.long_description = long_desc end |
.check_project!(args) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/ufo/command.rb', line 89 def check_project!(args) command_name = args.first return if subcommand? return if command_name.nil? return if help_flags.include?(args.last) # IE: -h help return if %w[-h -v --version central init version].include?(command_name) return if File.exist?("#{Ufo.root}/.ufo") logger.error "ERROR: It doesnt look like this is a ufo project. Are you sure you are in a ufo project?".color(:red) ENV['UFO_TEST'] ? raise : exit(1) end |
.command_help(shell, command_name) ⇒ Object
Override command_help to include the description at the top of the long_description.
103 104 105 106 107 108 |
# File 'lib/ufo/command.rb', line 103 def command_help(shell, command_name) meth = normalize_command_name(command_name) command = all_commands[meth] alter_command_description(command) super end |
.configure_dsl_evaluator ⇒ Object
Uses Ufo.logger and Ufo.root which loads Ufo.config. See comment where configure_dsl_evaluator is used about Ufo.role
71 72 73 74 75 76 77 78 |
# File 'lib/ufo/command.rb', line 71 def configure_dsl_evaluator DslEvaluator.configure do |config| config.backtrace.select_pattern = Ufo.root.to_s config.logger = Ufo.logger config.on_exception = :exit config.root = Ufo.root end end |
.dispatch(m, args, options, config) ⇒ Object
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 65 66 67 |
# File 'lib/ufo/command.rb', line 36 def dispatch(m, args, , config) # Old note: Configuring the DslEvalulator requires Ufo.root and Ufo.logger which # loads Ufo.config and Ufo::Config#load_project_config # This requires Ufo.role. # So we set Ufo.role before triggering Ufo.config loading configure_dsl_evaluator check_project!(args) # Allow calling for help via: # ufo command help # ufo command -h # ufo command --help # ufo command -D # # as well thor's normal way: # # ufo help command if args.length > 1 && !(args & help_flags).empty? args -= help_flags args.insert(-2, "help") end # ufo version # ufo --version # ufo -v version_flags = ["--version", "-v"] if args.length == 1 && !(args & version_flags).empty? args = ["version"] end super end |
.exit_on_failure? ⇒ Boolean
github.com/erikhuda/thor/issues/244 Deprecation warning: Thor exit with status 0 on errors. To keep this behavior, you must define ‘exit_on_failure?` in `Lono::CLI` You can silence deprecations warning by setting the environment variable THOR_SILENCE_DEPRECATION.
139 140 141 |
# File 'lib/ufo/command.rb', line 139 def exit_on_failure? true end |
.help_flags ⇒ Object
80 81 82 |
# File 'lib/ufo/command.rb', line 80 def help_flags Thor::HELP_MAPPINGS + ["help"] end |
.subcommand? ⇒ Boolean
85 86 87 |
# File 'lib/ufo/command.rb', line 85 def subcommand? !!caller.detect { |l| l.include?('in subcommand') } end |
.website ⇒ Object
meant to be overriden
132 133 134 |
# File 'lib/ufo/command.rb', line 132 def website "http://ufoships.com" end |