Class: ConfigOMat::Op::ParseMetaCli

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

Defined Under Namespace

Modules: CoreExt

Constant Summary collapse

DEFAULT_SYSTEMD_DIRECTORY =
'/run/systemd/system'

Instance Method Summary collapse

Instance Method Details

#callObject



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
81
82
83
84
85
86
87
88
89
90
# File 'lib/config_o_mat/meta_configurator/op/parse_meta_cli.rb', line 40

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

    opts.on(
      '-s', '--systemd-directory directory',
      "Write out systemd configuration to the given directory instead of #{DEFAULT_SYSTEMD_DIRECTORY}"
    ) do |dir|
      self.systemd_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.systemd_directory ||= DEFAULT_SYSTEMD_DIRECTORY

  self.configuration_directory = configuration_directory&.expand_path
end

#validateObject



92
93
94
95
96
97
98
99
100
# File 'lib/config_o_mat/meta_configurator/op/parse_meta_cli.rb', line 92

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