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
4 5 6 7 8 9 10 11 |
# File 'lib/thor-scmversion/shell_utils.rb', line 4 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
13 14 15 16 |
# File 'lib/thor-scmversion/shell_utils.rb', line 13 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
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/thor-scmversion/shell_utils.rb', line 18 def sh_with_excode(cmd, dir = '.', &block) cmd << " 2>&1" output = "" status = nil Dir.chdir(dir) { stdin, stdout, stderr, wait_thr = Open3::popen3(cmd) status = wait_thr.value output = stdout.readlines.join if status.to_i == 0 block.call(output) if block end } [ output, status ] end |