bin/crowdin-cli in crowdin-cli-0.3.3 vs bin/crowdin-cli in crowdin-cli-0.3.4

- old
+ new

@@ -323,10 +323,16 @@ desc I18n.t('app.flags.config.desc') default_value File.join(Dir.pwd, 'crowdin.yaml') arg_name '<s>' flag [:c, :config] +desc I18n.t('app.flags.identity.desc') +default_value File.join(Dir.home, '.crowdin.yaml') +arg_name '<s>' +flag [:identity] + + desc I18n.t('app.commands.upload.desc') long_desc I18n.t('app.commands.upload.long_desc') command :upload do |c| c.desc I18n.t('app.commands.upload.commands.sources.desc') @@ -362,13 +368,13 @@ dest = file['source'] dest_files << dest local_file = { dest: dest, source: File.join(@base_path, file['source']), export_pattern: file['translation'] } - local_file.merge!({ sheme: file['scheme'] }) if file.has_key?('scheme') - local_file.merge!({ first_line_contains_header: file['first_line_contains_header'] }) if file.has_key?('first_line_contains_header') - local_file.merge!({ update_option: file['update_option'] }) if file.has_key?('update_option') + @allowed_options.each do |option| + local_file.merge!({ option.to_sym => file[option] }) if file.has_key?(option) + end local_files << local_file else Find.find(@base_path) do |source_path| dest = source_path.sub(@base_path, '') # relative path in Crowdin @@ -386,13 +392,13 @@ export_pattern = construct_export_pattern(dest, file['source'], file['translation']) local_file = { dest: dest, source: source_path, export_pattern: export_pattern } - local_file.merge!({ sheme: file['scheme'] }) if file.has_key?('scheme') - local_file.merge!({ first_line_contains_header: file['first_line_contains_header'] }) if file.has_key?('first_line_contains_header') - local_file.merge!({ update_option: file['update_option'] }) if file.has_key?('update_option') + @allowed_options.each do |option| + local_file.merge!({ option.to_sym => file[option] }) if file.has_key?(option) + end local_files << local_file end end # Find @@ -429,13 +435,13 @@ files_for_upload = local_files.select { |file| update_files.include?(file[:dest]) } files_for_upload.each do |file| print "Updating source file `#{file[:dest]}'" params = {} - params[:scheme] = file.delete(:sheme) - params[:first_line_contains_header] = file.delete(:first_line_contains_header) - params[:update_option] = file.delete(:update_option) # 'update_without_changes' or 'update_as_unapproved' + @allowed_options.each do |option| + params[option.to_sym] = file.delete(option.to_sym) + end resp = @crowdin.update_file([] << file, params) case resp['files'].first[1] when 'skipped' @@ -452,12 +458,13 @@ files_for_add = local_files.select { |file| add_files.include?(file[:dest]) } files_for_add.each do |file| print "Uploading source file `#{file[:dest]}'" params = {} - params[:scheme] = file.delete(:sheme) - params[:first_line_contains_header] = file.delete(:first_line_contains_header) + @allowed_options.each do |option| + params[option.to_sym] = file.delete(option.to_sym) + end resp = @crowdin.add_file([] << file, params) puts "\rUploading source file `#{file[:dest]}' - OK" end @@ -765,13 +772,13 @@ dest = file['source'] dest_files << dest local_file = { dest: dest, source: File.join(@base_path, file['source']), export_pattern: file['translation'] } - local_file.merge!({ sheme: file['scheme'] }) if file.has_key?('scheme') - local_file.merge!({ first_line_contains_header: file['first_line_contains_header'] }) if file.has_key?('first_line_contains_header') - local_file.merge!({ update_option: file['update_option'] }) if file.has_key?('update_option') + @allowed_options.each do |option| + local_file.merge!({ option.to_sym => file[option] }) if file.has_key?(option) + end local_files << local_file else Find.find(@base_path) do |source_path| dest = source_path.sub(@base_path, '') # relative path in Crowdin @@ -789,13 +796,13 @@ export_pattern = construct_export_pattern(dest, file['source'], file['translation']) local_file = { dest: dest, source: source_path, export_pattern: export_pattern } - local_file.merge!({ sheme: file['scheme'] }) if file.has_key?('scheme') - local_file.merge!({ first_line_contains_header: file['first_line_contains_header'] }) if file.has_key?('first_line_contains_header') - local_file.merge!({ update_option: file['update_option'] }) if file.has_key?('update_option') + @allowed_options.each do |option| + local_file.merge!({ option.to_sym => file[option] }) if file.has_key?(option) + end local_files << local_file end end # Find @@ -837,11 +844,11 @@ if File.exists?(File.join(@base_path, file['source'])) dest = file['source'].sub("#{@base_path}", '') translation_languages.each do |lang| local_file = export_pattern_to_path(dest, file['translation'], lang, languages_mapping) - translations_files << local_file + translation_files << local_file end else Find.find(@base_path) do |source_path| dest = source_path.sub(@base_path, '') # relative path in Crowdin @@ -885,13 +892,39 @@ # Return true to proceed; false to abourt and not call the # chosen command # Use skips_pre before a command to skip this block # on that command only - if File.exists?(globals[:config]) - @config = YAML.load_file(globals[:config]) + @allowed_options = [ + # CSV files only + 'scheme', + 'first_line_contains_header', + 'update_option', + # XML files only + 'translate_content', + 'translate_attributes', + 'content_segmentations', + 'translate_elements', + ] + unless File.exists?(globals[:config]) + exit_now! <<EOS +Can't find configuration file (default `crowdin.yaml'). +Type `crowdin-cli help` to know how to specify custom configuration file + +See http://crowdin.net/page/cli-tool#configuration-file for more details +EOS + else + @config = YAML.load_file(globals[:config]) || {} + + if File.exists?(globals[:identity]) + identity = YAML.load_file(globals[:identity]) || {} + ['api_key', 'project_identifier'].each do |key| + @config[key] = identity[key] if identity[key] + end + end + ['api_key', 'project_identifier'].each do |key| unless @config[key] exit_now! <<EOS Configuration file misses required option `#{key}` @@ -905,17 +938,9 @@ Configuration file misses required section `files` See http://crowdin.net/page/cli-tool#configuration-file for more details EOS end - - else - exit_now! <<EOS -Can't find configuration file (default `crowdin.yaml'). -Type `crowdin-cli help` to know how to specify custom configuration file - -See http://crowdin.net/page/cli-tool#configuration-file for more details -EOS end @config['files'].each do |file| file['source'] = '/' + file['source'] unless file['source'].start_with?('/') #file['translation'] = '/' + file['translation'] unless file['translation'].start_with?('/')