Class: GLI::InitConfig

Inherits:
Command show all
Defined in:
lib/gli/commands/initconfig.rb

Overview

Command that initializes the configuration file for apps that use it.

Constant Summary collapse

COMMANDS_KEY =

:nodoc:

'commands'

Constants inherited from Command

Command::PARENT

Instance Attribute Summary

Attributes included from CommandSupport

#parent

Attributes inherited from CommandLineToken

#aliases, #description, #long_description, #name

Instance Method Summary collapse

Methods inherited from Command

#action, #default_command, #default_desc, #example, #has_option?, name_as_string, #name_for_help

Methods included from CommandSupport

#arg_name, #arguments, #arguments_description, #arguments_options, #commands, #commands_declaration_order, #context_description, #default_description, #default_value, #desc, #examples, #execute, #flag, #flags, #get_default_command, #has_action?, #long_desc, #names, #nodoc, #skips_around, #skips_post, #skips_pre, #switch, #switches, #topmost_ancestor

Methods included from DSL

#arg, #arg_name, #clear_nexts, #command, #command_missing, #default_value, #desc, #flag, #flags_declaration_order, #long_desc, #switch, #switches_declaration_order

Methods inherited from CommandLineToken

#<=>, #names_and_aliases

Constructor Details

#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