Class: YleTfPlugins::CommandHelp::Command
- Inherits:
-
Object
- Object
- YleTfPlugins::CommandHelp::Command
- Defined in:
- lib/yle_tf_plugins/commands/help/command.rb
Instance Method Summary collapse
- #device(env) ⇒ Object
-
#error?(env) ⇒ Boolean
rubocop:enable Metrics/AbcSize, Metrics/MethodLength.
- #execute(env) ⇒ Object
-
#opts ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/MethodLength.
- #terraform_help ⇒ Object
- #tf_command_help ⇒ Object
Instance Method Details
#device(env) ⇒ Object
41 42 43 |
# File 'lib/yle_tf_plugins/commands/help/command.rb', line 41 def device(env) error?(env) ? STDERR : STDOUT end |
#error?(env) ⇒ Boolean
rubocop:enable Metrics/AbcSize, Metrics/MethodLength
37 38 39 |
# File 'lib/yle_tf_plugins/commands/help/command.rb', line 37 def error?(env) env[:tf_env] == 'error' end |
#execute(env) ⇒ Object
9 10 11 12 |
# File 'lib/yle_tf_plugins/commands/help/command.rb', line 9 def execute(env) device(env).puts(opts.help) exit 1 if error?(env) end |
#opts ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/MethodLength
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/yle_tf_plugins/commands/help/command.rb', line 15 def opts OptionParser.new do |o| o.summary_width = 18 o. = 'Usage: tf <environment> <command> [<args>]' o.separator '' o.separator 'YleTf options:' o.on('-h', '--help', 'Prints this help') o.on('-v', '--version', 'Prints the version information') o.on('--debug', 'Print debug information') o.on('--no-color', 'Do not output with colors') o.on('--no-hooks', 'Do not run any hooks') o.on('--only-hooks', 'Only run the hooks') o.separator '' o.separator 'Special tf commands:' o.separator tf_command_help o.separator '' o.separator 'Terraform commands:' o.separator terraform_help end end |
#terraform_help ⇒ Object
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/yle_tf_plugins/commands/help/command.rb', line 51 def terraform_help on_error = proc do |exit_code| # exit_code is nil if the command was not found # Ignore other exit codes, as older Terraform versions return # non-zero exit codes for the help. return ' [Terraform not found]' if exit_code.nil? end help = YleTf::System.read_cmd('terraform', '--help', error_handler: on_error) help.lines.grep(/^ /) end |