Sha256: c3193c973fe9a0c09a744c46f8d7d76f72d2a4cb0a0dc9cd6328d3b13d21ba09
Contents?: true
Size: 1.39 KB
Versions: 3
Compression:
Stored size: 1.39 KB
Contents
require 'slop' 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://console.flydata.com/ and sign up." return end begin if @args.size > 0 first_arg = @args.shift cmd, sub_cmd = parse_command(first_arg) begin cmd_cls = "Flydata::Command::#{cmd.capitalize}".constantize rescue raise "Command not found: #{cmd}" end # Command class can define options for each subcommand by defining method "slop_subcommandname" slop_method = sub_cmd ? "slop_#{sub_cmd}".to_sym : :slop options = cmd_cls.respond_to?(slop_method) ? cmd_cls.send(slop_method) : Slop.new(strict: true) options.parse!(@args) cmd_obj = cmd_cls.new(options) sub_cmd ? cmd_obj.send(sub_cmd,*@args) : cmd_obj.run(*@args) else raise 'no command given' end rescue => e #raise e puts "! #{e.to_s}" puts puts print_usage raise e if FLYDATA_DEBUG exit 1 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
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
flydata-0.2.5 | lib/flydata/cli.rb |
flydata-0.2.4 | lib/flydata/cli.rb |
flydata-0.2.3 | lib/flydata/cli.rb |