Sha256: 7bfdb90b0506b3adcf9830108062bc4aeaa1e7dde6215b4176af0ea36053dc2a

Contents?: true

Size: 1.06 KB

Versions: 1

Compression:

Stored size: 1.06 KB

Contents

# frozen_string_literal: true

##
# Usage example:
#
#   ConvenientService::Examples::Standard::Gemfile::Services::PrintShellCommand.result(command: "ls -a")
#
module ConvenientService
  module Examples
    module Standard
      class Gemfile
        module Services
          class PrintShellCommand
            include ConvenientService::Standard::Config

            attr_reader :command, :skip, :out

            def initialize(command:, skip: false, out: $stdout)
              @command = command
              @skip = skip
              @out = out
            end

            def result
              return failure(command: "Command is `nil`") if command.nil?
              return failure(command: "Command is empty?") if command.empty?

              return error("Printing of shell command `#{command}` is skipped") if skip

              out.puts

              out.puts ::Paint["$ #{command}", :blue, :bold]

              success
            end

            def fallback_result
              success
            end
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
convenient_service-0.13.0 lib/convenient_service/examples/standard/gemfile/services/print_shell_command.rb