Module: BranchIOCLI::Helper::Methods
- Included in:
- Command::SetupCommand, IOSHelper, ReportHelper, Util
- Defined in:
- lib/branch_io_cli/helper/methods.rb
Instance Method Summary collapse
-
#clear ⇒ Object
Clear the screen and move the cursor to the top using highline.
-
#confirm(question, default_value) ⇒ Object
Ask a yes/no question with a default.
-
#sh(command, output = STDOUT) ⇒ Object
Execute a shell command with reporting.
Instance Method Details
#clear ⇒ Object
Clear the screen and move the cursor to the top using highline
30 31 32 |
# File 'lib/branch_io_cli/helper/methods.rb', line 30 def clear say "\e[2J\e[H" end |
#confirm(question, default_value) ⇒ Object
Ask a yes/no question with a default
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/branch_io_cli/helper/methods.rb', line 35 def confirm(question, default_value) yn_opts = default_value ? "Y/n" : "y/N" value = ask "#{question} (#{yn_opts}) ", nil # Convert to true/false dummy_option = Configuration::Option.new({}) value = dummy_option.convert(value) return default_value if value.nil? || value.kind_of?(String) value end |
#sh(command, output = STDOUT) ⇒ Object
Execute a shell command with reporting. The command itself is logged, then output from both stdout and stderr, then a success or failure message. Raises CommandError on error.
If output is STDOUT (the default), no redirection occurs. In all other cases, both stdout and stderr are redirected to output. In these cases, formatting (colors, highlights) may be lost.
24 25 26 27 |
# File 'lib/branch_io_cli/helper/methods.rb', line 24 def sh(command, output = STDOUT) status = output.log_command command raise CommandError, [%{Error executing "#{command}": #{status}.}, status] unless status.success? end |