yggdrasil 0.0.4 → 0.0.5

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/lib/yggdrasil.rb CHANGED
@@ -71,13 +71,14 @@ class Yggdrasil
71
71
  protected
72
72
  # @param [String] msg
73
73
  def Yggdrasil.error(msg)
74
- puts "#{CMD} error: #{msg}"
75
- puts
74
+ $stderr.puts "#{CMD} error: #{msg}"
75
+ $stderr.puts
76
76
  exit 1
77
77
  end
78
78
 
79
- def Yggdrasil.parse_options(args, valid_params)
80
- options = Hash.new
79
+ def parse_options(args, valid_params)
80
+ valid_params['--debug'] = :debug? # common
81
+ @options ||= Hash.new
81
82
  pos = 0
82
83
  while args.size > pos
83
84
  if valid_params.has_key?(args[pos])
@@ -85,35 +86,37 @@ class Yggdrasil
85
86
  option_key = valid_params[option_note]
86
87
  args = args[0...pos]+args[pos+1..-1]
87
88
  if option_key.to_s[-1] == '?'
88
- options[option_key] = true
89
+ @options[option_key] = true
89
90
  else
90
91
  error "Not enough arguments provided: #{option_note}" unless args.size > pos
91
92
  option_value = args[pos].dup
92
93
  args = args[0...pos]+args[pos+1..-1]
93
- options[option_key] = option_value
94
+ @options[option_key] = option_value
94
95
  end
95
96
  next
96
97
  end
97
98
  pos += 1
98
99
  end
99
- return args, options
100
+ args
100
101
  end
101
102
 
102
- def Yggdrasil.input_user_pass(options)
103
- until options.has_key?(:username) do
103
+ def input_user_pass
104
+ until @options.has_key?(:username) do
105
+ error "Can't get username or password" if @options.has_key?(:non_interactive?)
104
106
  print "Input svn username: "
105
107
  input = $stdin.gets
106
- options[:username] = input.chomp
108
+ @options[:username] = input.chomp
107
109
  end
108
- until options.has_key?(:password) do
110
+ until @options.has_key?(:password) do
111
+ error "Can't get username or password" if @options.has_key?(:non_interactive?)
109
112
  print "Input svn password: "
110
113
  #input = `sh -c 'read -s hoge;echo $hoge'`
111
114
  system3 'stty -echo', false
112
115
  input = $stdin.gets
113
116
  system3 'stty echo', false
114
- options[:password] = input.chomp
117
+ puts
118
+ @options[:password] = input.chomp
115
119
  end
116
- return options
117
120
  end
118
121
 
119
122
  def initialize(exist_config = true)
@@ -127,6 +130,7 @@ class Yggdrasil
127
130
  ENV["PATH"] = configs[:path]
128
131
  @svn = configs[:svn]
129
132
  @repo = configs[:repo]
133
+ @anon_access = (configs[:anon_access] == 'read')
130
134
  end
131
135
 
132
136
  # load config value from config file
@@ -139,28 +143,30 @@ class Yggdrasil
139
143
  l += 1
140
144
  next if /^\s*#.*$/ =~ line # comment line
141
145
  if /^\s*(\S+)\s*=\s*(\S+).*$/ =~ line
142
- configs[$1.to_sym] = $2
146
+ key, val = $1, $2
147
+ key.gsub!(/-/, '_')
148
+ configs[key.to_sym] = val
143
149
  else
144
- puts "#{CMD} error: syntax error. :#@config_file(#{l})"
145
- exit 1
150
+ error "syntax error. :#@config_file(#{l})"
146
151
  end
147
152
  end
148
153
  end
149
154
  rescue
150
- puts "#{CMD} error: can not open config file: #@config_file"
151
- exit 1
155
+ error "can not open config file: #@config_file"
152
156
  end
153
157
  configs
154
158
  end
155
159
 
156
- def sync_mirror(options)
160
+ def sync_mirror
157
161
  updates = Array.new
158
162
  FileUtils.cd @mirror_dir do
159
- out = system3("#@svn ls #@repo -R --no-auth-cache --non-interactive" +
160
- " --username '#{options[:username]}' --password '#{options[:password]}'")
163
+ cmd = "#@svn ls #@repo -R --no-auth-cache --non-interactive"
164
+ cmd += " --username '#{@options[:username]}' --password '#{@options[:password]}'" unless @anon_access
165
+ out = system3(cmd)
161
166
  files = out.split(/\n/)
162
- out = system3("#@svn status -q --no-auth-cache --non-interactive" +
163
- " --username '#{options[:username]}' --password '#{options[:password]}'")
167
+ cmd = "#@svn status -q --no-auth-cache --non-interactive"
168
+ cmd += " --username '#{@options[:username]}' --password '#{@options[:password]}'" unless @anon_access
169
+ out = system3(cmd)
164
170
  out.split(/\n/).each do |line|
165
171
  files << $1 if /^.*\s(\S+)\s*$/ =~ line
166
172
  end
@@ -172,13 +178,16 @@ class Yggdrasil
172
178
  " --no-auth-cache --non-interactive"
173
179
  elsif File.file?("/#{file}")
174
180
  if !File.exist?("#@mirror_dir/#{file}")
175
- system3 "#@svn revert #{file}"
181
+ cmd = "#@svn revert #{file}"
182
+ cmd += " --username '#{@options[:username]}' --password '#{@options[:password]}'" unless @anon_access
183
+ system3 cmd
176
184
  end
177
185
  FileUtils.copy_file "/#{file}", "#@mirror_dir/#{file}"
178
186
  end
179
187
  end
180
- out = system3("#@svn status -q --no-auth-cache --non-interactive" +
181
- " --username '#{options[:username]}' --password '#{options[:password]}'")
188
+ cmd = "#@svn status -q --no-auth-cache --non-interactive"
189
+ cmd += " --username '#{@options[:username]}' --password '#{@options[:password]}'" unless @anon_access
190
+ out = system3(cmd)
182
191
  out.split(/\n/).each do |line|
183
192
  updates << $1 if /^.*\s(\S+)\s*$/ =~ line
184
193
  end
@@ -219,8 +228,8 @@ class Yggdrasil
219
228
  matched_updates.sort.uniq
220
229
  end
221
230
 
222
- def confirm_updates(updates, options)
223
- until options.has_key?(:non_interactive?)
231
+ def confirm_updates(updates)
232
+ until @options.has_key?(:non_interactive?)
224
233
  puts
225
234
  (0...updates.size).each do |i|
226
235
  puts "#{i}:#{updates[i]}"
data/lib/yggdrasil/add.rb CHANGED
@@ -3,8 +3,7 @@ class Yggdrasil
3
3
  # @param [Array] args
4
4
  def add(args)
5
5
  while (arg = args.shift)
6
- file_path = `readlink -f #{arg}`.chomp
7
- exit $?.exitstatus unless $?.success?
6
+ file_path = system3("readlink -f #{arg}").chomp
8
7
  unless File.exist?(file_path)
9
8
  puts "no such file: #{file_path}"
10
9
  next
@@ -2,18 +2,17 @@ class Yggdrasil
2
2
 
3
3
  # @param [Array] args
4
4
  def cleanup(args)
5
- args, options = parse_options(args, {'--username'=>:username, '--password'=>:password})
5
+ args = parse_options(args, {'--username'=>:username, '--password'=>:password})
6
6
  if args.size != 0
7
7
  error "invalid arguments: #{args.join(',')}"
8
8
  end
9
9
 
10
- options = input_user_pass(options)
10
+ input_user_pass unless @anon_access
11
11
 
12
12
  system3 "rm -rf #@mirror_dir"
13
13
 
14
- system3 "#@svn checkout"\
15
- " --no-auth-cache --non-interactive"\
16
- " --username '#{options[:username]}' --password '#{options[:password]}'"\
17
- " #@repo #@mirror_dir"
14
+ cmd = "#@svn checkout --no-auth-cache --non-interactive #@repo #@mirror_dir"
15
+ cmd += " --username '#{@options[:username]}' --password '#{@options[:password]}'" unless @anon_access
16
+ system3 cmd
18
17
  end
19
18
  end
@@ -2,19 +2,19 @@ class Yggdrasil
2
2
 
3
3
  # @param [Array] args
4
4
  def commit(args)
5
- target_paths, options = parse_options(args,
5
+ target_paths = parse_options(args,
6
6
  {'--username'=>:username, '--password'=>:password,
7
7
  '-m'=>:message, '--message'=>:message, '--non-interactive'=>:non_interactive?})
8
- options = input_user_pass(options)
8
+ input_user_pass
9
9
 
10
- updates = sync_mirror(options)
10
+ updates = sync_mirror
11
11
  matched_updates = select_updates(updates, target_paths)
12
12
  if matched_updates.size == 0
13
13
  puts "\nno files."
14
14
  return
15
15
  end
16
16
 
17
- confirmed_updates = confirm_updates(matched_updates,options) do |relative_path|
17
+ confirmed_updates = confirm_updates(matched_updates) do |relative_path|
18
18
  FileUtils.cd @mirror_dir do
19
19
  puts system3("#@svn diff --no-auth-cache --non-interactive #{relative_path}")
20
20
  end
@@ -22,16 +22,16 @@ class Yggdrasil
22
22
  return unless confirmed_updates
23
23
  return if confirmed_updates.size == 0
24
24
 
25
- until options.has_key?(:message) do
25
+ until @options.has_key?(:message) do
26
26
  print "Input log message: "
27
27
  input = $stdin.gets
28
- options[:message] = input.chomp
28
+ @options[:message] = input.chomp
29
29
  end
30
30
 
31
31
  FileUtils.cd @mirror_dir do
32
- puts system3 "#@svn commit -m '#{options[:message]}'"\
32
+ puts system3 "#@svn commit -m '#{@options[:message]}'"\
33
33
  " --no-auth-cache --non-interactive"\
34
- " --username '#{options[:username]}' --password '#{options[:password]}'"\
34
+ " --username '#{@options[:username]}' --password '#{@options[:password]}'"\
35
35
  " #{confirmed_updates.join(' ')}"
36
36
  end
37
37
  end
@@ -2,11 +2,12 @@ class Yggdrasil
2
2
 
3
3
  # @param [Array] args
4
4
  def diff(args)
5
- args, options = parse_options(args,
5
+ args = parse_options(args,
6
6
  {'--username'=>:username, '--password'=>:password, '-r'=>:revision, '--revision'=>:revision})
7
- options = input_user_pass(options)
8
7
 
9
- sync_mirror options
8
+ input_user_pass unless @anon_access
9
+
10
+ sync_mirror
10
11
 
11
12
  paths = Array.new
12
13
  if args.size == 0
@@ -19,8 +20,8 @@ class Yggdrasil
19
20
  end
20
21
 
21
22
  cmd_arg = "#@svn diff --no-auth-cache --non-interactive"
22
- cmd_arg += " --username #{options[:username]} --password #{options[:password]}"
23
- cmd_arg += " -r #{options[:revision]}" if options.has_key?(:revision)
23
+ cmd_arg += " --username #{@options[:username]} --password #{@options[:password]}" unless @anon_access
24
+ cmd_arg += " -r #{@options[:revision]}" if @options.has_key?(:revision)
24
25
  cmd_arg += ' '+paths.join(' ')
25
26
  FileUtils.cd @mirror_dir do
26
27
  puts system3(cmd_arg)
@@ -111,9 +111,7 @@ Valid options:
111
111
  'BASE' base rev of item's working copy
112
112
  'COMMITTED' last commit at or before BASE
113
113
  'PREV' revision just before COMMITTED
114
- -R [--recursive] : descend recursively, same as --depth=infinity
115
- --depth ARG : limit operation by depth ARG ('empty', 'files',
116
- 'immediates', or 'infinity')
114
+ -R [--recursive] : descend recursively
117
115
 
118
116
  EOS
119
117
  when 'log'
@@ -142,8 +140,6 @@ usage: #{CMD} status [OPTIONS...] [PATH...]
142
140
  Valid options:
143
141
  --username ARG : specify a username ARG
144
142
  --password ARG : specify a password ARG
145
- --depth ARG : limit operation by depth ARG ('empty', 'files',
146
- 'immediates', or 'infinity')
147
143
 
148
144
  EOS
149
145
  when 'revert'
@@ -3,9 +3,9 @@ class Yggdrasil
3
3
  # @param [Array] args
4
4
  def init(args)
5
5
 
6
- args, options = parse_options(args,
6
+ args = parse_options(args,
7
7
  {'--username'=>:username, '--password'=>:password,
8
- '--repo'=>:repo, '--parents'=>:parents?, '--debug'=>:debug?})
8
+ '--repo'=>:repo, '--parents'=>:parents?, '--non-interactive'=>:non_interactive?})
9
9
  if args.size != 0
10
10
  error "invalid arguments: #{args.join(',')}"
11
11
  end
@@ -14,18 +14,12 @@ class Yggdrasil
14
14
  svn = out.chomp
15
15
 
16
16
  out = system3 'svn --version'
17
- unless /version (\d+\.\d+\.\d+) / =~ out
18
- puts "#{CMD} error: can not find version string: svn --version"
19
- exit 1
20
- end
17
+ error "can not find version string: svn --version" unless /version (\d+\.\d+\.\d+) / =~ out
21
18
  svn_version=$1
22
19
 
23
- if File.exist?(@config_file)
24
- puts "#{CMD} error: already exist config file: #@config_file"
25
- exit 1
26
- end
20
+ error "already exist config file: #@config_file" if File.exist?(@config_file)
27
21
 
28
- until options.has_key?(:repo) do
22
+ until @options.has_key?(:repo) do
29
23
  print "Input svn repo URL: "
30
24
  input = $stdin.gets
31
25
 
@@ -33,27 +27,32 @@ class Yggdrasil
33
27
  puts "ERROR: Invalid URL."
34
28
  redo
35
29
  end
36
- options[:repo] = input
30
+ @options[:repo] = input
37
31
  end
38
- options[:repo].chomp!
39
- options[:repo].chomp!('/')
40
-
41
- options = input_user_pass(options)
32
+ @options[:repo].chomp!
33
+ @options[:repo].chomp!('/')
42
34
 
43
35
  puts "SVN access test..."
44
- url_parts = options[:repo].split('/')
36
+ url_parts = @options[:repo].split('/')
45
37
  url_parts_num = url_parts.size
38
+ anon_access = true
46
39
  loop do
47
- puts "url_parts_num=#{url_parts_num}" if options[:debug?]
48
40
  if url_parts_num < 3
49
- puts "SVN error: can not access to '#{options[:repo]}'."
50
- exit 1
41
+ if anon_access
42
+ anon_access = false
43
+ url_parts_num = url_parts.size
44
+ input_user_pass
45
+ else
46
+ error "can not access to '#{@options[:repo]}'."
47
+ end
51
48
  end
49
+ puts "url_parts_num=#{url_parts_num}" if @options[:debug?]
50
+
52
51
  url = url_parts[0...url_parts_num].join('/')
53
- puts "try url=#{url}" if options[:debug?]
54
- ret = system3("#{svn} ls --no-auth-cache --non-interactive" +
55
- " --username '#{options[:username]}' --password '#{options[:password]}'" +
56
- " #{url}", false)
52
+ puts "try url=#{url}" if @options[:debug?]
53
+ cmd = "#{svn} ls --no-auth-cache --non-interactive #{url}"
54
+ cmd += " --username '#{@options[:username]}' --password '#{@options[:password]}'" unless anon_access
55
+ ret = system3(cmd, false)
57
56
  unless ret.nil?
58
57
  puts "SVN access OK: #{url}"
59
58
  break
@@ -65,18 +64,21 @@ class Yggdrasil
65
64
  Dir.mkdir @config_dir, 0755 unless File.exist?(@config_dir)
66
65
 
67
66
  if url_parts_num != url_parts.size
68
- until options[:parents?]
69
- puts "not exist directory(s): #{url_parts[url_parts_num...url_parts.size].join('/')}"
67
+ until @options[:parents?]
68
+ msg = "not exist directory(s): #{url_parts[url_parts_num...url_parts.size].join('/')}"
69
+ error msg if @options[:non_interactive?]
70
+ puts msg
70
71
  print "make directory(s)? [Yn]: "
71
72
  input = $stdin.gets
72
- exit 1 if input.nil?
73
+ error "can not gets $stdin" if input.nil?
73
74
  input.chomp!
74
75
  return if input == 'n'
75
76
  break if input == 'Y'
76
77
  end
78
+ input_user_pass
77
79
  `rm -rf #@mirror_dir`
78
80
  system3 "#{svn} checkout --no-auth-cache --non-interactive" +
79
- " --username '#{options[:username]}' --password '#{options[:password]}'" +
81
+ " --username '#{@options[:username]}' --password '#{@options[:password]}'" +
80
82
  " #{url_parts[0...url_parts_num].join('/')} #@mirror_dir"
81
83
  add_paths = Array.new
82
84
  path = @mirror_dir
@@ -88,7 +90,7 @@ class Yggdrasil
88
90
  url_parts_num += 1
89
91
  end
90
92
  system3 "#{svn} commit -m 'yggdrasil init' --no-auth-cache --non-interactive" +
91
- " --username '#{options[:username]}' --password '#{options[:password]}'" +
93
+ " --username '#{@options[:username]}' --password '#{@options[:password]}'" +
92
94
  ' ' + add_paths.join(' ')
93
95
  system3 "rm -rf #@mirror_dir"
94
96
  end
@@ -97,13 +99,13 @@ class Yggdrasil
97
99
  f.write "path=#{ENV['PATH']}\n"\
98
100
  "svn=#{svn}\n"\
99
101
  "svn_version=#{svn_version}\n"\
100
- "repo=#{options[:repo]}\n"
101
- end
102
+ "repo=#{@options[:repo]}\n"\
103
+ "anon-access=#{anon_access ? 'read' : 'none'}\n"
104
+ end
102
105
 
103
106
  `rm -rf #@mirror_dir`
104
- system3 "#{svn} checkout"\
105
- " --no-auth-cache --non-interactive"\
106
- " --username '#{options[:username]}' --password '#{options[:password]}'"\
107
- " #{options[:repo]} #@mirror_dir"
107
+ cmd = "#{svn} checkout --no-auth-cache --non-interactive #{@options[:repo]} #@mirror_dir"
108
+ cmd += " --username '#{@options[:username]}' --password '#{@options[:password]}'" unless anon_access
109
+ system3 cmd
108
110
  end
109
111
  end
@@ -2,14 +2,14 @@ class Yggdrasil
2
2
 
3
3
  # @param [Array] args
4
4
  def list(args)
5
- args, options = parse_options(args,
5
+ args = parse_options(args,
6
6
  {'--username'=>:username, '--password'=>:password,
7
7
  '-r'=>:revision, '--revision'=>:revision,
8
- '-R'=>:recursive?, '--recursive'=>:recursive?,
9
- '--depth'=>:depth})
10
- options = input_user_pass(options)
8
+ '-R'=>:recursive?, '--recursive'=>:recursive?})
11
9
 
12
- sync_mirror options
10
+ input_user_pass unless @anon_access
11
+
12
+ sync_mirror
13
13
 
14
14
  repos = Array.new
15
15
  if args.size == 0
@@ -22,10 +22,9 @@ class Yggdrasil
22
22
  end
23
23
 
24
24
  cmd_arg = "#@svn list --no-auth-cache --non-interactive"
25
- cmd_arg += " --username #{options[:username]} --password #{options[:password]}"
26
- cmd_arg += " -r #{options[:revision]}" if options.has_key?(:revision)
27
- cmd_arg += " -R" if options.has_key?(:recursive?)
28
- cmd_arg += " --depth #{options[:depth]}" if options.has_key?(:depth)
25
+ cmd_arg += " --username #{@options[:username]} --password #{@options[:password]}" unless @anon_access
26
+ cmd_arg += " -r #{@options[:revision]}" if @options.has_key?(:revision)
27
+ cmd_arg += " -R" if @options.has_key?(:recursive?)
29
28
  cmd_arg += ' ' + repos.join(' ')
30
29
  FileUtils.cd @mirror_dir do
31
30
  puts system3(cmd_arg)
data/lib/yggdrasil/log.rb CHANGED
@@ -2,10 +2,10 @@ class Yggdrasil
2
2
 
3
3
  # @param [Array] args
4
4
  def log(args)
5
- args, options = parse_options(args,
6
- {'--username'=>:username, '--password'=>:password,
7
- '-r'=>:revision, '--revision'=>:revision})
8
- options = input_user_pass(options)
5
+ args = parse_options(args,
6
+ {'--username'=>:username, '--password'=>:password,
7
+ '-r'=>:revision, '--revision'=>:revision})
8
+ input_user_pass unless @anon_access
9
9
 
10
10
  if args.size == 0
11
11
  dir = @mirror_dir + @current_dir
@@ -22,9 +22,9 @@ class Yggdrasil
22
22
  end
23
23
 
24
24
  cmd_arg = "#@svn log --verbose --no-auth-cache --non-interactive"
25
- cmd_arg += " --username #{options[:username]} --password #{options[:password]}"
26
- if options.has_key?(:revision)
27
- cmd_arg += " -r #{options[:revision]}"
25
+ cmd_arg += " --username #{@options[:username]} --password #{@options[:password]}" unless @anon_access
26
+ if @options.has_key?(:revision)
27
+ cmd_arg += " -r #{@options[:revision]}"
28
28
  else
29
29
  cmd_arg += " -r HEAD:1"
30
30
  end
@@ -2,21 +2,23 @@ class Yggdrasil
2
2
 
3
3
  # @param [Array] args
4
4
  def revert(args)
5
- target_paths, options = parse_options(args,
6
- {'--username'=>:username, '--password'=>:password,
7
- '--non-interactive'=>:non_interactive?})
8
- options = input_user_pass(options)
5
+ target_paths = parse_options(args,
6
+ {'--username'=>:username, '--password'=>:password,
7
+ '--non-interactive'=>:non_interactive?})
8
+ input_user_pass unless @anon_access
9
9
 
10
- updates = sync_mirror(options)
10
+ updates = sync_mirror
11
11
  matched_updates = select_updates(updates, target_paths)
12
12
  if matched_updates.size == 0
13
13
  puts "\nno files."
14
14
  return
15
15
  end
16
16
 
17
- confirmed_updates = confirm_updates(matched_updates,options) do |relative_path|
17
+ confirmed_updates = confirm_updates(matched_updates) do |relative_path|
18
18
  FileUtils.cd @mirror_dir do
19
- puts system3("#@svn diff --no-auth-cache --non-interactive #{relative_path}")
19
+ cmd = "#@svn diff --no-auth-cache --non-interactive #{relative_path}"
20
+ cmd += " --username '#{@options[:username]}' --password '#{@options[:password]}'" unless @anon_access
21
+ puts system3(cmd)
20
22
  end
21
23
  end
22
24
 
@@ -24,11 +26,15 @@ class Yggdrasil
24
26
  return if confirmed_updates.size == 0
25
27
 
26
28
  FileUtils.cd @mirror_dir do
27
- system3 "#@svn revert #{confirmed_updates.reverse.join(' ')}"
29
+ cmd = "#@svn revert #{confirmed_updates.reverse.join(' ')}"
30
+ cmd += " --username '#{@options[:username]}' --password '#{@options[:password]}'" unless @anon_access
31
+ system3 cmd
28
32
 
29
33
  # make ls hash
30
- out = system3("#@svn ls -R #@repo --no-auth-cache --non-interactive"\
31
- " --username '#{options[:username]}' --password '#{options[:password]}'")
34
+ cmd = "#@svn ls -R #@repo --no-auth-cache --non-interactive"
35
+ cmd += " --username '#{@options[:username]}' --password '#{@options[:password]}'" unless @anon_access
36
+ out = system3(cmd)
37
+
32
38
  ls_hash = Hash.new
33
39
  out.split(/\n/).each {|relative| ls_hash[relative]=true}
34
40
 
@@ -2,12 +2,11 @@ class Yggdrasil
2
2
 
3
3
  # @param [Array] args
4
4
  def status(args)
5
- args, options = parse_options(args,
6
- {'--username'=>:username, '--password'=>:password,
7
- '--depth'=>:depth})
8
- options = input_user_pass(options)
5
+ args = parse_options(args,
6
+ {'--username'=>:username, '--password'=>:password})
7
+ input_user_pass unless @anon_access
9
8
 
10
- sync_mirror options
9
+ sync_mirror
11
10
 
12
11
  paths = String.new
13
12
  if args.size == 0
@@ -20,8 +19,7 @@ class Yggdrasil
20
19
  end
21
20
 
22
21
  cmd_arg = "#@svn status#{paths} -qu --no-auth-cache --non-interactive"
23
- cmd_arg += " --username #{options[:username]} --password #{options[:password]}"
24
- cmd_arg += " --depth #{options[:depth]}" if options.has_key?(:depth)
22
+ cmd_arg += " --username #{@options[:username]} --password #{@options[:password]}" unless @anon_access
25
23
  FileUtils.cd @mirror_dir do
26
24
  out = system3(cmd_arg)
27
25
  print out.gsub(/^Status against revision:.*\n/, '')
@@ -2,17 +2,18 @@ class Yggdrasil
2
2
 
3
3
  # @param [Array] args
4
4
  def update(args)
5
- target_paths, options = parse_options(args,
6
- {'--username'=>:username, '--password'=>:password,
7
- '-r'=>:revision, '--revision'=>:revision,
8
- '--non-interactive'=>:non_interactive?})
9
- options = input_user_pass(options)
10
- sync_mirror options
5
+ target_paths = parse_options(args,
6
+ {'--username'=>:username, '--password'=>:password,
7
+ '-r'=>:revision, '--revision'=>:revision,
8
+ '--non-interactive'=>:non_interactive?})
9
+ input_user_pass unless @anon_access
10
+ sync_mirror
11
11
 
12
12
  updates = Array.new
13
13
  FileUtils.cd @mirror_dir do
14
- out = system3("#@svn status -qu --no-auth-cache --non-interactive" +
15
- " --username '#{options[:username]}' --password '#{options[:password]}'")
14
+ cmd = "#@svn status -qu --no-auth-cache --non-interactive"
15
+ cmd += " --username '#{@options[:username]}' --password '#{@options[:password]}'" unless @anon_access
16
+ out = system3(cmd)
16
17
  out.split(/\n/).each do |line|
17
18
  updates << $1 if /^.*\*.*\s(\S+)\s*$/ =~ line
18
19
  end
@@ -24,13 +25,13 @@ class Yggdrasil
24
25
  return
25
26
  end
26
27
 
27
- confirmed_updates = confirm_updates(matched_updates,options) do |relative_path|
28
+ confirmed_updates = confirm_updates(matched_updates) do |relative_path|
28
29
  FileUtils.cd @mirror_dir do
29
30
  cmd = "#@svn diff"
30
31
  cmd += " --no-auth-cache --non-interactive"
31
- cmd += " --username #{options[:username]} --password #{options[:password]}"
32
- if options.has_key?(:revision)
33
- cmd += " --old=#{relative_path} --new=#{relative_path}@#{options[:revision]}"
32
+ cmd += " --username #{@options[:username]} --password #{@options[:password]}" unless @anon_access
33
+ if @options.has_key?(:revision)
34
+ cmd += " --old=#{relative_path} --new=#{relative_path}@#{@options[:revision]}"
34
35
  else
35
36
  cmd += " --old=#{relative_path} --new=#{relative_path}@HEAD"
36
37
  end
@@ -43,9 +44,9 @@ class Yggdrasil
43
44
  return if confirmed_updates == 0 # no files to update
44
45
 
45
46
  cmd_arg = "#@svn update --no-auth-cache --non-interactive"
46
- cmd_arg += " --username #{options[:username]} --password #{options[:password]}"
47
- if options.has_key?(:revision)
48
- cmd_arg += " -r #{options[:revision]}"
47
+ cmd_arg += " --username #{@options[:username]} --password #{@options[:password]}" unless @anon_access
48
+ if @options.has_key?(:revision)
49
+ cmd_arg += " -r #{@options[:revision]}"
49
50
  else
50
51
  cmd_arg += " -r HEAD"
51
52
  end
@@ -1,5 +1,5 @@
1
1
  class Yggdrasil
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  CMD = File::basename($0)
4
4
 
5
5
  def Yggdrasil.version
data/spec/add_spec.rb CHANGED
@@ -9,10 +9,10 @@ describe Yggdrasil, "add" do
9
9
 
10
10
  it 'should warn: add non-exist files' do
11
11
  puts '---- should warn: add non-exist files'
12
- out = catch_out_err{Yggdrasil.command %w{add hoge}}
12
+ out = catch_out{Yggdrasil.command %w{add hoge}}
13
13
  out.should == "no such file: #{`readlink -f hoge`}"
14
14
 
15
- out = catch_out_err{Yggdrasil.command %w{add /etc/hoge}}
15
+ out = catch_out{Yggdrasil.command %w{add /etc/hoge}}
16
16
  out.should == "no such file: /etc/hoge\n"
17
17
  end
18
18
 
data/spec/diff_spec.rb CHANGED
@@ -13,7 +13,7 @@ describe Yggdrasil, "diff" do
13
13
 
14
14
  it 'should success diff (absolute/relative path)' do
15
15
  puts "---- should success diff (absolute/relative path)"
16
- out = catch_out_err do
16
+ out = catch_out do
17
17
  FileUtils.cd "/tmp/yggdrasil-test" do
18
18
  Yggdrasil.command(%w{diff /tmp/yggdrasil-test/A B --username hoge --password foo})
19
19
  end
@@ -40,7 +40,7 @@ EOS
40
40
 
41
41
  it 'should success (no path)' do
42
42
  puts "---- should success (no path)"
43
- out = catch_out_err do
43
+ out = catch_out do
44
44
  FileUtils.cd "/tmp/yggdrasil-test" do
45
45
  Yggdrasil.command %w{diff --username hoge --password foo}
46
46
  end
@@ -67,7 +67,7 @@ EOS
67
67
 
68
68
  it 'should success (-r)' do
69
69
  puts "---- should success (-r)"
70
- out = catch_out_err do
70
+ out = catch_out do
71
71
  FileUtils.cd "/tmp/yggdrasil-test" do
72
72
  Yggdrasil.command %w{diff -r 2:3 A --username hoge --password foo}
73
73
  end
@@ -85,7 +85,7 @@ EOS
85
85
 
86
86
  it 'should success (--revision)' do
87
87
  puts "---- should success (--revision)"
88
- out = catch_out_err do
88
+ out = catch_out do
89
89
  FileUtils.cd "/tmp/yggdrasil-test" do
90
90
  Yggdrasil.command %w{diff --revision 3 A --username hoge --password foo}
91
91
  end
@@ -106,16 +106,14 @@ EOS
106
106
  puts "---- should error: diff with incorrect option"
107
107
  cmd = %w{diff --hoge --username hoge --password foo}
108
108
 
109
- tmp_err = $stderr
110
- $stderr = StringIO.new
111
- FileUtils.cd "/" do
112
- lambda{Yggdrasil.command cmd}.should raise_error(SystemExit)
109
+ err = catch_err do
110
+ FileUtils.cd "/" do
111
+ lambda{Yggdrasil.command cmd}.should raise_error(SystemExit)
112
+ end
113
113
  end
114
- out = $stderr.string
115
- $stderr = tmp_err
116
- out.sub!(%r{/\S*svn}, 'svn')
117
- out.should == <<"EOS"
118
- rspec error: command failure: svn diff --no-auth-cache --non-interactive --username hoge --password foo --hoge
114
+ err.sub!(%r{/\S*svn}, 'svn')
115
+ err.should == <<"EOS"
116
+ #{File.basename($0)} error: command failure: svn diff --no-auth-cache --non-interactive --username hoge --password foo --hoge
119
117
  command output:
120
118
  svn: invalid option: --hoge
121
119
  Type 'svn help' for usage.
data/spec/help_spec.rb CHANGED
@@ -29,34 +29,34 @@ EOS
29
29
 
30
30
  it 'should show subcommands on no subcommands' do
31
31
  puts '---- should show subcommands on no subcommands'
32
- out = catch_out_err{Yggdrasil.command []}
32
+ out = catch_out{Yggdrasil.command []}
33
33
  out.should == show_subcommands
34
34
  end
35
35
 
36
36
  it 'should show subcommands on "help"' do
37
37
  puts '---- should show subcommands on "help"'
38
- out = catch_out_err{Yggdrasil.command %w{help}}
38
+ out = catch_out{Yggdrasil.command %w{help}}
39
39
  out.should == show_subcommands
40
40
  end
41
41
 
42
42
  it 'should show subcommands on "h"' do
43
43
  puts '---- should show subcommands on "h"'
44
- out = catch_out_err{Yggdrasil.command %w{h}}
44
+ out = catch_out{Yggdrasil.command %w{h}}
45
45
  out.should == show_subcommands
46
46
  end
47
47
 
48
48
  it 'should show subcommands on "?"' do
49
49
  puts '---- should show subcommands on "?"'
50
- out = catch_out_err{Yggdrasil.command %w{?}}
50
+ out = catch_out{Yggdrasil.command %w{?}}
51
51
  out.should == show_subcommands
52
52
  end
53
53
 
54
54
  it 'should be unknown subcommand on "hoge"' do
55
55
  puts '---- should be unknown subcommand on "hoge"'
56
- out = catch_out_err do
56
+ err = catch_err do
57
57
  lambda{Yggdrasil.command(%w{hoge})}.should raise_error(SystemExit)
58
58
  end
59
- out.should == "#{File.basename($0)} error: Unknown subcommand: 'hoge'\n\n"
59
+ err.should == "#{File.basename($0)} error: Unknown subcommand: 'hoge'\n\n"
60
60
  end
61
61
 
62
62
  help_help = <<"EOS"
@@ -67,21 +67,21 @@ EOS
67
67
 
68
68
  it 'should show help_help' do
69
69
  puts '---- should show help_help'
70
- out = catch_out_err{Yggdrasil.command %w{help help}}
70
+ out = catch_out{Yggdrasil.command %w{help help}}
71
71
  out.should == help_help
72
72
  end
73
73
 
74
74
  it 'should error too many arguments' do
75
75
  puts '---- should error too many arguments'
76
- out = catch_out_err do
76
+ err = catch_err do
77
77
  lambda{Yggdrasil.command(%w{help help help})}.should raise_error(SystemExit)
78
78
  end
79
- out.should == "#{File.basename($0)} error: too many arguments.\n\n"
79
+ err.should == "#{File.basename($0)} error: too many arguments.\n\n"
80
80
  end
81
81
 
82
82
  it 'should show help of version' do
83
83
  puts '---- should show help of version'
84
- out = catch_out_err{Yggdrasil.command %w{help version}}
84
+ out = catch_out{Yggdrasil.command %w{help version}}
85
85
  out.should == <<"EOS"
86
86
  version: See the program version
87
87
  usage: #{File.basename($0)} version
@@ -91,7 +91,7 @@ EOS
91
91
 
92
92
  it 'should show help of init' do
93
93
  puts '---- should show help of init'
94
- out = catch_out_err{Yggdrasil.command %w{help init}}
94
+ out = catch_out{Yggdrasil.command %w{help init}}
95
95
  out.should == <<"EOS"
96
96
  init: Check environment and initialize configuration.
97
97
  usage: #{File.basename($0)} init [OPTIONS...]
@@ -106,7 +106,7 @@ EOS
106
106
 
107
107
  it 'should show help of add' do
108
108
  puts '---- should show help of add'
109
- out = catch_out_err{Yggdrasil.command %w{help add}}
109
+ out = catch_out{Yggdrasil.command %w{help add}}
110
110
  out.should == <<"EOS"
111
111
  add: Add files to management list (add to subversion)
112
112
  usage #{File.basename($0)} add [FILES...]
@@ -116,7 +116,7 @@ EOS
116
116
 
117
117
  it 'should show help of commit' do
118
118
  puts '---- should show help of commit'
119
- out = catch_out_err{Yggdrasil.command %w{help commit}}
119
+ out = catch_out{Yggdrasil.command %w{help commit}}
120
120
  out.should == <<"EOS"
121
121
  commit (ci): Send changes from your local file to the repository.
122
122
  usage: #{File.basename($0)} commit [OPTIONS...] [FILES...]
@@ -132,7 +132,7 @@ EOS
132
132
 
133
133
  it 'should show help of cleanup' do
134
134
  puts '---- should show help of cleanup'
135
- out = catch_out_err{Yggdrasil.command %w{help cleanup}}
135
+ out = catch_out{Yggdrasil.command %w{help cleanup}}
136
136
  out.should == <<"EOS"
137
137
  cleanup: clean up the working copy
138
138
  usage: #{File.basename($0)} cleanup [OPTIONS...]
@@ -146,7 +146,7 @@ EOS
146
146
 
147
147
  it 'should show help of diff' do
148
148
  puts '---- should show help of diff'
149
- out = catch_out_err{Yggdrasil.command %w{help diff}}
149
+ out = catch_out{Yggdrasil.command %w{help diff}}
150
150
  out.should == <<"EOS"
151
151
  diff (di): Display the differences between two revisions or paths.
152
152
  usage: #{File.basename($0)} diff [OPTIONS...] [PATH...]
@@ -168,7 +168,7 @@ EOS
168
168
 
169
169
  it 'should show help of list' do
170
170
  puts '---- should show help of list'
171
- out = catch_out_err{Yggdrasil.command %w{help list}}
171
+ out = catch_out{Yggdrasil.command %w{help list}}
172
172
  out.should == <<"EOS"
173
173
  list (ls): List directory entries in the repository.
174
174
  usage: #{File.basename($0)} list [OPTIONS...] [PATH...]
@@ -184,16 +184,14 @@ Valid options:
184
184
  'BASE' base rev of item's working copy
185
185
  'COMMITTED' last commit at or before BASE
186
186
  'PREV' revision just before COMMITTED
187
- -R [--recursive] : descend recursively, same as --depth=infinity
188
- --depth ARG : limit operation by depth ARG ('empty', 'files',
189
- 'immediates', or 'infinity')
187
+ -R [--recursive] : descend recursively
190
188
 
191
189
  EOS
192
190
  end
193
191
 
194
192
  it 'should show help of log' do
195
193
  puts '---- should show help of log'
196
- out = catch_out_err{Yggdrasil.command %w{help log}}
194
+ out = catch_out{Yggdrasil.command %w{help log}}
197
195
  out.should == <<"EOS"
198
196
  log: Show the log messages for a set of revision(s) and/or file(s).
199
197
  usage: #{File.basename($0)} log [OPTIONS...] [PATH]
@@ -215,7 +213,7 @@ EOS
215
213
 
216
214
  it 'should show help of status' do
217
215
  puts '---- should show help of status'
218
- out = catch_out_err{Yggdrasil.command %w{help status}}
216
+ out = catch_out{Yggdrasil.command %w{help status}}
219
217
  out.should == <<"EOS"
220
218
  status (stat, st): Print the status of managed files and directories.
221
219
  usage: #{File.basename($0)} status [OPTIONS...] [PATH...]
@@ -223,15 +221,13 @@ usage: #{File.basename($0)} status [OPTIONS...] [PATH...]
223
221
  Valid options:
224
222
  --username ARG : specify a username ARG
225
223
  --password ARG : specify a password ARG
226
- --depth ARG : limit operation by depth ARG ('empty', 'files',
227
- 'immediates', or 'infinity')
228
224
 
229
225
  EOS
230
226
  end
231
227
 
232
228
  it 'should show help of update' do
233
229
  puts '---- should show help of update'
234
- out = catch_out_err{Yggdrasil.command %w{help update}}
230
+ out = catch_out{Yggdrasil.command %w{help update}}
235
231
  out.should == <<"EOS"
236
232
  update (up): Bring changes from the repository into the local files.
237
233
  usage: #{File.basename($0)} update [PATH...]
@@ -254,7 +250,7 @@ EOS
254
250
 
255
251
  it 'should show help of revert' do
256
252
  puts '---- should show help of revert'
257
- out = catch_out_err{Yggdrasil.command %w{help revert}}
253
+ out = catch_out{Yggdrasil.command %w{help revert}}
258
254
  out.should == <<"EOS"
259
255
  revert: Restore pristine working copy file (undo most local edits).
260
256
  usage: #{File.basename($0)} revert [PATH...]
data/spec/init_spec.rb CHANGED
@@ -8,20 +8,44 @@ describe Yggdrasil, "init" do
8
8
 
9
9
  it 'should error: "Not enough arguments provided"' do
10
10
  puts '---- should error: "Not enough arguments provided"'
11
- out = catch_out_err do
11
+ err = catch_err do
12
12
  lambda{Yggdrasil.command(%w{init --repo})}.should raise_error(SystemExit)
13
13
  end
14
- out.should == "#{File.basename($0)} error: Not enough arguments provided: --repo\n\n"
14
+ err.should == "#{File.basename($0)} error: Not enough arguments provided: --repo\n\n"
15
15
  end
16
16
 
17
17
  it 'should error: can not access to SVN server' do
18
18
  puts '---- should error: can not access to SVN server'
19
19
  `rm -rf /tmp/yggdrasil-test/.yggdrasil`
20
- out = catch_out_err do
20
+ err = catch_err do
21
21
  cmd_args = %w{init --repo file:///tmp/yggdrasil-test/hoge --username hoge --password foo}
22
22
  lambda{Yggdrasil.command(cmd_args)}.should raise_error(SystemExit)
23
23
  end
24
- out.should == "SVN access test...\nSVN error: can not access to 'file:///tmp/yggdrasil-test/hoge'.\n"
24
+ err.should == "#{File.basename($0)} error: can not access to 'file:///tmp/yggdrasil-test/hoge'.\n\n"
25
+ end
26
+
27
+ it 'should error: need username' do
28
+ puts '---- should error: need username'
29
+
30
+ err = catch_err do
31
+ cmd_args = %w{init --repo file:///tmp/yggdrasil-test/svn-repo/mng-repo/host-name/} +
32
+ %w{--non-interactive}
33
+ lambda{Yggdrasil.command(cmd_args)}.should raise_error(SystemExit)
34
+ end
35
+ err.should ==
36
+ "#{File.basename($0)} error: not exist directory(s): mng-repo/host-name\n\n"
37
+ end
38
+
39
+ it 'should error: need password' do
40
+ puts '---- should error: need password'
41
+
42
+ err = catch_err do
43
+ cmd_args = %w{init --repo file:///tmp/yggdrasil-test/svn-repo/mng-repo/host-name/} +
44
+ %w{--non-interactive --parents --username hoge }
45
+ lambda{Yggdrasil.command(cmd_args)}.should raise_error(SystemExit)
46
+ end
47
+ err.should ==
48
+ "#{File.basename($0)} error: Can't get username or password\n\n"
25
49
  end
26
50
 
27
51
  it 'should error: no valid repository' do
@@ -29,10 +53,11 @@ describe Yggdrasil, "init" do
29
53
  `rm -rf /tmp/yggdrasil-test/.yggdrasil`
30
54
  `rm -rf /tmp/yggdrasil-test/svn-repo`
31
55
 
32
- catch_out_err do # > /dev/null
56
+ err = catch_err do
33
57
  cmd_args = %w{init --repo file:///tmp/yggdrasil-test/svn-repo/mng-repo/host-name/ --username hoge --password foo}
34
58
  lambda{Yggdrasil.command(cmd_args)}.should raise_error(SystemExit)
35
59
  end
60
+ err.should == "#{File.basename($0)} error: can not access to 'file:///tmp/yggdrasil-test/svn-repo/mng-repo/host-name'.\n\n"
36
61
  end
37
62
 
38
63
  it 'should success: create config file' do
@@ -68,7 +93,7 @@ EOS
68
93
  end
69
94
  `svnserve -d`
70
95
 
71
- out = catch_out_err do
96
+ out = catch_out do
72
97
  Yggdrasil.command %w{init},
73
98
  "svn://localhost/tmp/yggdrasil-test/svn-repo/mng-repo/host-name/\n"\
74
99
  "hoge\n"\
@@ -77,9 +102,9 @@ EOS
77
102
  end
78
103
  out.should == \
79
104
  "Input svn repo URL: "\
80
- "Input svn username: "\
81
- "Input svn password: "\
82
105
  "SVN access test...\n"\
106
+ "Input svn username: "\
107
+ "Input svn password: \n"\
83
108
  "SVN access OK: svn://localhost/tmp/yggdrasil-test/svn-repo\n"\
84
109
  "not exist directory(s): mng-repo/host-name\n"\
85
110
  "make directory(s)? [Yn]: "
data/spec/list_spec.rb CHANGED
@@ -9,14 +9,14 @@ describe Yggdrasil, "list" do
9
9
 
10
10
  it 'should show list (absolute path)' do
11
11
  puts '---- should show list (absolute path)'
12
- out = catch_out_err{Yggdrasil.command(%w{list /tmp} +
12
+ out = catch_out{Yggdrasil.command(%w{list /tmp} +
13
13
  %w{--username hoge --password foo})}
14
14
  out.should == "yggdrasil-test/\n"
15
15
  end
16
16
 
17
17
  it 'should show list (relative path)' do
18
18
  puts '---- should show list (relative path)'
19
- out = catch_out_err do
19
+ out = catch_out do
20
20
  FileUtils.cd "/tmp" do
21
21
  Yggdrasil.command %w{list yggdrasil-test}+
22
22
  %w{--username hoge --password foo}
@@ -27,7 +27,7 @@ describe Yggdrasil, "list" do
27
27
 
28
28
  it 'should show list (no path)' do
29
29
  puts '---- should show list (no path)'
30
- out = catch_out_err do
30
+ out = catch_out do
31
31
  FileUtils.cd "/tmp/yggdrasil-test" do
32
32
  Yggdrasil.command %w{list} +
33
33
  %w{--username hoge --password foo}
@@ -38,7 +38,7 @@ describe Yggdrasil, "list" do
38
38
 
39
39
  it 'should show list (with options)' do
40
40
  puts '---- should show list (with options)'
41
- out = catch_out_err{Yggdrasil.command(%w{list -R --revision 2 --recursive /tmp} +
41
+ out = catch_out{Yggdrasil.command(%w{list -R --revision 2 --recursive /tmp} +
42
42
  %w{--username hoge --password foo})}
43
43
  out.should == "yggdrasil-test/\nyggdrasil-test/A\nyggdrasil-test/B\n"
44
44
  end
data/spec/log_spec.rb CHANGED
@@ -9,7 +9,7 @@ describe Yggdrasil, "log" do
9
9
 
10
10
  it 'should show log (absolute path)' do
11
11
  puts '---- should show log (absolute path)'
12
- out = catch_out_err{Yggdrasil.command(%w{log /tmp} +
12
+ out = catch_out{Yggdrasil.command(%w{log /tmp} +
13
13
  %w{--username hoge --password foo})}
14
14
  out.gsub!(%r{20..-..-.. .*20..\)}, '')
15
15
  out.should == <<"EOS"
@@ -35,7 +35,7 @@ EOS
35
35
 
36
36
  it 'should show log (relative path)' do
37
37
  puts '---- should show log (relative path)'
38
- out = catch_out_err do
38
+ out = catch_out do
39
39
  FileUtils.cd "/tmp" do
40
40
  Yggdrasil.command %w{log yggdrasil-test}+
41
41
  %w{--username hoge --password foo}
@@ -65,7 +65,7 @@ EOS
65
65
 
66
66
  it 'should show log (no path)' do
67
67
  puts '---- should show log (no path)'
68
- out = catch_out_err do
68
+ out = catch_out do
69
69
  FileUtils.cd "/tmp/yggdrasil-test" do
70
70
  Yggdrasil.command %w{log} +
71
71
  %w{--username hoge --password foo}
@@ -95,7 +95,7 @@ EOS
95
95
 
96
96
  it 'should show log (with options)' do
97
97
  puts '---- should show log (with options)'
98
- out = catch_out_err{Yggdrasil.command(%w{log --revision 2 /tmp} +
98
+ out = catch_out{Yggdrasil.command(%w{log --revision 2 /tmp} +
99
99
  %w{--username hoge --password foo})}
100
100
  out.sub!(%r{20..-..-.. .*20..\)}, '')
101
101
  out.should == <<"EOS"
data/spec/revert_spec.rb CHANGED
@@ -22,7 +22,7 @@ describe Yggdrasil, "revert" do
22
22
  end
23
23
 
24
24
  puts "\n-- check revert file (add)"
25
- out = catch_out_err do
25
+ out = catch_out do
26
26
  Yggdrasil.command %w{status /tmp/yggdrasil-test} +
27
27
  %w{--username hoge --password foo}
28
28
  end
@@ -40,7 +40,7 @@ describe Yggdrasil, "revert" do
40
40
  "0\nY\n"
41
41
 
42
42
  puts "\n-- check revert file (modify)"
43
- out = catch_out_err do
43
+ out = catch_out do
44
44
  Yggdrasil.command %w{status /tmp/yggdrasil-test} +
45
45
  %w{--username hoge --password foo}
46
46
  end
@@ -56,7 +56,7 @@ describe Yggdrasil, "revert" do
56
56
  "foo\nY\n" # interactive input: password, Y/n
57
57
 
58
58
  puts "\n-- check revert file"
59
- out = catch_out_err do
59
+ out = catch_out do
60
60
  Yggdrasil.command %w{status /tmp/yggdrasil-test} +
61
61
  %w{--username hoge --password foo}
62
62
  end
@@ -74,7 +74,7 @@ describe Yggdrasil, "revert" do
74
74
  "0\nY\n"
75
75
 
76
76
  puts "\n-- check revert file"
77
- out = catch_out_err do
77
+ out = catch_out do
78
78
  Yggdrasil.command %w{status /tmp/yggdrasil-test} +
79
79
  %w{--username hoge --password foo}
80
80
  end
@@ -92,7 +92,7 @@ describe Yggdrasil, "revert" do
92
92
  "0\nn\n"
93
93
 
94
94
  puts "\n-- check status"
95
- out = catch_out_err do
95
+ out = catch_out do
96
96
  Yggdrasil.command %w{status /tmp/yggdrasil-test} +
97
97
  %w{--username hoge --password foo}
98
98
  end
@@ -116,7 +116,7 @@ describe Yggdrasil, "revert" do
116
116
  "0\nY\n"
117
117
 
118
118
  puts "\n-- check status"
119
- out = catch_out_err do
119
+ out = catch_out do
120
120
  Yggdrasil.command %w{status /tmp/yggdrasil-test} +
121
121
  %w{--username hoge --password foo}
122
122
  end
data/spec/spec_helper.rb CHANGED
@@ -49,7 +49,7 @@ def init_yggdrasil
49
49
  %w{--username hoge --password foo}
50
50
  end
51
51
 
52
- def catch_out_err
52
+ def catch_out
53
53
  exit 1 unless block_given?
54
54
  tmp_out = $stdout
55
55
  $stdout = StringIO.new
@@ -57,3 +57,12 @@ def catch_out_err
57
57
  $stdout, tmp_out = tmp_out, $stdout
58
58
  tmp_out.string
59
59
  end
60
+
61
+ def catch_err
62
+ exit 1 unless block_given?
63
+ tmp_err = $stdout
64
+ $stderr = StringIO.new
65
+ yield
66
+ $stderr, tmp_err = tmp_err, $stderr
67
+ tmp_err.string
68
+ end
data/spec/status_spec.rb CHANGED
@@ -16,7 +16,7 @@ describe Yggdrasil, "status" do
16
16
 
17
17
  it 'should show status(absolute and relative)' do
18
18
  puts "---- should show status(absolute and relative)"
19
- out = catch_out_err do
19
+ out = catch_out do
20
20
  FileUtils.cd "/tmp/yggdrasil-test" do
21
21
  Yggdrasil.command %w{status /tmp/yggdrasil-test/A B --username hoge --password foo}
22
22
  end
@@ -30,7 +30,7 @@ EOS
30
30
 
31
31
  it 'should show status(/)' do
32
32
  puts "---- should show status(/)"
33
- out = catch_out_err do
33
+ out = catch_out do
34
34
  FileUtils.cd "/tmp/yggdrasil-test" do
35
35
  Yggdrasil.command %w{status / --username hoge --password foo}
36
36
  end
@@ -46,7 +46,7 @@ EOS
46
46
 
47
47
  it 'should show status (no path)' do
48
48
  puts "---- should show status (no path)"
49
- out = catch_out_err do
49
+ out = catch_out do
50
50
  FileUtils.cd "/tmp/yggdrasil-test" do
51
51
  Yggdrasil.command %w{status --username hoge --password foo}
52
52
  end
data/spec/version_spec.rb CHANGED
@@ -12,13 +12,13 @@ EOS
12
12
 
13
13
  it 'should show version on "version"' do
14
14
  puts '---- should show version on "version"'
15
- out = catch_out_err{Yggdrasil.command %w{version}}
15
+ out = catch_out{Yggdrasil.command %w{version}}
16
16
  out.should == show_version
17
17
  end
18
18
 
19
19
  it 'should show version on "--version"' do
20
20
  puts '---- should show version on "--version"'
21
- out = catch_out_err{Yggdrasil.command %w{--version}}
21
+ out = catch_out{Yggdrasil.command %w{--version}}
22
22
  out.should == show_version
23
23
  end
24
24
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yggdrasil
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-19 00:00:00.000000000 Z
12
+ date: 2013-01-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -98,7 +98,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
98
98
  version: '0'
99
99
  segments:
100
100
  - 0
101
- hash: -1095897170101989481
101
+ hash: -1085258469847408052
102
102
  required_rubygems_version: !ruby/object:Gem::Requirement
103
103
  none: false
104
104
  requirements:
@@ -107,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
107
  version: '0'
108
108
  segments:
109
109
  - 0
110
- hash: -1095897170101989481
110
+ hash: -1085258469847408052
111
111
  requirements: []
112
112
  rubyforge_project:
113
113
  rubygems_version: 1.8.23