Method: GLI::InitConfig#initialize

Defined in:
lib/gli/commands/initconfig.rb

#initialize(config_file_name, commands, flags, switches) ⇒ InitConfig

Returns a new instance of InitConfig.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/gli/commands/initconfig.rb', line 11

def initialize(config_file_name,commands,flags,switches)
  @filename = config_file_name
  super(:names => :initconfig,
        :description => "Initialize the config file using current global options",
        :long_desc => 'Initializes a configuration file where you can set default options for command line flags, both globally and on a per-command basis.  These defaults override the built-in defaults and allow you to omit commonly-used command line flags when invoking this program',
        :skips_pre => true,:skips_post => true, :skips_around => true)

  @app_commands = commands
  @app_flags = flags
  @app_switches = switches

  self.desc 'force overwrite of existing config file'
  self.switch :force

  action do |global_options,options,arguments|
    if options[:force] || !File.exist?(@filename)
      create_config(global_options,options,arguments)
    else
      raise "Not overwriting existing config file #{@filename}, use --force to override"
    end
  end
end