class Rb1drvTools::CLI

Constants

CLI_DELIMITER

Public Class Methods

cwd() click to toggle source
# File lib/rb1drv-tools/cli.rb, line 49
def self.cwd
  @cwd ||= CLI.od.root
end
cwd=(value) click to toggle source
# File lib/rb1drv-tools/cli.rb, line 53
def self.cwd=value
  @cwd = value
end
logger() click to toggle source
# File lib/rb1drv-tools/cli.rb, line 66
def self.logger
  @logger
end
new(*args) click to toggle source
# File lib/rb1drv-tools/cli.rb, line 4
def initialize(*args)
  CLI.set_od(*args)

  @profiles = Profile.all
  @profile_index = nil
  @profile = nil

  ARGV << 'help' if ARGV.empty?

  set_profile
  split_args.each do |args|
    dispatch_command args
  end
end
od() click to toggle source
# File lib/rb1drv-tools/cli.rb, line 62
def self.od
  @od
end
set_od(*args) click to toggle source
# File lib/rb1drv-tools/cli.rb, line 57
def self.set_od(*args)
  @logger = args[3]
  @od = OneDrive.new(*args)
end

Public Instance Methods

dispatch_command(args) click to toggle source
# File lib/rb1drv-tools/cli.rb, line 38
def dispatch_command(args)
  return if args.empty?
  cmd = args.shift
  method = "cmd_#{cmd}"
  unless Command.respond_to?(method)
    puts "Unknown command #{cmd}"
    return
  end
  Command.send(method, args)
end
set_profile() click to toggle source
# File lib/rb1drv-tools/cli.rb, line 19
def set_profile
  if ARGV.first[0] == ':'
    @profile_index = ARGV.shift[1..-1]
    Profile.profile_index = @profile_index
  end
end
split_args() click to toggle source
# File lib/rb1drv-tools/cli.rb, line 26
def split_args
  argv = ARGV.dup
  @profile_index = argv.shift[1..-1] if argv.first[0] == ':'
  Enumerator.new do |y|
    while delimiter_pos = argv.index(CLI_DELIMITER)
      y << argv[0...delimiter_pos]
      argv = argv[(delimiter_pos+1)..-1]
    end
    y << argv
  end
end