Class: GLI::InitConfig
- Inherits:
-
Command
- Object
- CommandLineToken
- Command
- GLI::InitConfig
- Defined in:
- lib/support/initconfig.rb
Overview
:nodoc:
Constant Summary collapse
- COMMANDS_KEY =
'commands'
Instance Attribute Summary
Attributes inherited from CommandLineToken
#aliases, #description, #long_description, #name
Instance Method Summary collapse
- #execute(global_options, options, arguments) ⇒ Object
-
#initialize(config_file_name) ⇒ InitConfig
constructor
A new instance of InitConfig.
Methods inherited from Command
#action, #arg_name, #arguments_description, #clear_nexts, #default_value, #desc, #flag, #flags, #long_desc, name_as_string, #names, #skips_post, #skips_pre, #switch, #switches, #usage
Methods included from CopyOptionsToAliases
Methods inherited from CommandLineToken
Constructor Details
#initialize(config_file_name) ⇒ InitConfig
Returns a new instance of InitConfig.
9 10 11 12 13 14 15 |
# File 'lib/support/initconfig.rb', line 9 def initialize(config_file_name) @filename = config_file_name super(:initconfig,"Initialize the config file using current global options",nil,'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') self.desc 'force overwrite of existing config file' self.switch :force end |
Instance Method Details
#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(,,arguments) if [:force] || !File.exist?(@filename) config = 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 |