Sha256: 84591acf3843e9dc35a5276f8fba95259beec2a5fca2b242632ca01360a8e79c

Contents?: true

Size: 1.92 KB

Versions: 5

Compression:

Stored size: 1.92 KB

Contents

module Coral
  module Vagrant
    module SubCommand
      class CoralConfig < ::Vagrant.plugin('2', :command)

        #-----------------------------------------------------------------------
        # Execution
        
        def execute
          options = {}
          success = true

          opts = OptionParser.new do |opts|
            opts.banner = 'Usage: coral config -ha --dir={config_dir} {config_name} [ {value} ]'
            opts.separator ''
            
            opts.on('-a', '--add', 'Add configuration value to existing values instead of overriding') do |a|
              options[:add] = a
            end

            options[:repo] = '.'
            opts.on('-r', '--repo REPO_DIR', 'Local directory of repository relative to the Vagrantfile root (.)') do |r|
              options[:repo] = r
            end

            options[:directory] = 'config'
            opts.on('-d', '--dir DIRECTORY', 'Root directory of configuration files (config)') do |d|
              options[:directory] = d
            end
            
            options[:ext] = 'json'
            opts.on('-e', '--ext FILE_EXTENSION', 'Configuration file extension (json)') do |e|
              options[:ext] = e
            end
          end

          #---

          args = parse_options(opts)
          return unless args
          
          raise ::Vagrant::Errors::CLIInvalidUsage, :help => opts.help.chomp if args.length < 1

          config_elements = args[0].gsub(/\s+/, '').split(/\@/)
          property        = config_elements.pop
          config_file     = File.join(config_elements)
          
          raise ::Vagrant::Errors::CLIInvalidUsage, :help => opts.help.chomp unless property && config_file
          
          config_file = "#{config_file}." + options[:ext]
          value       = ( args.size < 2 ? nil : args[1] )

          #---------
          # Start
          
          exit success ? 0 : 1
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
coral_vagrant-0.2.8 lib/coral_vagrant/commands/coral/config.rb
coral_vagrant-0.2.5 lib/coral_vagrant/commands/coral/config.rb
coral_vagrant-0.2.4 lib/coral_vagrant/commands/coral/config.rb
coral_vagrant-0.2.3 lib/coral_vagrant/commands/coral/config.rb
coral_vagrant-0.2.2 lib/coral_vagrant/commands/coral/config.rb