Class: MetaCon::Switch

Inherits:
Object
  • Object
show all
Defined in:
lib/metacon/switch.rb

Class Method Summary collapse

Class Method Details

.handle(cmd, opts) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/metacon/switch.rb', line 3

def self.handle(cmd, opts)
  if opts.nil? or opts.size == 0
    all = $proj.list(cmd)
    current = $proj.current_state[cmd]
    all.sort.each do |avail|
      if avail == current
        $cli.cputs "* |{green #{avail}}"
      else
        puts "  #{avail}"
      end
    end
  else
    res = $proj.switch({cmd=>opts[0]})
    case res
    when :nochange
      $cli.cwarn 'Nothing changed'
    when :switched
      $cli.result "Switched #{cmd} to '#{opts[0]}'"
    when :impossible
      $cli.cfail 'Cannot switch. Probably because submodules need committing.'
    end
    MetaCon::Stat.curr
  end
end