Module: VagrantPlugins::Unison::UnisonSync
- Included in:
- CommandInteract, CommandOnce, CommandPolling
- Defined in:
- lib/vagrant-unison2/unison_sync.rb
Overview
mixin providing common functionality for our vagrant commands
Instance Method Summary collapse
- #check_conflicting_options! ⇒ Object
- #execute_sync_command(machine) {|shell_command| ... } ⇒ Object
- #options ⇒ Object
- #options_parser ⇒ Object
- #parse_options! ⇒ Object
Instance Method Details
#check_conflicting_options! ⇒ Object
89 90 91 92 93 94 |
# File 'lib/vagrant-unison2/unison_sync.rb', line 89 def enabled = [:prefer_local, :prefer_remote, :force_local, :force_remote].select do |opt| [opt] end raise ArgumentError.new("Conflicting options: #{enabled.inspect}") if enabled.length > 1 end |
#execute_sync_command(machine) {|shell_command| ... } ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/vagrant-unison2/unison_sync.rb', line 7 def execute_sync_command(machine) unison_paths = UnisonPaths.new(@env, machine) guest_path = unison_paths.guest host_path = unison_paths.host @env.ui.info "Unisoning changes from {host}::#{host_path} --> {guest VM}::#{guest_path}" # Create the guest path machine.communicate.sudo("mkdir -p '#{guest_path}'") machine.communicate.sudo("chown #{machine.config.unison.ssh_user} '#{guest_path}'") ssh_command = SshCommand.new(machine) shell_command = ShellCommand.new(machine, unison_paths, ssh_command) shell_command.prefer_local = [:prefer_local] shell_command.prefer_remote = [:prefer_remote] shell_command.force_local = [:force_local] shell_command.force_remote = [:force_remote] yield shell_command end |
#options ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/vagrant-unison2/unison_sync.rb', line 49 def @options ||= { :prefer_local => false, :prefer_remote => false, :force_local => false, :force_remote => false, :verbose => false, } end |
#options_parser ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/vagrant-unison2/unison_sync.rb', line 59 def @option_parser ||= OptionParser.new do |o| o. = "Usage: vagrant #{ARGV[0]} [options]" o.on('--push', 'prefer changes on the local machine.') do |flag| [:prefer_local] = flag end o.on('--pull', 'prefer changes on the remote machine.') do |flag| [:prefer_remote] = flag end o.on('--force-push', 'force-push changes to the remote machine. Dangerous!') do |flag| [:force_local] = flag end o.on('--force-pull', 'force-pull changes from the remote machine. Super dangerous!') do |flag| [:force_remote] = flag end o.on('--verbose', 'Print additional debug information') do |flag| [:verbose] = flag end end end |
#parse_options! ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/vagrant-unison2/unison_sync.rb', line 31 def # parse_options(option_parser) is provided by vagrant, but # documentation is scarse. Best way to view the docs (imo) is to put # a binding.pry in here and then type `? parse_options` @parsed_argv ||= () if [:verbose] @env.ui.info "Options: #{}" end # According to the docs: # > If parse_options returns `nil`, then you should assume that # > help was printed and parsing failed. if @parsed_argv == nil exit 1 end end |