Module: BranchIOCLI::Helper::Methods
- Included in:
- Command::SetupCommand, IOSHelper, ReportHelper, ToolHelper, 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) ⇒ Object
Execute a shell command with reporting.
Instance Method Details
#clear ⇒ Object
Clear the screen and move the cursor to the top using highline
34 35 36 |
# File 'lib/branch_io_cli/helper/methods.rb', line 34 def clear say "\e[2J\e[H" end |
#confirm(question, default_value) ⇒ Object
Ask a yes/no question with a default
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/branch_io_cli/helper/methods.rb', line 39 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) ⇒ 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. No redirection occurs.
28 29 30 31 |
# File 'lib/branch_io_cli/helper/methods.rb', line 28 def sh(*command) status = STDOUT.sh(*command) raise CommandError, [command, status] unless status.success? end |