Sha256: abcd1c176119bd4ba9ba34cbfc63cccb44019ec3e505c700ced19dd4490ef916
Contents?: true
Size: 1.28 KB
Versions: 2
Compression:
Stored size: 1.28 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://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 # 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 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
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
flydata-0.1.10 | lib/flydata/cli.rb |
flydata-0.1.9 | lib/flydata/cli.rb |