Class: ConfCtl::Cli::Swpins::Channel

Inherits:
Command
  • Object
show all
Includes:
Utils
Defined in:
lib/confctl/cli/swpins/channel.rb

Instance Attribute Summary

Attributes inherited from Command

#args, #gopts, #opts

Instance Method Summary collapse

Methods included from Utils

#channel_list, #cluster_name_list, #each_channel, #each_channel_spec, #each_cluster_name, #each_cluster_name_spec, #spec_set_msg, #spec_update_msg

Methods inherited from Command

#ask_action, #ask_confirmation, #ask_confirmation!, #initialize, #require_args!, run, #run_method, #use_color?, #use_pager?

Constructor Details

This class inherits a constructor from ConfCtl::Cli::Command

Instance Method Details

#listObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/confctl/cli/swpins/channel.rb', line 8

def list
  rows = []

  each_channel_spec(args[0] || '*', args[1] || '*') do |chan, spec|
    rows << {
      channel: chan.name,
      sw: spec.name,
      type: spec.type,
      pin: spec.status
    }
  end

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

#setObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/confctl/cli/swpins/channel.rb', line 27

def set
  require_args!('channel-pattern', 'sw-pattern', 'version...', strict: false)
  channels = []
  change_set = ConfCtl::Swpins::ChangeSet.new

  each_channel_spec(args[0], args[1]) do |chan, spec|
    change_set.add(chan, spec)
    spec_set_msg(chan, spec) { spec.prefetch_set(args[2..]) }
    channels << chan unless channels.include?(chan)
  end

  channels.each(&:save)

  return unless opts[:commit]

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

#updateObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/confctl/cli/swpins/channel.rb', line 48

def update
  require_args!(optional: %w[channel-pattern sw-pattern])
  channels = []
  change_set = ConfCtl::Swpins::ChangeSet.new

  each_channel_spec(args[0] || '*', args[1] || '*') do |chan, spec|
    if spec.can_update?
      change_set.add(chan, spec)
      spec_update_msg(chan, spec) { spec.prefetch_update }
      channels << chan unless channels.include?(chan)
    else
      puts "#{spec.name} not configured for update"
    end
  end

  channels.each(&:save)

  return unless opts[:commit]

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