Class: VagrantPlugins::SyncedFolderSSHFS::Command::SSHFS

Inherits:
Object
  • Object
show all
Includes:
Vagrant::Action::Builtin::MixinSyncedFolders
Defined in:
lib/vagrant-sshfs/command.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.synopsisObject



8
9
10
# File 'lib/vagrant-sshfs/command.rb', line 8

def self.synopsis
  "mounts SSHFS shared folder mounts into the remote machine"
end

Instance Method Details

#executeObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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
# File 'lib/vagrant-sshfs/command.rb', line 12

def execute
  options = {:unmount => false} # Default to mounting shares
  opts = OptionParser.new do |o|
    o.banner = "Usage: vagrant sshfs [--mount|--unmount] [vm-name]"
    o.separator ""
    o.separator "Mount or unmount sshfs synced folders into the vagrant box"
    o.separator ""

    o.on("--mount", "Mount folders - the default") do
      options[:unmount] = false
    end
    o.on("--unmount", "Unmount folders") do
      options[:unmount] = true
    end
  end

  # Parse the options and return if we don't have any target.
  argv = parse_options(opts)
  return if !argv

  # Go through each machine and perform the rsync
  error = false
  with_target_vms(argv) do |machine|

    # Is the machine up yet?
    if !machine.communicate.ready?
      machine.ui.error(I18n.t("vagrant.sshfs.errors.communicator_not_ready"))
      error = true
      next
    end

    # Determine the sshfs synced folders for this machine
    folders = synced_folders(machine, cached: false)[:sshfs]
    next if !folders || folders.empty?

    # Mount or Unmount depending on the user's request
    if options[:unmount]
      SyncedFolder.new.disable(machine, folders, {})
    else
      SyncedFolder.new.enable(machine, folders, {})
    end
  end
  return error ? 1 : 0
end