Class: Leg::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/leg/cli.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ CLI

Returns a new instance of CLI.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/leg/cli.rb', line 3

def initialize(options = {})
  @options = options

  initial_dir = FileUtils.pwd

  @config = nil
  last_dir = nil
  while FileUtils.pwd != last_dir
    if File.exist?("leg.yml")
      @config = Leg::Config.new(FileUtils.pwd)
      @config.load!
      break
    end

    last_dir = FileUtils.pwd
    FileUtils.cd("..")
  end

  FileUtils.cd(initial_dir)
end

Instance Method Details

#run(args) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/leg/cli.rb', line 24

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 = "step"
  end

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