Class: ThorSCMVersion::ShellUtils
- Inherits:
-
Object
- Object
- ThorSCMVersion::ShellUtils
- Defined in:
- lib/thor-scmversion/shell_utils.rb
Class Method Summary collapse
- .secure_password ⇒ Object
- .sh(cmd, dir = '.', &block) ⇒ Object
- .sh_with_excode(cmd, dir = '.', &block) ⇒ Object
Class Method Details
.secure_password ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'lib/thor-scmversion/shell_utils.rb', line 6 def secure_password password = String.new while password.length < 20 password << ::OpenSSL::Random.random_bytes(1).gsub(/\W/, '') end password end |
.sh(cmd, dir = '.', &block) ⇒ Object
15 16 17 18 |
# File 'lib/thor-scmversion/shell_utils.rb', line 15 def sh(cmd, dir = '.', &block) out, code = sh_with_excode(cmd, dir, &block) code == 0 ? out : raise(out.empty? ? "Running `#{cmd}` failed. Run this command directly for more detailed output." : out) end |
.sh_with_excode(cmd, dir = '.', &block) ⇒ Object
20 21 22 23 24 |
# File 'lib/thor-scmversion/shell_utils.rb', line 20 def sh_with_excode(cmd, dir = '.', &block) command = Mixlib::ShellOut.new(cmd << " 2>&1", :cwd => dir) command.run_command [command.stdout, command.exitstatus] end |