class Tmsync::CLI
Public Instance Methods
execute()
click to toggle source
# File lib/tmsync/cli.rb, line 13 def execute matching_regex = -> { case options[:platform].downcase when 'ios' Tmsync::Constants::IOS_MATCHING_REGEX when 'android' Tmsync::Constants::ANDROID_MATCHING_REGEX else options[:matching_regex] end }.call exclude_regex = -> { case options[:platform].downcase when 'ios' Tmsync::Constants::IOS_EXCLUDE_REGEX when 'android' Tmsync::Constants::ANDROID_EXCLUDE_REGEX else options[:exclude_regex] end }.call file_search = Tmsync::FileSearch.new( base_path: options[:path], matching_regex: matching_regex, exclude_regex: exclude_regex ) result = file_search.find_all_grouped_by_language if result.empty? puts "No translation files found." else ([options[:source_language]] | result.keys).each do |language| result[language].each do |file_path| file_directory = File.dirname(file_path).gsub(options[:path], '') file_directory[0] = '' if file_directory[0] == '/' file_extension = File.extname(file_path) file_name = File.basename(file_path, file_extension) android_module = '' android_module = file_path.match(/([^\/]+)\/src\/main\/res/).captures.first if options[:platform] == 'android' command = options[:command] .gsub('<LANGUAGE>', language) .gsub('<FILE_PATH>', file_path) .gsub('<FILE_DIR>', file_directory) .gsub('<FILE_EXT>', file_extension) .gsub('<FILE_NAME>', file_name) .gsub('<ANDROID_MODULE>', android_module) puts "Executing: '#{command}'" output = %x(#{command}) if output.nil? || output.empty? puts "Output: n/a" else puts "Output: #{output}" end end end end end