You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@whimsical.apache.org by se...@apache.org on 2020/07/13 23:00:38 UTC
[whimsy] branch master updated: Allow command to be an array
This is an automated email from the ASF dual-hosted git repository.
sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/whimsy.git
The following commit(s) were added to refs/heads/master by this push:
new 76bd9f4 Allow command to be an array
76bd9f4 is described below
commit 76bd9f4a777835edc9080de5b5b22474dba85983
Author: Sebb <se...@apache.org>
AuthorDate: Mon Jul 13 23:59:46 2020 +0100
Allow command to be an array
This allows for e.g. list -v or list --xml
---
lib/spec/lib/svn_spec.rb | 34 ++++++++++++++++++++++++++++++++++
lib/spec/lib/svn_wunderbar_spec.rb | 19 +++++++++++++++++++
lib/whimsy/asf/svn.rb | 28 +++++++++++++++++++++++++---
3 files changed, 78 insertions(+), 3 deletions(-)
diff --git a/lib/spec/lib/svn_spec.rb b/lib/spec/lib/svn_spec.rb
index f2eb27a..65549b9 100644
--- a/lib/spec/lib/svn_spec.rb
+++ b/lib/spec/lib/svn_spec.rb
@@ -277,6 +277,19 @@ describe ASF::SVN do
end
end
+ it "svn(['help'], 'help') should return some help" do
+ out, err = ASF::SVN.svn(['help'],'help')
+ expect(out).to match(/Describe the usage of this program or its subcommands/)
+ expect(out).not_to match(/Global options/)
+ end
+ it "svn(['help', '-v'], 'help') should return Global help" do
+ out, err = ASF::SVN.svn(['help', '-v'],'help')
+ expect(out).to match(/Global options/)
+ end
+ it "svn(['help', '--verbose'], 'help') should return Global help" do
+ out, err = ASF::SVN.svn(['help', '--verbose'],'help')
+ expect(out).to match(/Global options/)
+ end
end
describe "ASF::SVN._svn_build_cmd" do
@@ -343,6 +356,27 @@ describe ASF::SVN do
expect(cmd).to eq(["svn", "help", "--non-interactive", "--revision", '123', "--", "path"])
end
+ it "_svn_build_cmd(true, 'path') should fail with ArgumentError" do
+ expect {ASF::SVN._svn_build_cmd(true, 'path', {}) }.to raise_error(ArgumentError, 'command must be a String or an Array of Strings')
+ end
+
+ it "_svn_build_cmd(['list', true], 'path') should fail with ArgumentError" do
+ expect {ASF::SVN._svn_build_cmd([true], 'path', {}) }.to raise_error(ArgumentError, 'command true must be a String')
+ end
+
+ it "_svn_build_cmd([true], 'path') should fail with ArgumentError" do
+ expect {ASF::SVN._svn_build_cmd([true], 'path', {}) }.to raise_error(ArgumentError, 'command true must be a String')
+ end
+
+ it "_svn_build_cmd(['help', 'xyz'], 'path') should report error" do
+ expect {
+ # seems to be necessary to reset logger otherwise output is lost. However it's only necessary in conjunction with
+ # other tests such as committee_spec.rb (q.v.)
+ Wunderbar.logger = nil
+ ASF::SVN._svn_build_cmd(['help','xyz'], 'path', {})
+ }.to output("_ERROR Invalid option \"xyz\"\n").to_stderr
+ end
+
end
describe "ASF::SVN.svnpath!" do
diff --git a/lib/spec/lib/svn_wunderbar_spec.rb b/lib/spec/lib/svn_wunderbar_spec.rb
index f25b86c..2320da1 100644
--- a/lib/spec/lib/svn_wunderbar_spec.rb
+++ b/lib/spec/lib/svn_wunderbar_spec.rb
@@ -141,6 +141,25 @@ describe "ASF::SVN.svn_" do
expect(act).to eq(exp.inspect)
end
+ it "['help'] should not include Global options" do
+ rc, out = _json do |_|
+ ASF::SVN.svn_(['help'], 'help', _)
+ end
+ expect(rc).to eq(0)
+ act = out['transcript'].join(' ')
+ expect(act).to match(/Describe the usage of this program or its subcommands./)
+ expect(act).not_to match(/Global options/)
+ end
+
+ it "['help','-v'] should include Global options" do
+ rc, out = _json do |_|
+ ASF::SVN.svn_(['help','-v'], 'help', _)
+ end
+ expect(rc).to eq(0)
+ act = out['transcript'].join(' ')
+ expect(act).to match(/Describe the usage of this program or its subcommands./)
+ expect(act).to match(/Global options/)
+ end
end
describe "ASF::SVN.update" do
diff --git a/lib/whimsy/asf/svn.rb b/lib/whimsy/asf/svn.rb
index 332b520..ae2cc72 100644
--- a/lib/whimsy/asf/svn.rb
+++ b/lib/whimsy/asf/svn.rb
@@ -290,8 +290,12 @@ module ASF
end
# retrieve list, [err] for a path in svn
- def self.list(path, user=nil, password=nil)
- return self.svn('list', path, {user: user, password: password})
+ def self.list(path, user=nil, password=nil, timestamp=false)
+ if timestamp
+ return self.svn(['list','--xml'], path, {user: user, password: password})
+ else
+ return self.svn('list', path, {user: user, password: password})
+ end
end
# These keys are common to svn_ and svn
@@ -305,8 +309,24 @@ module ASF
raise ArgumentError.new "Following options not recognised: #{bad_keys.inspect}"
end
+ if command.is_a? String
+ # TODO convert to ArgumentError after further testing
+ Wunderbar.error "command #{command.inspect} is invalid" unless command =~ %r{^[a-z]+$}
+ else
+ if command.is_a? Array
+ command.each do |cmd|
+ raise ArgumentError.new "command #{cmd.inspect} must be a String" unless cmd.is_a? String
+ end
+ Wunderbar.error "command #{command.first.inspect} is invalid" unless command.first =~ %r{^[a-z]+$}
+ command.drop(1).each do |cmd|
+ Wunderbar.error "Invalid option #{cmd.inspect}" unless cmd =~ %r{^(--[a-z][a-z=]+|-[a-z])$}
+ end
+ else
+ raise ArgumentError.new "command must be a String or an Array of Strings"
+ end
+ end
# build svn command
- cmd = ['svn', command, '--non-interactive']
+ cmd = ['svn', *command, '--non-interactive']
stdin = nil # for use with -password-from-stdin
msg = options[:msg]
@@ -361,6 +381,7 @@ module ASF
# low level SVN command
# params:
# command - info, list etc
+ # Can be array, e.g. ['list', '--xml']
# path - the path(s) to be used - String or Array of Strings
# options - hash of:
# :msg - ['--message', value]
@@ -414,6 +435,7 @@ module ASF
# low level SVN command for use in Wunderbar context (_json, _text etc)
# params:
# command - info, list etc
+ # Can be array, e.g. ['list', '--xml']
# path - the path(s) to be used - String or Array of Strings
# _ - wunderbar context
# options - hash of:
Re: [whimsy] branch master updated: Allow command to be an array
Posted by Sam Ruby <ru...@intertwingly.net>.
This likely will fail on Travis.
help -v is a relatively recent addition to svn.
- Sam Ruby
On Mon, Jul 13, 2020 at 7:00 PM <se...@apache.org> wrote:
>
> This is an automated email from the ASF dual-hosted git repository.
>
> sebb pushed a commit to branch master
> in repository https://gitbox.apache.org/repos/asf/whimsy.git
>
>
> The following commit(s) were added to refs/heads/master by this push:
> new 76bd9f4 Allow command to be an array
> 76bd9f4 is described below
>
> commit 76bd9f4a777835edc9080de5b5b22474dba85983
> Author: Sebb <se...@apache.org>
> AuthorDate: Mon Jul 13 23:59:46 2020 +0100
>
> Allow command to be an array
>
> This allows for e.g. list -v or list --xml
> ---
> lib/spec/lib/svn_spec.rb | 34 ++++++++++++++++++++++++++++++++++
> lib/spec/lib/svn_wunderbar_spec.rb | 19 +++++++++++++++++++
> lib/whimsy/asf/svn.rb | 28 +++++++++++++++++++++++++---
> 3 files changed, 78 insertions(+), 3 deletions(-)
>
> diff --git a/lib/spec/lib/svn_spec.rb b/lib/spec/lib/svn_spec.rb
> index f2eb27a..65549b9 100644
> --- a/lib/spec/lib/svn_spec.rb
> +++ b/lib/spec/lib/svn_spec.rb
> @@ -277,6 +277,19 @@ describe ASF::SVN do
> end
> end
>
> + it "svn(['help'], 'help') should return some help" do
> + out, err = ASF::SVN.svn(['help'],'help')
> + expect(out).to match(/Describe the usage of this program or its subcommands/)
> + expect(out).not_to match(/Global options/)
> + end
> + it "svn(['help', '-v'], 'help') should return Global help" do
> + out, err = ASF::SVN.svn(['help', '-v'],'help')
> + expect(out).to match(/Global options/)
> + end
> + it "svn(['help', '--verbose'], 'help') should return Global help" do
> + out, err = ASF::SVN.svn(['help', '--verbose'],'help')
> + expect(out).to match(/Global options/)
> + end
> end
>
> describe "ASF::SVN._svn_build_cmd" do
> @@ -343,6 +356,27 @@ describe ASF::SVN do
> expect(cmd).to eq(["svn", "help", "--non-interactive", "--revision", '123', "--", "path"])
> end
>
> + it "_svn_build_cmd(true, 'path') should fail with ArgumentError" do
> + expect {ASF::SVN._svn_build_cmd(true, 'path', {}) }.to raise_error(ArgumentError, 'command must be a String or an Array of Strings')
> + end
> +
> + it "_svn_build_cmd(['list', true], 'path') should fail with ArgumentError" do
> + expect {ASF::SVN._svn_build_cmd([true], 'path', {}) }.to raise_error(ArgumentError, 'command true must be a String')
> + end
> +
> + it "_svn_build_cmd([true], 'path') should fail with ArgumentError" do
> + expect {ASF::SVN._svn_build_cmd([true], 'path', {}) }.to raise_error(ArgumentError, 'command true must be a String')
> + end
> +
> + it "_svn_build_cmd(['help', 'xyz'], 'path') should report error" do
> + expect {
> + # seems to be necessary to reset logger otherwise output is lost. However it's only necessary in conjunction with
> + # other tests such as committee_spec.rb (q.v.)
> + Wunderbar.logger = nil
> + ASF::SVN._svn_build_cmd(['help','xyz'], 'path', {})
> + }.to output("_ERROR Invalid option \"xyz\"\n").to_stderr
> + end
> +
> end
>
> describe "ASF::SVN.svnpath!" do
> diff --git a/lib/spec/lib/svn_wunderbar_spec.rb b/lib/spec/lib/svn_wunderbar_spec.rb
> index f25b86c..2320da1 100644
> --- a/lib/spec/lib/svn_wunderbar_spec.rb
> +++ b/lib/spec/lib/svn_wunderbar_spec.rb
> @@ -141,6 +141,25 @@ describe "ASF::SVN.svn_" do
> expect(act).to eq(exp.inspect)
> end
>
> + it "['help'] should not include Global options" do
> + rc, out = _json do |_|
> + ASF::SVN.svn_(['help'], 'help', _)
> + end
> + expect(rc).to eq(0)
> + act = out['transcript'].join(' ')
> + expect(act).to match(/Describe the usage of this program or its subcommands./)
> + expect(act).not_to match(/Global options/)
> + end
> +
> + it "['help','-v'] should include Global options" do
> + rc, out = _json do |_|
> + ASF::SVN.svn_(['help','-v'], 'help', _)
> + end
> + expect(rc).to eq(0)
> + act = out['transcript'].join(' ')
> + expect(act).to match(/Describe the usage of this program or its subcommands./)
> + expect(act).to match(/Global options/)
> + end
> end
>
> describe "ASF::SVN.update" do
> diff --git a/lib/whimsy/asf/svn.rb b/lib/whimsy/asf/svn.rb
> index 332b520..ae2cc72 100644
> --- a/lib/whimsy/asf/svn.rb
> +++ b/lib/whimsy/asf/svn.rb
> @@ -290,8 +290,12 @@ module ASF
> end
>
> # retrieve list, [err] for a path in svn
> - def self.list(path, user=nil, password=nil)
> - return self.svn('list', path, {user: user, password: password})
> + def self.list(path, user=nil, password=nil, timestamp=false)
> + if timestamp
> + return self.svn(['list','--xml'], path, {user: user, password: password})
> + else
> + return self.svn('list', path, {user: user, password: password})
> + end
> end
>
> # These keys are common to svn_ and svn
> @@ -305,8 +309,24 @@ module ASF
> raise ArgumentError.new "Following options not recognised: #{bad_keys.inspect}"
> end
>
> + if command.is_a? String
> + # TODO convert to ArgumentError after further testing
> + Wunderbar.error "command #{command.inspect} is invalid" unless command =~ %r{^[a-z]+$}
> + else
> + if command.is_a? Array
> + command.each do |cmd|
> + raise ArgumentError.new "command #{cmd.inspect} must be a String" unless cmd.is_a? String
> + end
> + Wunderbar.error "command #{command.first.inspect} is invalid" unless command.first =~ %r{^[a-z]+$}
> + command.drop(1).each do |cmd|
> + Wunderbar.error "Invalid option #{cmd.inspect}" unless cmd =~ %r{^(--[a-z][a-z=]+|-[a-z])$}
> + end
> + else
> + raise ArgumentError.new "command must be a String or an Array of Strings"
> + end
> + end
> # build svn command
> - cmd = ['svn', command, '--non-interactive']
> + cmd = ['svn', *command, '--non-interactive']
> stdin = nil # for use with -password-from-stdin
>
> msg = options[:msg]
> @@ -361,6 +381,7 @@ module ASF
> # low level SVN command
> # params:
> # command - info, list etc
> + # Can be array, e.g. ['list', '--xml']
> # path - the path(s) to be used - String or Array of Strings
> # options - hash of:
> # :msg - ['--message', value]
> @@ -414,6 +435,7 @@ module ASF
> # low level SVN command for use in Wunderbar context (_json, _text etc)
> # params:
> # command - info, list etc
> + # Can be array, e.g. ['list', '--xml']
> # path - the path(s) to be used - String or Array of Strings
> # _ - wunderbar context
> # options - hash of:
>