Sha256: ff819e9c9e4f08e4eaf6bf1e3c9e280794648381cd90a242b72bb5e907e5bfd5

Contents?: true

Size: 791 Bytes

Versions: 4

Compression:

Stored size: 791 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]
      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

4 entries across 4 versions & 1 rubygems

Version Path
cumuli-0.3.4 lib/cumuli/cli/remote_command.rb
cumuli-0.3.2 lib/cumuli/cli/remote_command.rb
cumuli-0.3.1 lib/cumuli/cli/remote_command.rb
cumuli-0.3.0 lib/cumuli/cli/remote_command.rb