Class: Ops
- Inherits:
-
Object
- Object
- Ops
- Defined in:
- lib/ops.rb
Overview
executes commands based on local ‘ops.yml`
Constant Summary collapse
- INVALID_SYNTAX_EXIT_CODE =
64
- UNKNOWN_ACTION_EXIT_CODE =
65
- ERROR_LOADING_APP_CONFIG_EXIT_CODE =
66
- MIN_VERSION_NOT_MET_EXIT_CODE =
67
- ACTION_CONFIG_ERROR_EXIT_CODE =
68
- BUILTIN_SYNTAX_ERROR_EXIT_CODE =
69
- ACTION_NOT_ALLOWED_IN_ENV_EXIT_CODE =
70
- RECOMMEND_HELP_TEXT =
"Run 'ops help' for a list of builtins and actions."
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(argv, config_file: nil) ⇒ Ops
constructor
A new instance of Ops.
-
#run ⇒ Object
rubocop:disable Metrics/MethodLength better to have all the rescues in one place.
Constructor Details
#initialize(argv, config_file: nil) ⇒ Ops
Returns a new instance of Ops.
32 33 34 35 36 37 38 |
# File 'lib/ops.rb', line 32 def initialize(argv, config_file: nil) @action_name = argv[0] @args = argv[1..-1] @config_file = config_file || CONFIG_FILES.find { |file| File.exist?(file) } || "ops.yml" Options.set(config["options"] || {}) end |
Class Method Details
.project_name ⇒ Object
27 28 29 |
# File 'lib/ops.rb', line 27 def project_name File.basename(::Dir.pwd) end |
Instance Method Details
#run ⇒ Object
rubocop:disable Metrics/MethodLength better to have all the rescues in one place
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 |
# File 'lib/ops.rb', line 42 def run # "return" is here to allow specs to stub "exit" without executing everything after it return exit(INVALID_SYNTAX_EXIT_CODE) unless syntax_valid? return exit(MIN_VERSION_NOT_MET_EXIT_CODE) unless min_version_met? Profiler.measure("runner:run") do runner.run end rescue Runner::UnknownActionError => e Output.error(e.to_s) Output.out(RECOMMEND_HELP_TEXT) unless print_did_you_mean exit(UNKNOWN_ACTION_EXIT_CODE) rescue Runner::ActionConfigError => e Output.error("Error(s) running action '#{@action_name}': #{e}") exit(ACTION_CONFIG_ERROR_EXIT_CODE) rescue Builtin::ArgumentError => e Output.error("Error running builtin '#{@action_name}': #{e}") exit(BUILTIN_SYNTAX_ERROR_EXIT_CODE) rescue AppConfig::ParsingError => e Output.error("Error parsing app config: #{e}") exit(ERROR_LOADING_APP_CONFIG_EXIT_CODE) rescue Runner::NotAllowedInEnvError => e Output.error("Error running action #{@action_name}: #{e}") exit(ACTION_NOT_ALLOWED_IN_ENV_EXIT_CODE) end |