Module: CemAcpt::Cli

Defined in:
lib/cem_acpt/cli.rb

Class Method Summary collapse

Class Method Details

.parse_opts_for(command) ⇒ Object



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
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/cem_acpt/cli.rb', line 7

def self.parse_opts_for(command)
  cmd = command
  options = {}
  parser = OptionParser.new do |opts|
    opts.banner = "Usage: #{command} [options]"

    opts.on('-h', '--help', 'Show this help message') do
      puts opts
      exit 0
    end

    # Command specific options
    case command
    when :cem_acpt
      opts.on('-m', '--module-dir DIR', 'Set module directory. Example: -m "/tmp/module"') do |m|
        options[:module_dir] = m
      end

      opts.on('-a', '--only-actions ACTIONS', 'Set actions. Example: -a "acpt,noop"') do |a|
        options[:actions] ||= {}
        options[:actions][:only] = a.split(',')
      end

      opts.on('-A', '--except-actions ACTIONS', 'Set excluded actions. Example: -A "noop,idempotent"') do |a|
        options[:actions] ||= {}
        options[:actions][:except] = a.split(',')
      end

      opts.on('-t', '--tests TESTS', 'Set tests. Example: -t "test1,test2"') do |t|
        options[:tests] = t.split(',')
      end

      opts.on('-B', '--no-bolt-tests', 'Do not run Bolt tests') do
        options[:bolt] ||= {}
        options[:bolt][:tests] ||= {}
        options[:bolt][:tests][:enabled] = false
      end
    when :cem_acpt_image
      opts.on('--dry-run', 'Logs the information for the images that would be created. Does not create images.') do
        options[:dry_run] = true
      end

      opts.on('--no-build-images', 'Do not build images. Can be combined with --no-destroy-nodes to just provision nodes.') do
        options[:no_build_images] = true
      end

      opts.on('--no-linux', 'Do not build Linux images') do
        options[:cem_acpt_image] ||= {}
        options[:cem_acpt_image][:no_linux] = true
      end

      opts.on('--no-windows', 'Do not build Windows images') do
        options[:cem_acpt_image] ||= {}
        options[:cem_acpt_image][:no_windows] = true
      end

      opts.on('-F', '--filter FILTER', 'Filter images to build by name with regex. Example: -F "(alma|rhel)-8"') do |f|
        options[:image_name_filter] = Regexp.new(f)
      end
    end

    opts.on('-D', '--debug', 'Enable debug logging') do
      options[:log_level] = 'debug'
    end

    opts.on('-L', '--log-file FILE', 'Log to FILE') do |file|
      options[:log_file] = file
    end

    opts.on('-O', '--options OPTS', 'Set options. Example: -P "param1=value1,param2=value2"') do |o|
      params = o.split(',').map { |s| s.split('=') }.to_h
      params.transform_keys(&:to_sym).each do |k, v|
        options[k] = v
      end
    end

    opts.on('-p', '--platform PLATFORM', 'Set platform. Example: -p "gcp"') do |p|
      options[:platform] = p
    end

    opts.on('-c', '--config-file FILE', 'Set config file. Example: -c "/tmp/config.yaml"') do |c|
      options[:config_file] = c
    end

    opts.on('-I', '--CI', 'Run in CI mode (modifies logging for Github Actions output)') do
      options[:ci_mode] = true
      options[:log_format] = 'github_action'
    end

    opts.on('-E', '--no-destroy-nodes', 'Do not destroy nodes') do
      options[:no_destroy_nodes] = true
    end

    opts.on('-q', '--quiet', 'Do not log to stdout') do
      options[:quiet] = true
    end

    opts.on('-v', '--verbose', 'Enables verbose logging mode') do
      options[:verbose] = true
    end

    opts.on('-S', '--no-epehemeral-ssh-key', 'Do not generate an ephemeral SSH key for test suites') do
      options[:no_ephemeral_ssh_key] = true
    end

    opts.on('-V', '--version', 'Show the cem_acpt version') do
      cmd = :version
    end

    opts.on('-Y', '--print-yaml-config', 'Loads and prints the config as YAML. Other specified options will be added to the config.') do
      cmd = :print_yaml_config
    end

    opts.on('-X', '--explain-config', 'Loads and prints the config explanation. Other specified options will be added to the config.') do
      cmd = :print_explain_config
    end

    opts.on('--trace', 'Enables trace output') do
      options[:trace] = true
    end

    opts.on(
      '--trace-events [EVENTS]',
      [
        'Comma-separated list of trace events to enable. Example: --trace-events "line,call,b_call,thread_begin,thread_end"',
        'See here for list of events: https://ruby-doc.org/core-2.5.0/TracePoint.html#class-TracePoint-label-Events.',
        'Default: line,call,b_call,thread_begin,thread_end',
      ].join(' '),
    ) do |events|
      options[:trace_events] = events.split(',')
    end

    opts.on('--puppet-no-debug', 'Disables Puppet debug logging') do
      options[:puppet] ||= {}
      options[:puppet][:no_debug] = true
    end

    opts.on('--puppet-no-verbose', 'Disables Puppet verbose logging') do
      options[:puppet] ||= {}
      options[:puppet][:no_verbose] = true
    end
  end
  parser.parse!
  [cmd, options]
end