Sha256: 45562cdf2f7a30267c4dc44daa3586046e95708caaa388996db1670eb0f64036

Contents?: true

Size: 1.04 KB

Versions: 2

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

module ConvenientService
  module Examples
    module Dry
      module Gemfile
        module Services
          class RunShell
            include DryService::Config

            option :command
            option :debug, default: -> { false }

            contract do
              schema do
                required(:command).value(:string)
                optional(:debug).value(:bool)
              end
            end

            def result
              Services::PrintShellCommand.result(text: command) if debug

              ##
              # NOTE: When the command exit code is 0, `system` return true, and false otherwise.
              # - https://ruby-doc.org/core-3.1.2/Kernel.html#method-i-system
              # - https://stackoverflow.com/a/37329716/12201472
              #
              if system(command)
                success
              else
                error(message: "#{command} returned non-zero exit code")
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
convenient_service-0.2.0 lib/convenient_service/examples/dry/gemfile/services/run_shell.rb
convenient_service-0.1.0 lib/convenient_service/examples/dry/gemfile/services/run_shell.rb