Class: ConfigOMat::Op::ParseCli

Inherits:
LifecycleVM::OpBase
  • Object
show all
Defined in:
lib/config_o_mat/configurator/op/parse_cli.rb

Defined Under Namespace

Modules: CoreExt

Instance Method Summary collapse

Instance Method Details

#callObject



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
72
73
74
75
76
77
78
79
80
# File 'lib/config_o_mat/configurator/op/parse_cli.rb', line 37

def call
  self.early_exit = false

  parser = OptionParser.new do |opts|
    opts.on('-v', '--version', 'Display the version') do
      self.early_exit = true
    end

    opts.on('-h', '--help', 'Prints this help') do
      puts opts
      self.early_exit = true
    end

    opts.on(
      '-c', '--configuration-directory directory',
      'Read configuration from the given directory instead of from $CONFIGURATION_DIRECTORY'
    ) do |dir|
      self.configuration_directory = dir
    end

    opts.on(
      '-r', '--runtime-directory directory',
      'Use the given directory for writing templates instead of $RUNTIME_DIRECTORY'
    ) do |dir|
      self.runtime_directory = dir
    end

    opts.on(
      '-l', '--logs-directory directory',
      'Use the given directory for writing log files instead of $LOGS_DIRECTORY'
    ) do |dir|
      self.logs_directory = dir
    end
  end

  parser.parse(argv)

  self.configuration_directory ||= env['CONFIGURATION_DIRECTORY']
  self.runtime_directory ||= env['RUNTIME_DIRECTORY']
  self.logs_directory ||= env['LOGS_DIRECTORY']

  self.configuration_directory = configuration_directory&.expand_path
  self.runtime_directory = runtime_directory&.expand_path
end

#validateObject



82
83
84
85
86
87
88
89
90
# File 'lib/config_o_mat/configurator/op/parse_cli.rb', line 82

def validate
  return if early_exit

  if configuration_directory.nil? || configuration_directory.empty?
    error :configuration_directory, 'must be present'
  end

  error :runtime_directory, 'must be present' if runtime_directory.nil? || runtime_directory.empty?
end