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
- .check_version_structure! ⇒ 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
-
.non_project_command? ⇒ Boolean
Also, using ARGV instead of args because args is called by thor in multiple passes For ‘ufo central update`: * 1st pass: “central” * 2nd pass: “update”.
- .subcommand? ⇒ Boolean
-
.website ⇒ Object
meant to be overriden.
Methods included from Utils::Logging
Class Method Details
.alter_command_description(command) ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/ufo/command.rb', line 144 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
97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/ufo/command.rb', line 97 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 non_project_command? 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 |
.check_version_structure! ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/ufo/command.rb', line 118 def check_version_structure! return if non_project_command? return if File.exist?('.ufo/config.rb') puts "ERROR: Latest ufo structure not detected".color(:red) puts <<~EOL It looks like this project .ufo files for an older ufo version. The old .ufo structure does not work with this version of ufo. Current Installed UFO Version: #{Ufo::VERSION} Please update the .ufo structure. See: https://ufoships.com/docs/upgrading/upgrade6/ EOL exit 1 end |
.command_help(shell, command_name) ⇒ Object
Override command_help to include the description at the top of the long_description.
137 138 139 140 141 142 |
# File 'lib/ufo/command.rb', line 137 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
79 80 81 82 83 84 85 86 |
# File 'lib/ufo/command.rb', line 79 def configure_dsl_evaluator DslEvaluator.configure do |config| config.backtrace.select_pattern = "#{Ufo.root}/.ufo" 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 68 69 70 71 72 73 74 75 |
# 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 check_project!(args) check_version_structure! # Special case for `ufo central` commands. # Dont want to call configure_dsl_evaluator # and trigger loading of config => .ufo/config.rb # Also, using ARGV instead of args because args is called by thor in multiple passes # For `ufo central update`: # * 1st pass: "central" # * 2nd pass: "update" configure_dsl_evaluator unless ARGV[0] == "central" # 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.
173 174 175 |
# File 'lib/ufo/command.rb', line 173 def exit_on_failure? true end |
.help_flags ⇒ Object
88 89 90 |
# File 'lib/ufo/command.rb', line 88 def help_flags Thor::HELP_MAPPINGS + ["help"] end |
.non_project_command? ⇒ Boolean
Also, using ARGV instead of args because args is called by thor in multiple passes For ‘ufo central update`:
-
1st pass: “central”
-
2nd pass: “update”
113 114 115 116 |
# File 'lib/ufo/command.rb', line 113 def non_project_command? commands = %w[-h -v --version completion completion_script help central init version] commands.include?(ARGV[0]) end |
.subcommand? ⇒ Boolean
93 94 95 |
# File 'lib/ufo/command.rb', line 93 def subcommand? !!caller.detect { |l| l.include?('in subcommand') } end |
.website ⇒ Object
meant to be overriden
166 167 168 |
# File 'lib/ufo/command.rb', line 166 def website "http://ufoships.com" end |