Sha256: de6d8c52a44a2ab4f254b3b7e3924eb18c2c3a6e6dff7709affc81cc1ff0205c

Contents?: true

Size: 1.21 KB

Versions: 24

Compression:

Stored size: 1.21 KB

Contents

require 'gli'
require 'gli/command'
require 'yaml'

module GLI
  class InitConfig < Command # :nodoc:
    COMMANDS_KEY = 'commands'

    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

    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') do |file|
          YAML.dump(config,file)
        end
      else
        raise "Not overwriting existing config file #{@filename}, use --force to override"
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 3 rubygems

Version Path
brightbox-cli-0.18.1 lib/brightbox-cli/vendor/gli/lib/support/initconfig.rb
brightbox-cli-0.18.0 lib/brightbox-cli/vendor/gli/lib/support/initconfig.rb
brightbox-cli-0.17.5 lib/brightbox-cli/vendor/gli/lib/support/initconfig.rb
brightbox-cli-0.17.4 lib/brightbox-cli/vendor/gli/lib/support/initconfig.rb
brightbox-cli-0.17.3 lib/brightbox-cli/vendor/gli/lib/support/initconfig.rb
brightbox-cli-0.17.2 lib/brightbox-cli/vendor/gli/lib/support/initconfig.rb
brightbox-cli-0.17.1 lib/brightbox-cli/vendor/gli/lib/support/initconfig.rb
brightbox-cli-0.17.0 lib/brightbox-cli/vendor/gli/lib/support/initconfig.rb
brightbox-cli-0.16.0 lib/brightbox-cli/vendor/gli/lib/support/initconfig.rb
gli-1.3.6 lib/support/initconfig.rb
brightbox-cli-0.15.0 lib/brightbox-cli/vendor/gli/lib/support/initconfig.rb
gli-1.3.5 lib/support/initconfig.rb
brightbox-cli-0.14.1 lib/brightbox-cli/vendor/gli/lib/support/initconfig.rb
brightbox-cli-0.14.0 lib/brightbox-cli/vendor/gli/lib/support/initconfig.rb
gli-1.3.4 lib/support/initconfig.rb
brightbox-cli-0.13.1 lib/brightbox-cli/vendor/gli/lib/support/initconfig.rb
bbcloud-0.13.0 lib/bbcloud/vendor/gli/lib/support/initconfig.rb
brightbox-cli-0.13.0 lib/brightbox-cli/vendor/gli/lib/support/initconfig.rb
gli-1.3.3 lib/support/initconfig.rb
bbcloud-0.12.0 lib/bbcloud/vendor/gli/lib/support/initconfig.rb