class Leg::CLI

Constants

CONFIG_FILE

Public Class Methods

new() click to toggle source
# File lib/leg/cli.rb, line 4
def initialize
  initial_dir = FileUtils.pwd

  last_dir = nil
  last_dir2 = nil
  while FileUtils.pwd != last_dir
    if File.exist?(CONFIG_FILE)
      @config = YAML.load(File.read(CONFIG_FILE))
      unless @config.is_a? Hash
        puts "Error: Invalid config file."
        exit!
      end
      @config[:path] = FileUtils.pwd
      @config[:step_path] = last_dir2
      @config[:orig_path] = initial_dir
      break
    end

    last_dir2 = last_dir
    last_dir = FileUtils.pwd
    FileUtils.cd('..')
  end

  FileUtils.cd(initial_dir)
end

Public Instance Methods

run(args) click to toggle source
# File lib/leg/cli.rb, line 30
def run(args)
  args = ["help"] if args.empty?
  cmd_name = args.shift.downcase

  if cmd_name =~ /\A\d+\z/
    args.unshift(cmd_name)
    cmd_name = "ref"
  end

  if cmd = Leg::Commands::LIST.find { |cmd| cmd.name == cmd_name }
    cmd.new(args, @config).run
  else
    puts "There is no '#{cmd_name}' command. Run `leg help` for help."
  end
end