Sha256: 36e8f65050512d16a46a5103d23e1b8ed9416d32e78df3c30b66c2706d6cf87f

Contents?: true

Size: 2 KB

Versions: 2

Compression:

Stored size: 2 KB

Contents

require 'confctl/cli/command'
require 'confctl/cli/swpins/utils'

module ConfCtl::Cli
  class Swpins::Core < Command
    include Swpins::Utils

    def list
      core = ConfCtl::Swpins::Core.get

      rows = []

      core.specs.each do |name, spec|
        next if args[0] && !ConfCtl::Pattern.match(args[0], name)

        rows << {
          sw: spec.name,
          channel: spec.channel,
          type: spec.type,
          pin: spec.status
        }
      end

      OutputFormatter.print(
        rows,
        %i[sw channel type pin],
        layout: :columns
      )
    end

    def set
      require_args!('sw', 'version...', strict: false)

      core = ConfCtl::Swpins::Core.get
      change_set = ConfCtl::Swpins::ChangeSet.new

      core.specs.each_value do |spec|
        if spec.from_channel?
          puts "Skipping #{spec.name} as it comes from channel #{spec.channel}"
        else
          change_set.add(core, spec)
          spec_set_msg(core, spec) { spec.prefetch_set(args[1..]) }
        end
      end

      core.save
      core.pre_evaluate

      return unless opts[:commit]

      change_set.commit(
        type: opts[:downgrade] ? :downgrade : :upgrade,
        changelog: opts[:changelog]
      )
    end

    def update
      require_args!(optional: %w[sw])
      core = ConfCtl::Swpins::Core.get
      change_set = ConfCtl::Swpins::ChangeSet.new

      core.specs.each do |name, spec|
        next if args[0] && !ConfCtl::Pattern.match(args[0], name)

        if spec.from_channel?
          puts "Skipping #{spec.name} as it comes from channel #{spec.channel}"
        elsif spec.can_update?
          change_set.add(core, spec)
          spec_update_msg(core, spec) { spec.prefetch_update }
        else
          puts "#{spec.name} not configured for update"
        end
      end

      core.save
      core.pre_evaluate

      return unless opts[:commit]

      change_set.commit(
        type: opts[:downgrade] ? :downgrade : :upgrade,
        changelog: opts[:changelog]
      )
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
confctl-2.0.0 lib/confctl/cli/swpins/core.rb
confctl-1.0.0 lib/confctl/cli/swpins/core.rb