Class: HybridPlatformsConductor::Executable
- Inherits:
-
Object
- Object
- HybridPlatformsConductor::Executable
- Includes:
- LoggerHelpers
- Defined in:
- lib/hybrid_platforms_conductor/executable.rb
Overview
Give a common executable interface to all our executables
Constant Summary
Constants included from LoggerHelpers
LoggerHelpers::LEVELS_MODIFIERS, LoggerHelpers::LEVELS_TO_STDERR
Instance Attribute Summary collapse
-
#selected_nodes ⇒ Object
readonly
Give the list of selected nodes, if the option was offered.
Instance Method Summary collapse
-
#initialize(check_options: true, nodes_selection_options: true, parallel_options: true, timeout_options: true, deploy_options: true, logger: Logger.new(STDOUT, level: :info), logger_stderr: Logger.new(STDERR, level: :info), &opts_block) ⇒ Executable
constructor
Constructor.
-
#parse_options! ⇒ Object
Parse options for this executable.
Methods included from LoggerHelpers
#err, #init_loggers, #log_component=, #log_debug?, #log_level=, #out, #section, #set_loggers_format, #stderr_device, #stderr_device=, #stderr_displayed?, #stdout_device, #stdout_device=, #stdout_displayed?, #stdouts_to_s, #with_progress_bar
Constructor Details
#initialize(check_options: true, nodes_selection_options: true, parallel_options: true, timeout_options: true, deploy_options: true, logger: Logger.new(STDOUT, level: :info), logger_stderr: Logger.new(STDERR, level: :info), &opts_block) ⇒ Executable
Constructor
- Parameters
-
check_options (Boolean): Do we offer check/why-run options? [default: true]
-
nodes_selection_options (Boolean): Do we offer nodes selection options? [default: true]
-
parallel_options (Boolean): Do we offer parallel options? [default: true]
-
timeout_options (Boolean): Do we offer timeout options? [default: true]
-
deploy_options (Boolean): Do we offer deploy options? [default: true]
-
logger (Logger): The stdout logger to be used [default: Logger.new(STDOUT, level: :info)]
-
logger_stderr (Logger): The stderr logger to be used [default: Logger.new(STDERR, level: :info)]
-
opts_block (Proc): Optional code called to register main options
- Parameters
-
opts (OptionsParser): The options parser to complete
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/hybrid_platforms_conductor/executable.rb', line 40 def initialize( check_options: true, nodes_selection_options: true, parallel_options: true, timeout_options: true, deploy_options: true, logger: Logger.new(STDOUT, level: :info), logger_stderr: Logger.new(STDERR, level: :info), &opts_block ) init_loggers(logger, logger_stderr) @check_options = @nodes_selection_options = @parallel_options = @timeout_options = @deploy_options = @opts_block = opts_block # List of nodes description selected @selected_nodes = [] # Possible Conductor components this executable can use @instantiated_components = {} # Initialize the loggers # We set the debug format right now before calling the options parser, just in case some option parsing needs debugging (like plugins discovery) self.log_level = :debug if ARGV.include?('--debug') || ARGV.include?('-d') end |
Instance Attribute Details
#selected_nodes ⇒ Object (readonly)
Give the list of selected nodes, if the option was offered. Check NodesHandler#select_nodes to know which kind of nodes description exist.
Array<Object>
25 26 27 |
# File 'lib/hybrid_platforms_conductor/executable.rb', line 25 def selected_nodes @selected_nodes end |
Instance Method Details
#parse_options! ⇒ Object
Parse options for this executable. Use options for any Hybrid Platforms Conductor component that has been accessed through the above methods. Handle common options (like logging and help).
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/hybrid_platforms_conductor/executable.rb', line 108 def OptionParser.new do |opts| opts. = "Usage: #{$0} [options]" opts.separator '' opts.separator 'Main options:' opts.on('-d', '--debug', 'Activate debug mode') do self.log_level = :debug end opts.on('-h', '--help', 'Display help and exit') do out opts exit 0 end @opts_block.call(opts) if @opts_block nodes_handler.(opts) if nodes_handler_instantiated? nodes_handler.(opts, @selected_nodes) if @nodes_selection_options cmd_runner.(opts) if cmd_runner_instantiated? actions_executor.(opts, parallel: @parallel_options) if actions_executor_instantiated? deployer.( opts, parallel_switch: @parallel_options, timeout_options: @timeout_options, why_run_switch: @check_options ) if deployer_instantiated? && @deploy_options json_dumper.(opts) if json_dumper_instantiated? reports_handler.(opts) if reports_handler_instantiated? tests_runner.(opts) if tests_runner_instantiated? topographer.(opts) if topographer_instantiated? end.parse! actions_executor.validate_params if actions_executor_instantiated? deployer.validate_params if deployer_instantiated? reports_handler.validate_params if reports_handler_instantiated? topographer.validate_params if topographer_instantiated? raise "Unknown options: #{ARGV.join(' ')}" unless ARGV.empty? end |