Sha256: 3383d00d3760354f1fb69009fd2c3e6539f0dd3e79bad133bfa96a8b3f347bc1
Contents?: true
Size: 1.42 KB
Versions: 13
Compression:
Stored size: 1.42 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 $stderr.puts "! #{e.to_s}" $stderr.puts $stderr.puts $stderr.puts usage_text 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
13 entries across 13 versions & 1 rubygems