guard-remote-sync 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -1,12 +1,35 @@
1
- guard-remote-sync
2
- ============
1
+ #Guard::RemoteSync [![Build Status](https://secure.travis-ci.org/pmcjury/guard-remote-sync.png)](http://travis-ci.org/pmcjury/guard-remote-sync)
2
+
3
+ ## Install
4
+
5
+ Please be sure to have [Guard](https://github.com/guard/guard) installed before continuing.
6
+
7
+ Please be sure to have the rsync command in your path.
8
+
9
+ It's recommended that you set up a ssh key if you're going to do remote syncing.
10
+ Alterantively your can use a password file as per rsync default option --password-file=FILE, the drawback with this is you might commit your information to the repo, and that ain't no good.
11
+ Lastly, you can just type in your password everytime, but that's too much work. Add a ssh key!
12
+
13
+ Install the gem:
3
14
 
4
- **Usage**
5
15
  ```
6
- bundle exec guard
16
+ $ gem install guard-remote-sync
7
17
  ```
8
18
 
9
- **Example Guardfile**
19
+ Add guard definition to your Guardfile by running this command:
20
+
21
+ ```
22
+ $ guard init rspec
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ Please read [Guard usage doc](https://github.com/guard/guard#readme)
28
+
29
+ ## Guardfile
30
+
31
+ ### Any directory you need to rsync
32
+
10
33
  ```ruby
11
34
  guard 'remote-sync',
12
35
  :source => ".",
@@ -20,3 +43,77 @@ guard 'remote-sync',
20
43
  watch(%r{^.+\.(js|xml|php|class|config)$})
21
44
  end
22
45
  ```
46
+ Please read [Guard doc](https://github.com/guard/guard#readme) for more information about the Guardfile DSL.
47
+
48
+ ## Options
49
+
50
+ ### There are only two required options
51
+
52
+ ```ruby
53
+ guard 'remote-sync', :source => '.', :destination => './tmp' do
54
+ # ...
55
+ end
56
+ ```
57
+
58
+ ### Syncing to a remote machine required additional options
59
+ ```ruby
60
+ guard 'remote-sync',
61
+ :source => "." # the directory to start the remote sync guard in
62
+ :destination => '/export/home/user' # the directory to sync to
63
+ :user => "someone" # the user to user ex: {USER}@somehost.com
64
+ :remote_address => 'company.com' # the remote address ip or url
65
+ do
66
+ # ...
67
+ end
68
+ ```
69
+
70
+ ### Using your own rsync command. This bypasses all validations, etc.
71
+ ```ruby
72
+ guard 'remote-sync', :cli_options => 'rsync -Carv . user@company.com:/export/home/user' do
73
+ # ...
74
+ end
75
+ ```
76
+
77
+ ### List of available options:
78
+
79
+ Most of these options are human readable and correspond to rsync's options. Long options are used wherever
80
+ possible to be more verbose
81
+
82
+ ```ruby
83
+ :source => nil # the source directory to start in
84
+ :destination => nil # the directory to sync to
85
+ :user => nil # the user to use if remote syncing to another machine
86
+ :remote_address => nil # the remote address to the other machine ip|url
87
+ :ssh => false # see rsync options : "$ man rsync"
88
+ :cli_options => nil # used if you want to pass your own rsyn command
89
+ :archive => true # see rsync options : "$ man rsync"
90
+ :recursive => true # see rsync options : "$ man rsync"
91
+ :verbose => true # see rsync options : "$ man rsync"
92
+ :delete => true # see rsync options : "$ man rsync"
93
+ :include => nil # see rsync options : "$ man rsync"
94
+ :include_from => nil # see rsync options : "$ man rsync"
95
+ :exclude => nil # see rsync options : "$ man rsync"
96
+ :exclude_from => ".rsync-filter" # see rsync options : "$ man rsync"
97
+ :progress => true # see rsync options : "$ man rsync"
98
+ :sync_on_start => false # rsycn when the guard starts instead of waiting for a watcher to trigger guard
99
+ :dry_run => false # see rsync options : "$ man rsync"
100
+ :cvs_exclude => true # see rsync options : "$ man rsync"
101
+ :password_file => nil # see rsync options : "$ man rsync"
102
+ :timeout => 10 # see rsync options : "$ man rsync"
103
+ ```
104
+
105
+ Development
106
+ -----------
107
+
108
+ * Source hosted at [GitHub](https://github.com/pmcjury/guard-remote-sync)
109
+ * Report issues/Questions/Feature requests on [GitHub Issues](https://github.com/pmcjury/guard-remote-sync/issues)
110
+
111
+ Testing
112
+ -------
113
+
114
+ Please run `bundle exec rake spec` to test the source
115
+
116
+ Author
117
+ ------
118
+
119
+ [Patrick H. McJury](https://github.com/pmcjury)
@@ -33,7 +33,8 @@ module Guard
33
33
  :sync_on_start => false,
34
34
  :dry_run => false,
35
35
  :cvs_exclude => true,
36
- :password_file => nil
36
+ :password_file => nil,
37
+ :timeout => 10
37
38
  }.merge(options)
38
39
 
39
40
  @source = Source.new(options[:source])
@@ -48,7 +49,11 @@ module Guard
48
49
  throw([:task_has_failed], "Guard::RemoteSync options invalid") unless options_valid?
49
50
  UI.info "Guard::RemoteSync started in source directory '#{File.expand_path @source.directory}'"
50
51
  Notifier.notify("Guard::RemoteSync is running in directory #{File.expand_path @source.directory}", notifier_options)
51
- @command.sync if options[:sync_on_start] && @command.test
52
+ if @command.test
53
+ @command.sync if options[:sync_on_start]
54
+ else
55
+ throw([:task_has_failed], "Guard::RemoteSync rsync failed, please check your configurations, directories, permissions, and maybe even your ssh details ( set up a public key possibly )")
56
+ end
52
57
 
53
58
  end
54
59
 
@@ -4,6 +4,26 @@ module Guard
4
4
 
5
5
  attr_accessor :command, :source, :destination
6
6
 
7
+ CLEAR = "\e[0m"
8
+ # The start of an ANSI bold sequence.
9
+ BOLD = "\e[1m"
10
+ # Set the terminal's foreground ANSI color to black.
11
+ BLACK = "\e[30m"
12
+ # Set the terminal's foreground ANSI color to red.
13
+ RED = "\e[31m"
14
+ # Set the terminal's foreground ANSI color to green.
15
+ GREEN = "\e[32m"
16
+ # Set the terminal's foreground ANSI color to yellow.
17
+ YELLOW = "\e[33m"
18
+ # Set the terminal's foreground ANSI color to blue.
19
+ BLUE = "\e[34m"
20
+ # Set the terminal's foreground ANSI color to magenta.
21
+ MAGENTA = "\e[35m"
22
+ # Set the terminal's foreground ANSI color to cyan.
23
+ CYAN = "\e[36m"
24
+ # Set the terminal's foreground ANSI color to white.
25
+ WHITE = "\e[37m"
26
+
7
27
  def initialize(source, destination, options = {})
8
28
  @options = options
9
29
  @source = source
@@ -13,28 +33,47 @@ module Guard
13
33
 
14
34
  def sync
15
35
  UI.info "Guard::RemoteSync `#{@command}`"
16
- r = `#{@command}`
17
- UI.info "Guard::RemoteSync Status : \n #{r}" if @options[:verbose]
36
+ run_command @command
18
37
  end
19
38
 
20
39
  def test
40
+ $stderr.puts("\r\e[0m")
41
+ $stderr.puts "#{BOLD}Testing rsync with a dry run and stats. Verifying the results...#{CLEAR}"
42
+ opts = @options
21
43
  @options[:dry_run] = true
44
+ @options[:stats] = true
22
45
  test_command = build_command
23
- @options[:dry_run] = false
24
- $stdout.sync = true
25
- `#{test_command}`
26
- $stdout.sync = false
27
- $?.exitstatus
46
+ @options = opts
47
+ result = run_command test_command, {:suppress_output => false}
48
+ $stderr.puts("\r\e[0m")
49
+ result.to_i == 0
28
50
  end
29
51
 
30
52
  private
31
53
 
54
+ def run_command(cmd, opts = {})
55
+ options = {:color => CYAN, :suppress_output => false}.merge(opts)
56
+ $stderr.puts "\r\e[0m" unless options[:suppress_output]
57
+ exit_value = nil
58
+ Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
59
+ stdout.read.split("\n").each do |line|
60
+ $stderr.puts "\t#{options[:color]}#{line}#{CLEAR}" unless options[:suppress_output]
61
+ end
62
+ stderr.read.split("\n").each do |line|
63
+ $stderr.puts "\t#{BOLD}#{RED}ERROR:#{line}#{CLEAR}"
64
+ end
65
+ exit_value = wait_thr.value.to_s.split.last
66
+ end
67
+ $stderr.puts "\t#{BOLD}#{YELLOW}Result Code #{exit_value}#{CLEAR}"
68
+ exit_value
69
+ end
70
+
32
71
  def build_command
33
72
  unless @options[:cli_options].nil?
34
- UI.info "':cli' option was given so ignoring all other options, and outputting as is..."
73
+ UI.debug "Guard::RemoteSync ':cli' option was given so ignoring all other options, and outputting as is..." if @options[:verbose]
35
74
  command = "#{rsync_command} #{@options[:cli_options]}"
36
75
  else
37
- UI.debug "building rsync options from specified options"
76
+ UI.debug "Guard::RemoteSync building rsync options from specified options" if @options[:verbose]
38
77
  @command_options = build_options
39
78
  @remote_options = check_remote_options
40
79
  destination = @remote_options.nil? ? "#{@destination.directory}" : "#{@remote_options}:#{@destination.directory}"
@@ -56,7 +95,7 @@ module Guard
56
95
  value = check_boolean_option(o)
57
96
  opts.concat "#{value} " unless value.nil?
58
97
  end
59
- [:include, :include_from, :exclude, :exclude_from, :password_file].each do |o|
98
+ [:include, :include_from, :exclude, :exclude_from, :password_file, :timeout].each do |o|
60
99
  value = check_nil_option(o)
61
100
  opts.concat "#{value} " unless value.nil?
62
101
  end
@@ -1,5 +1,5 @@
1
1
  module Guard
2
2
  module RemoteSyncVersion
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: guard-remote-sync
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: