Method: GLI::InitConfig#execute

Defined in:
lib/support/initconfig.rb

#execute(global_options, options, arguments) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/support/initconfig.rb', line 17

def execute(global_options,options,arguments)
  if options[:force] || !File.exist?(@filename)
    config = global_options
    config[COMMANDS_KEY] = {}
    GLI.commands.each do |name,command|
      if (command != self) && (name != :rdoc) && (name != :help)
        config[COMMANDS_KEY][name.to_sym] = {} if command != self
      end
    end
    File.open(@filename,'w', 0600) do |file|
      YAML.dump(config,file)
    end
  else
    raise "Not overwriting existing config file #{@filename}, use --force to override"
  end
end