From 7af9048cf435de398058533f9abcbb9009cff0e4 Mon Sep 17 00:00:00 2001 From: Sebastian Celis Date: Thu, 1 Mar 2012 09:32:05 -0600 Subject: [PATCH] Do not match untagged strings when tags are specified. In addition, add a --untagged option for force-selecting all untagged strings. --- lib/twine/cli.rb | 5 ++++- lib/twine/formatters/android.rb | 2 +- lib/twine/formatters/apple.rb | 2 +- lib/twine/stringsfile.rb | 6 +++--- test/fixtures/test-output-1.txt | 1 + 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/twine/cli.rb b/lib/twine/cli.rb index 63df42a..38b6bf1 100644 --- a/lib/twine/cli.rb +++ b/lib/twine/cli.rb @@ -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 diff --git a/lib/twine/formatters/android.rb b/lib/twine/formatters/android.rb index fff1488..2d5484a 100644 --- a/lib/twine/formatters/android.rb +++ b/lib/twine/formatters/android.rb @@ -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 diff --git a/lib/twine/formatters/apple.rb b/lib/twine/formatters/apple.rb index 07c35e7..5912b87 100644 --- a/lib/twine/formatters/apple.rb +++ b/lib/twine/formatters/apple.rb @@ -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 diff --git a/lib/twine/stringsfile.rb b/lib/twine/stringsfile.rb index adf3a31..d40ae77 100644 --- a/lib/twine/stringsfile.rb +++ b/lib/twine/stringsfile.rb @@ -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 diff --git a/test/fixtures/test-output-1.txt b/test/fixtures/test-output-1.txt index ccadd5a..ff0aee4 100644 --- a/test/fixtures/test-output-1.txt +++ b/test/fixtures/test-output-1.txt @@ -7,4 +7,5 @@ key1-french key2-french key3-english + key4-english