Class: Boxafe::CLI

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

Instance Method Summary collapse

Instance Method Details

#mount(*args) ⇒ Object



29
30
31
32
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
# File 'lib/boxafe/cli.rb', line 29

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 } }

  notifier = Boxafe::Notifier.notifier config.options

  puts
  boxes.each do |box|

    print "Mounting #{box.name}... "
    case box.mount_status
    when :mounted
      notifier.notify "#{box.name} is already mounted" if notifier
      puts Paint['already mounted', :green]
      next
    when :invalid
      notifier.notify "#{box.name} has an invalid mount point (not a directory)", type: :failure if notifier
      puts Paint['invalid mount point (not a directory)', :red]
      next
    end

    box.ensure_mount_point
    box.mount

    puts case box.mount_status
    when :mounted
      notifier.notify "#{box.name} is mounted", type: :success if notifier
      Paint['mounted', :green]
    else
      notifier.notify "#{box.name} could not be mounted", type: :failure if notifier
      Paint['could not be mounted', :red]
    end
  end

  puts
end

#start(options = {}) ⇒ Object



4
5
6
7
8
# File 'lib/boxafe/cli.rb', line 4

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

#status(options = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/boxafe/cli.rb', line 14

def status options = {}

  config = load_config options

  puts
  puts Paint["# Boxafe v#{Boxafe::VERSION}", :bold]

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

  puts
end

#stop(options = {}) ⇒ Object



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

def stop options = {}
  Boxafe::Scheduler.platform_scheduler(options).stop
end

#unmount(*args) ⇒ Object



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

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

    puts case box.mount_status
    when :unmounted
      Paint['unmounted', :green]
    else
      Paint['could not be unmounted', :red]
    end
  end

  puts
end