Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/twine.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Celis <sebastian@sebastiancelis.com>2017-09-14 15:48:21 +0300
committerGitHub <noreply@github.com>2017-09-14 15:48:21 +0300
commit9dc3845cae85d17f349bf47beafdbc152c1af53d (patch)
tree87e6cd3b89dc19c233aedaade293622f036c56d0
parent968d7963897030551e761f8d5ee1c8072b0efc81 (diff)
parentf106e2e27285de8ab82edec896b0595fdc76d12d (diff)
Merge pull request #215 from scelis/213-twine-version
Fix #213: Add --version again which got lost in c619dd6.
-rw-r--r--lib/twine/cli.rb20
-rw-r--r--lib/twine/runner.rb2
-rw-r--r--test/test_cli.rb33
3 files changed, 47 insertions, 8 deletions
diff --git a/lib/twine/cli.rb b/lib/twine/cli.rb
index 60165dd..38f7a2f 100644
--- a/lib/twine/cli.rb
+++ b/lib/twine/cli.rb
@@ -220,21 +220,25 @@ module Twine
command = args.select { |a| a[0] != '-' }[0]
args = args.reject { |a| a == command }
+ if args.any? { |a| a == '--version' }
+ Twine::stdout.puts "Twine version #{Twine::VERSION}"
+ return false
+ end
+
mapped_command = DEPRECATED_COMMAND_MAPPINGS[command]
if mapped_command
Twine::stderr.puts "WARNING: Twine commands names have changed. `#{command}` is now `#{mapped_command}`. The old command is deprecated and will soon stop working. For more information please check the documentation at https://github.com/mobiata/twine"
command = mapped_command
end
- unless COMMANDS.keys.include? command
- Twine::stderr.puts "Invalid command: #{command}" unless command.nil?
+ if command.nil?
print_help(args)
- abort
+ return false
+ elsif not COMMANDS.keys.include? command
+ raise Twine::Error.new "Invalid command: #{command}"
end
- options = parse_command_options(command, args)
-
- return options
+ parse_command_options(command, args)
end
private
@@ -361,8 +365,8 @@ module Twine
end
parser.define('-h', '--help', 'Show this message.') do
- puts parser.help
- exit
+ Twine::stdout.puts parser.help
+ return false
end
parser.separator ''
diff --git a/lib/twine/runner.rb b/lib/twine/runner.rb
index f0a76ff..cd21e15 100644
--- a/lib/twine/runner.rb
+++ b/lib/twine/runner.rb
@@ -7,6 +7,8 @@ module Twine
class Runner
def self.run(args)
options = CLI.parse(args)
+
+ return unless options
twine_file = TwineFile.new
twine_file.read options[:twine_file]
diff --git a/test/test_cli.rb b/test/test_cli.rb
index a626da4..7b7147e 100644
--- a/test/test_cli.rb
+++ b/test/test_cli.rb
@@ -17,6 +17,12 @@ class CLITest < TwineTest
raise "you need to implement `parse_with` in your test class"
end
+ def assert_help
+ parse_with '--help'
+ assert_equal @options, false
+ assert_match /Usage: twine.*Examples:/m, Twine::stdout.string
+ end
+
def assert_option_consume_all
parse_with '--consume-all'
assert @options[:consume_all]
@@ -115,6 +121,26 @@ class CLITest < TwineTest
end
end
+class TestCLI < CLITest
+ def test_version
+ parse "--version"
+
+ assert_equal @options, false
+ assert_equal "Twine version #{Twine::VERSION}\n", Twine::stdout.string
+ end
+
+ def test_help
+ parse ""
+ assert_match 'Usage: twine', Twine::stdout.string
+ end
+
+ def test_invalid_command
+ assert_raises Twine::Error do
+ parse "not a command"
+ end
+ end
+end
+
class TestGenerateLocalizationFileCLI < CLITest
def parse_with(parameters)
parse "generate-localization-file #{@twine_file_path} #{@output_path} " + parameters
@@ -141,6 +167,7 @@ class TestGenerateLocalizationFileCLI < CLITest
end
def test_options
+ assert_help
assert_option_developer_language
assert_option_encoding
assert_option_format
@@ -179,6 +206,7 @@ class TestGenerateAllLocalizationFilesCLI < CLITest
end
def test_options
+ assert_help
assert_option_developer_language
assert_option_encoding
assert_option_format
@@ -228,6 +256,7 @@ class TestGenerateLocalizationArchiveCLI < CLITest
end
def test_options
+ assert_help
assert_option_developer_language
assert_option_encoding
assert_option_include
@@ -279,6 +308,7 @@ class TestConsumeLocalizationFileCLI < CLITest
end
def test_options
+ assert_help
assert_option_consume_all
assert_option_consume_comments
assert_option_developer_language
@@ -317,6 +347,7 @@ class TestConsumeAllLocalizationFilesCLI < CLITest
end
def test_options
+ assert_help
assert_option_consume_all
assert_option_consume_comments
assert_option_developer_language
@@ -353,6 +384,7 @@ class TestConsumeLocalizationArchiveCLI < CLITest
end
def test_options
+ assert_help
assert_option_consume_all
assert_option_consume_comments
assert_option_developer_language
@@ -398,6 +430,7 @@ class TestValidateTwineFileCLI < CLITest
end
def test_options
+ assert_help
assert_option_developer_language
end