Add --quiet option. Closes .

This commit is contained in:
Sebastian Ludwig 2018-05-21 13:05:59 +02:00
parent 8eccb7fa57
commit 937c713b71
5 changed files with 62 additions and 7 deletions

View file

@ -78,6 +78,10 @@ module Twine
switch: ['-p', '--[no-]pedantic'],
description: 'When validating a Twine file, perform additional checks that go beyond pure validity (like presence of tags).'
},
quiet: {
switch: ['-q', '--[no-]quiet'],
description: 'Suppress all console output except error messages.'
},
tags: {
switch: ['-t', '--tags TAG1,TAG2,TAG3', Array],
description: <<-DESC,
@ -110,6 +114,7 @@ module Twine
:format,
:include,
:languages,
:quiet,
:tags,
:untagged,
:validate
@ -131,6 +136,7 @@ module Twine
:file_name,
:format,
:include,
:quiet,
:tags,
:untagged,
:validate
@ -147,6 +153,7 @@ module Twine
:developer_language,
:encoding,
:include,
:quiet,
:tags,
:untagged,
:validate
@ -164,6 +171,7 @@ module Twine
:format,
:languages,
:output_path,
:quiet,
:tags
],
option_validation: Proc.new { |options|
@ -183,6 +191,7 @@ module Twine
:encoding,
:format,
:output_path,
:quiet,
:tags
],
example: 'twine consume-all-localization-files twine.txt Resources/Locales/ --developer-language en --tags DefaultTag1,DefaultTag2'
@ -197,6 +206,7 @@ module Twine
:encoding,
:format,
:output_path,
:quiet,
:tags
],
example: 'twine consume-localization-archive twine.txt LocDrop5.zip'
@ -206,7 +216,8 @@ module Twine
arguments: [:twine_file],
optional_options: [
:developer_language,
:pedantic
:pedantic,
:quiet
],
example: 'twine validate-twine-file twine.txt'
}

View file

@ -5,6 +5,14 @@ Twine::Plugin.new # Initialize plugins first in Runner.
module Twine
class Runner
class NullOutput
def puts(message)
end
def string
""
end
end
def self.run(args)
options = CLI.parse(args)
@ -35,6 +43,9 @@ module Twine
def initialize(options = {}, twine_file = TwineFile.new)
@options = options
@twine_file = twine_file
if @options[:quite]
Twine::stdout = NullOutput.new
end
end
def write_twine_data(path)

View file

@ -82,6 +82,13 @@ class CLITest < TwineTest
assert_equal @output_path, @options[:output_path]
end
def assert_option_quiet
parse_with '--quiet'
assert @options[:quiet]
parse_with '--no-quiet'
refute @options[:quiet]
end
def assert_option_tags
# single tag
random_tag = "tag#{rand(100)}"
@ -174,6 +181,7 @@ class TestGenerateLocalizationFileCLI < CLITest
assert_option_include
assert_option_single_language
assert_raises(Twine::Error) { assert_option_multiple_languages }
assert_option_quiet
assert_option_tags
assert_option_untagged
assert_option_validate
@ -211,6 +219,7 @@ class TestGenerateAllLocalizationFilesCLI < CLITest
assert_option_encoding
assert_option_format
assert_option_include
assert_option_quiet
assert_option_tags
assert_option_untagged
assert_option_validate
@ -260,6 +269,7 @@ class TestGenerateLocalizationArchiveCLI < CLITest
assert_option_developer_language
assert_option_encoding
assert_option_include
assert_option_quiet
assert_option_tags
assert_option_untagged
assert_option_validate
@ -317,6 +327,7 @@ class TestConsumeLocalizationFileCLI < CLITest
assert_option_single_language
assert_raises(Twine::Error) { assert_option_multiple_languages }
assert_option_output_path
assert_option_quiet
assert_option_tags
end
end
@ -354,6 +365,7 @@ class TestConsumeAllLocalizationFilesCLI < CLITest
assert_option_encoding
assert_option_format
assert_option_output_path
assert_option_quiet
assert_option_tags
end
end
@ -391,6 +403,7 @@ class TestConsumeLocalizationArchiveCLI < CLITest
assert_option_encoding
assert_option_format
assert_option_output_path
assert_option_quiet
assert_option_tags
end
@ -432,6 +445,7 @@ class TestValidateTwineFileCLI < CLITest
def test_options
assert_help
assert_option_developer_language
assert_option_quiet
end
def test_option_pedantic

View file

@ -47,8 +47,8 @@ class TestGenerateAllLocalizationFiles < CommandTest
end
class TestDoNotCreateFolders < TestGenerateAllLocalizationFiles
def new_runner(twine_file = nil)
super(false, twine_file)
def new_runner(twine_file = nil, options = {})
super(false, twine_file, options)
end
def test_fails_if_output_folder_does_not_exist
@ -69,11 +69,18 @@ class TestGenerateAllLocalizationFiles < CommandTest
new_runner(empty_twine_file).generate_all_localization_files
assert_match "Skipping file at path", Twine::stdout.string
end
def test_does_not_print_empty_file_warnings_if_quite
Dir.mkdir File.join @output_dir, 'en.lproj'
empty_twine_file = build_twine_file('en') {}
new_runner(empty_twine_file, quite: true).generate_all_localization_files
refute_match "Skipping file at path", Twine::stdout.string
end
end
class TestCreateFolders < TestGenerateAllLocalizationFiles
def new_runner(twine_file = nil)
super(true, twine_file)
def new_runner(twine_file = nil, options = {})
super(true, twine_file, options)
end
def test_creates_output_folder
@ -94,6 +101,13 @@ class TestGenerateAllLocalizationFiles < CommandTest
assert_match "Skipping file at path", Twine::stdout.string
end
def test_does_not_print_empty_file_warnings_if_quite
empty_twine_file = build_twine_file('en') {}
new_runner(empty_twine_file, quite: true).generate_all_localization_files
refute_match "Skipping file at path", Twine::stdout.string
end
end
class TestValidate < CommandTest

View file

@ -1,8 +1,7 @@
require 'command_test'
class TestGenerateLocalizationArchive < CommandTest
def new_runner(twine_file = nil)
options = {}
def new_runner(twine_file = nil, options = {})
options[:output_path] = @output_path
options[:format] = 'apple'
@ -48,6 +47,12 @@ class TestGenerateLocalizationArchive < CommandTest
assert_match "Skipping file", Twine::stdout.string
end
def test_does_not_print_empty_file_warnings_if_quite
empty_twine_file = build_twine_file('en') {}
new_runner(empty_twine_file, quite: true).generate_localization_archive
refute_match "Skipping file", Twine::stdout.string
end
class TestValidate < CommandTest
def new_runner(validate)
options = {}