Class: Boxafe::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/boxafe/cli.rb

Instance Method Summary collapse

Instance Method Details

#mount(*args) ⇒ Object


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/boxafe/cli.rb', line 33

def mount *args

  options = args.last.kind_of?(Hash) ? args.pop : {}
  config = load_config options

  # FIXME: crashes with unknown box names
  boxes = args.empty? ? config.boxes : args.collect{ |arg| config.boxes.find{ |box| box.name == arg } }

  puts
  boxes.each do |box|

    print "Mounting #{box.name}... "
    if box.mounted?
      notify :info, "#{box.name} is already mounted", config.options
      puts Paint['already mounted', :green]
      next
    end

    begin
      box.mount
    rescue Boxafe::OptionError => e
      msg = ":#{e.option} option error - #{e.message}"
      notify :error, "#{box.name} #{msg}", config.options
      puts Paint[msg, :red]
      next
    end

    if box.mounted?
      notify :ok, "#{box.name} is mounted", config.options
      puts Paint['mounted', :green]
    else
      notify :error, "#{box.name} could not be mounted", config.options
      puts Paint['could not be mounted', :red]
    end
  end

  puts
end

#start(options = {}) ⇒ Object


8
9
10
11
12
# File 'lib/boxafe/cli.rb', line 8

def start options = {}
  # TODO: allow to mount only specific boxes
  # TODO: only allow boxes with an extpass
  schedule(options).start
end

#status(options = {}) ⇒ Object


18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/boxafe/cli.rb', line 18

def status options = {}

  config = load_config options

  puts
  puts global_description(config, options[:verbose])

  config.boxes.each do |box|
    puts
    puts box_description(box, options[:verbose])
  end

  puts
end

#stop(options = {}) ⇒ Object


14
15
16
# File 'lib/boxafe/cli.rb', line 14

def stop options = {}
  schedule(options).stop
end

#unmount(*args) ⇒ Object


72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/boxafe/cli.rb', line 72

def unmount *args

  options = args.last.kind_of?(Hash) ? args.pop : {}
  config = load_config options

  boxes = args.empty? ? config.boxes : args.collect{ |arg| config.boxes.find{ |box| box.name == arg } }

  puts
  boxes.each do |box|

    print "Umounting #{box.name}... "
    box.unmount

    if box.mounted?
      puts Paint['could not be unmounted', :red]
    else
      puts Paint['unmounted', :green]
    end
  end

  puts
end