summaryrefslogtreecommitdiff
path: root/lib/leap_cli/commands/pre.rb
blob: 346814b60b9d2dbb22674df79ad2665f229a4267 (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57

#
# 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 'Display version number and exit'
    switch :version, :negatable => false

    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

      #
      # load Leapfile
      #
      unless LeapCli.leapfile.load
        bail! { log :missing, 'Leapfile in directory tree' }
      end
      Path.set_platform_path(LeapCli.leapfile.platform_directory_path)
      Path.set_provider_path(LeapCli.leapfile.provider_directory_path)
      if !Path.provider || !File.directory?(Path.provider)
        bail! { log :missing, "provider directory '#{Path.provider}'" }
      end
      if !Path.platform || !File.directory?(Path.platform)
        bail! { log :missing, "platform directory '#{Path.platform}'" }
      end

      #
      # load all the nodes everything
      #
      manager

      #
      # check requirements
      #
      REQUIREMENTS.each do |key|
        assert_config! key
      end

    end

  end
end