Class: NextcloudReleaseAgent::Shell
- Inherits:
-
Object
- Object
- NextcloudReleaseAgent::Shell
- Defined in:
- lib/nextcloud_release_agent/cli.rb
Instance Method Summary collapse
- #capture(*command, chdir:, allow_failure: false, env: {}) ⇒ Object
-
#initialize(logger:, dry_run: false) ⇒ Shell
constructor
A new instance of Shell.
- #system!(*command, chdir:, allow_failure: false, env: {}) ⇒ Object
Constructor Details
#initialize(logger:, dry_run: false) ⇒ Shell
Returns a new instance of Shell.
53 54 55 56 |
# File 'lib/nextcloud_release_agent/cli.rb', line 53 def initialize(logger:, dry_run: false) @logger = logger @dry_run = dry_run end |
Instance Method Details
#capture(*command, chdir:, allow_failure: false, env: {}) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/nextcloud_release_agent/cli.rb', line 58 def capture(*command, chdir:, allow_failure: false, env: {}) printable = command.shelljoin @logger.info("#{@dry_run ? 'would run' : 'running'}: #{printable}") return CommandResult.new(stdout: "", stderr: "", status: 0) if @dry_run stdout, stderr, status = Open3.capture3(env, *command, chdir: chdir) result = CommandResult.new(stdout: stdout, stderr: stderr, status: status.exitstatus) return result if status.success? || allow_failure raise Error, "command failed (#{status.exitstatus}): #{printable}\n#{stderr.strip}" end |
#system!(*command, chdir:, allow_failure: false, env: {}) ⇒ Object
70 71 72 73 74 75 |
# File 'lib/nextcloud_release_agent/cli.rb', line 70 def system!(*command, chdir:, allow_failure: false, env: {}) result = capture(*command, chdir: chdir, allow_failure: allow_failure, env: env) return result if result.status.zero? || allow_failure raise Error, "command failed (#{result.status}): #{command.shelljoin}\n#{result.stderr.strip}" end |