parent
968d796389
commit
f106e2e272
3 changed files with 47 additions and 8 deletions
|
@ -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 ''
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Reference in a new issue