Sha256: 61bb511c0e178fa4a8c6e09ef62ebbe93c1dcc6f5239e0b49ac83a0502b3eb03

Contents?: true

Size: 956 Bytes

Versions: 7

Compression:

Stored size: 956 Bytes

Contents

module Flydata
  class Cli
    include Helpers
    def initialize(args)
      @args = args
    end

    def run
      unless check_environment
        puts "Sorry, you have to run the installation command to use flydata. Please go to https://secure.flydata.co/ and sign up."
        return
      end
      begin
        if @args.size > 0
          first_arg = @args.shift
          cmd, sub_cmd = parse_command(first_arg)
          cmd_cls = "Flydata::Command::#{cmd.capitalize}".constantize
          cmd_obj = cmd_cls.new
          sub_cmd ? cmd_obj.send(sub_cmd) : cmd_obj.run
        else
          raise 'no command given'
        end
      rescue => e
        #raise e
        puts "! #{e.to_s}"
        puts
        puts
        print_usage
        raise e if FLYDATA_DEBUG
      end
    end

    private
    def check_environment
      FileTest.file?(flydata_api_host_file)
    end
    def parse_command(cmd)
      cmd.split(':')
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
flydata-0.1.7 lib/flydata/cli.rb
flydata-0.1.6 lib/flydata/cli.rb
flydata-0.1.5 lib/flydata/cli.rb
flydata-0.1.4 lib/flydata/cli.rb
flydata-0.1.3 lib/flydata/cli.rb
flydata-0.1.1 lib/flydata/cli.rb
flydata-0.1.0 lib/flydata/cli.rb