Module: GClouder::Config::CLIArgs

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.checkObject

Raises:

  • (ArgumentError)


73
74
75
76
# File 'lib/gclouder/config/cli_args.rb', line 73

def self.check
  raise ArgumentError, "config file not specified" unless cli_args[:config_given]
  raise ArgumentError, "config file not readable: #{cli_args[:config]}" unless File.readable?(cli_args[:config])
end

.cli_argsObject



6
7
8
# File 'lib/gclouder/config/cli_args.rb', line 6

def self.cli_args
  @cli_args ||= { debug: false }
end

.included(klass) ⇒ Object



14
15
16
# File 'lib/gclouder/config/cli_args.rb', line 14

def self.included(klass)
  klass.extend CLIArgs
end

.loadObject



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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/gclouder/config/cli_args.rb', line 22

def self.load
  option_parser = Trollop::Parser.new do
    banner GClouder::Header.display + "\n \n "

    # required
    opt :config,                       "path to config file\n ", type: :string, required: true

    # level of operation
    opt :dry_run,                      "passive mode"
    opt :purge,                        "remove unmanaged resources (destructive!)\n "

    # authentication / for automation
    opt :activate_service_accounts,    "activate service account(s) (for use when running using service accounts, i.e: with CI)"
    opt :keys_dir,                     "path to directory with service account key files (for use with --activate-service-accounts)\n ", type: :string

    opt :ignore_default_service_account, "don't attempt to switch back to a default service account for the environment"

    # which resources / actions
    # FIXME: integrate checks for required permissions into Project module
    opt :bootstrap,                    "create project (requires being run as non-service account)"
    # this should be type: proc and validate that the params match one of: validate, ensure, clean
    opt :stages,                       "which stages to run (validate,ensure,clean) [csv]", type: :string
    opt :resources,                    "which resources to update [csv]", type: :string
    opt :skip_cross_project_resources, "skip resources which don't reside in main project\n "

    # output
    opt :debug,                        "print commands to be executed, and stack traces"
    opt :trace,                        "print stack traces"
    opt :no_color,                     "disable color\n \n "
  end

  @cli_args = Trollop.with_standard_exception_handling(option_parser) do
    raise Trollop::HelpNeeded if ARGV.empty?
    option_parser.parse ARGV
  end

  String.disable_colorization = @cli_args[:no_color]

  if @cli_args[:resources]
    @cli_args[:resources].split(',').each do |resource|
      unless valid_resources.include?(resource)
        puts "valid resources: #{valid_resources.join(', ')}"
        puts "invalid resource for --resources flag: #{resource}"
        exit 1
      end
    end
  end

  check
end

.valid_resourcesObject



18
19
20
# File 'lib/gclouder/config/cli_args.rb', line 18

def self.valid_resources
  GClouder.resources.map { |resource| resource[:name] }
end

Instance Method Details

#cli_argsObject



10
11
12
# File 'lib/gclouder/config/cli_args.rb', line 10

def cli_args
  CLIArgs.cli_args
end