Do not match untagged strings when tags are specified.
In addition, add a --untagged option for force-selecting all untagged strings.
This commit is contained in:
parent
6a1a7a0584
commit
7af9048cf4
5 changed files with 10 additions and 6 deletions
|
@ -36,9 +36,12 @@ module Twine
|
|||
opts.on('-l', '--lang LANGUAGES', Array, 'The language code(s) to use for the specified action.') do |langs|
|
||||
@options[:languages] = langs
|
||||
end
|
||||
opts.on('-t', '--tags TAGS', Array, 'The tag(s) to use for the specified action. Only strings with that tag will be processed.') do |tags|
|
||||
opts.on('-t', '--tags TAGS', Array, 'The tag(s) to use for the specified action. Only strings with that tag will be processed. Do not specify any tags to match all strings in the strings data file.') do |tags|
|
||||
@options[:tags] = tags
|
||||
end
|
||||
opts.on('-u', '--untagged', 'If you have specified tags using the --tags flag, then only those tags will be selected. If you also want to select all strings that are untagged, then you can specify this option to do so.') do |u|
|
||||
@options[:untagged] = true
|
||||
end
|
||||
formats = []
|
||||
Formatters::FORMATTERS.each do |formatter|
|
||||
formats << formatter::FORMAT_NAME
|
||||
|
|
|
@ -77,7 +77,7 @@ module Twine
|
|||
@strings.sections.each do |section|
|
||||
printed_section = false
|
||||
section.rows.each do |row|
|
||||
if row.matches_tags?(@options[:tags])
|
||||
if row.matches_tags?(@options[:tags], @options[:untagged])
|
||||
if !printed_section
|
||||
f.puts ''
|
||||
if section.name && section.name.length > 0
|
||||
|
|
|
@ -75,7 +75,7 @@ module Twine
|
|||
@strings.sections.each do |section|
|
||||
printed_section = false
|
||||
section.rows.each do |row|
|
||||
if row.matches_tags?(@options[:tags])
|
||||
if row.matches_tags?(@options[:tags], @options[:untagged])
|
||||
if !printed_section
|
||||
f.puts ''
|
||||
if section.name && section.name.length > 0
|
||||
|
|
|
@ -22,13 +22,13 @@ module Twine
|
|||
@translations = {}
|
||||
end
|
||||
|
||||
def matches_tags?(tags)
|
||||
def matches_tags?(tags, include_untagged)
|
||||
if tags == nil || tags.length == 0
|
||||
# The user did not specify any tags. Everything passes.
|
||||
return true
|
||||
elsif @tags == nil || @tags.length == 0
|
||||
# This row has no tags. Never match
|
||||
return false
|
||||
# This row has no tags.
|
||||
return (include_untagged) ? true : false
|
||||
else
|
||||
tags.each do |tag|
|
||||
if @tags.include? tag
|
||||
|
|
1
test/fixtures/test-output-1.txt
vendored
1
test/fixtures/test-output-1.txt
vendored
|
@ -7,4 +7,5 @@
|
|||
<string name="key1">key1-french</string>
|
||||
<string name="key2">key2-french</string>
|
||||
<string name="key3">key3-english</string>
|
||||
<string name="key4">key4-english</string>
|
||||
</resources>
|
||||
|
|
Reference in a new issue