Sha256: 5151299d0b94f2ffa1f1927fadad0a73d640276dc27cb988ef13546f45b1d80a

Contents?: true

Size: 973 Bytes

Versions: 2

Compression:

Stored size: 973 Bytes

Contents

# frozen_string_literal: true

module Pcli
  module Services
    module Steps
      class Main < Step
        include Depends.on(
          'input',
          'output',
          'commander'
        )

        spaced

        def initialize(**args)
          super

          @cmd_prompt = TTY::Prompt.new(
            input: input,
            output: output,
            enable_color: false
          )
        end

        def run(_)
          output.puts while _run

          success
        end

        private

        attr_reader :cmd_prompt

        def _run
          cmd = cmd_prompt.ask("#{Pl.blue('pcli')}>")

          begin
            result = commander.run(cmd) || CommandOutput.continue
            !result.halt?
          rescue StandardError => e
            output.puts(Pl.red('Exception occurred during command!'))
            output.puts
            output.puts(e.full_message)
            true
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pcli-0.1.1 lib/pcli/services/steps/main.rb
pcli-0.1.0 lib/pcli/services/steps/main.rb