Sha256: 89f7d0aeb38890922610878614f32149872ef46a4142655c6d1cf8cd07fa0f10

Contents?: true

Size: 1.09 KB

Versions: 20

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true

require 'json'

# If pre-compiled catalogs are available, these can be used to short-circuit the build process.
# These files must exist and be in Puppet catalog format.
# @param parser [OptionParser object] The OptionParser argument
# @param options [Hash] Options hash being constructed; this is modified in this method.
OctocatalogDiff::Cli::Options::Option.newoption(:existing_catalogs) do
  has_weight 30

  def parse(parser, options)
    these_options = { 'from' => :from_catalog, 'to' => :to_catalog }
    these_options.each do |tag, hash_key|
      parser.on("--#{tag}-catalog FILENAME", "Use a pre-compiled catalog '#{tag}'") do |catalog_file|
        path = File.absolute_path(catalog_file)
        raise Errno::ENOENT, "Invalid '#{hash_key} catalog' file provided" unless File.file?(path)
        options[hash_key] = path
        if options[:node].nil?
          x = JSON.parse(File.read(path))
          options[:node] ||= x['data']['name'] if x['data'].is_a?(Hash)
          options[:node] ||= x['name'] if x['name'].is_a?(String)
        end
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
octocatalog-diff-2.3.1 lib/octocatalog-diff/cli/options/existing_catalogs.rb
octocatalog-diff-2.3.0 lib/octocatalog-diff/cli/options/existing_catalogs.rb
octocatalog-diff-2.1.0 lib/octocatalog-diff/cli/options/existing_catalogs.rb
octocatalog-diff-2.0.0 lib/octocatalog-diff/cli/options/existing_catalogs.rb
octocatalog-diff-1.6.0 lib/octocatalog-diff/cli/options/existing_catalogs.rb
octocatalog-diff-1.5.4 lib/octocatalog-diff/cli/options/existing_catalogs.rb
octocatalog-diff-1.5.3 lib/octocatalog-diff/cli/options/existing_catalogs.rb
octocatalog-diff-1.5.2 lib/octocatalog-diff/cli/options/existing_catalogs.rb
octocatalog-diff-1.5.1 lib/octocatalog-diff/cli/options/existing_catalogs.rb
octocatalog-diff-1.5.0 lib/octocatalog-diff/cli/options/existing_catalogs.rb
octocatalog-diff-1.4.1 lib/octocatalog-diff/cli/options/existing_catalogs.rb
octocatalog-diff-1.4.0 lib/octocatalog-diff/cli/options/existing_catalogs.rb
octocatalog-diff-1.3.0 lib/octocatalog-diff/cli/options/existing_catalogs.rb
octocatalog-diff-1.2.0 lib/octocatalog-diff/cli/options/existing_catalogs.rb
octocatalog-diff-1.1.0 lib/octocatalog-diff/cli/options/existing_catalogs.rb
octocatalog-diff-1.0.4 lib/octocatalog-diff/cli/options/existing_catalogs.rb
octocatalog-diff-1.0.3 lib/octocatalog-diff/cli/options/existing_catalogs.rb
octocatalog-diff-1.0.2 lib/octocatalog-diff/cli/options/existing_catalogs.rb
octocatalog-diff-1.0.1 lib/octocatalog-diff/cli/options/existing_catalogs.rb
octocatalog-diff-1.0.0 lib/octocatalog-diff/cli/options/existing_catalogs.rb