summaryrefslogtreecommitdiff
path: root/lib/leap_cli/commands/pre.rb
blob: d80a9c23ac8a5666ec1ced5b9a2bf871739c9b0f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43

#
# check to make sure we can find the root directory of the platform
#
module LeapCli
  module Commands

    desc 'Verbosity level 0..2'
    arg_name 'level'
    default_value '1'
    flag [:v, :verbose]

    desc 'Specify the root directory'
    arg_name 'path'
    default_value Path.root
    flag [:root]

    pre do |global,command,options,args|
      #
      # set verbosity
      #
      LeapCli.log_level = global[:verbose].to_i
      if LeapCli.log_level > 1
        ENV['GLI_DEBUG'] = "true"
      else
        ENV['GLI_DEBUG'] = "false"
      end

      #
      # require a root directory
      #
      if global[:root]
        Path.set_root(global[:root])
      end
      if Path.ok?
        true
      else
        bail!("Could not find the root directory. Change current working directory or try --root")
      end
    end

  end
end