Sha256: af8796358a1e6eee8179c1cbdbcae63b96e5afa00e8e9ce4bf5ba1924b9e546c

Contents?: true

Size: 1.14 KB

Versions: 3

Compression:

Stored size: 1.14 KB

Contents

# frozen_string_literal: true

##
# Usage example:
#
#   ConvenientService::Examples::Standard::V1::Gemfile::Services::PrintShellCommand.result(command: "ls -a")
#
module ConvenientService
  module Examples
    module Standard
      module V1
        class Gemfile
          module Services
            class PrintShellCommand
              include ConvenientService::Standard::V1::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_error_result
                success
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
convenient_service-0.16.0 lib/convenient_service/examples/standard/v1/gemfile/services/print_shell_command.rb
convenient_service-0.15.0 lib/convenient_service/examples/standard/v1/gemfile/services/print_shell_command.rb
convenient_service-0.14.0 lib/convenient_service/examples/standard/v1/gemfile/services/print_shell_command.rb