Sha256: 394067b1301acf90b6f34fe9a4857c0c1d346513ee96dc83d7c4a0a3f0d67d4b

Contents?: true

Size: 807 Bytes

Versions: 2

Compression:

Stored size: 807 Bytes

Contents

module Cumuli
  class CLI
    class RemoteCommand
      attr_reader :argv

      DIR_ENV = 'DIR='
      COMMAND_ENV= 'COMMAND='

      def initialize(argv)
        @argv = argv
      end

      def extract_env(env_var)
        found_arg = argv.detect{|arg| arg.include?(env_var)}
        found_arg && found_arg.gsub(env_var, '')
      end

      def dir
        extract_env(DIR_ENV)
      end

      def raw_command
        extract_env(COMMAND_ENV) || get_passed_command
      end

      def get_passed_command
        matched = argv.first.match(/\[(.*)\]/)
        (matched && matched[1]) || argv.first
      end

      def command
        Commander.new(raw_command).build
      end

      def perform
        Dir.chdir(dir) do
          Terminal.new(command).spawn
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cumuli-0.4.1 lib/cumuli/cli/remote_command.rb
cumuli-0.4.0 lib/cumuli/cli/remote_command.rb