bin/crowdin-cli in crowdin-cli-0.5.0.pre vs bin/crowdin-cli in crowdin-cli-0.5.0.pre1

- old
+ new

@@ -369,20 +369,18 @@ c.desc I18n.t('app.flags.branch.desc') c.arg_name 'branch_name' c.flag [:b, :branch] c.action do |global_options, options, args| - project_info = @crowdin.project_info + source_language = @project_info['details']['source_language']['code'] - source_language = project_info['details']['source_language']['code'] - # Crowdin supported languages list supported_languages = @crowdin.supported_languages source_language = supported_languages.find { |lang| lang['crowdin_code'] == source_language } if @branch_name - branch = project_info['files'].find { |h| h['node_type'] == 'branch' && h['name'] == @branch_name } + branch = @project_info['files'].find { |h| h['node_type'] == 'branch' && h['name'] == @branch_name } if branch branch_files = [] << branch else print "Creating a new branch `#{@branch_name}'" @@ -398,11 +396,11 @@ # Remove branch directory from a directory path string remote_project_tree[:dirs].map! { |p| p.split('/')[2..-1].unshift('').join('/') } remote_project_tree[:files].map! { |p| p.split('/')[2..-1].unshift('').join('/') } else # INFO it also includes all branches - remote_project_tree = get_remote_files_hierarchy(project_info['files']) + remote_project_tree = get_remote_files_hierarchy(@project_info['files']) end local_files = [] dest_files = [] @@ -569,14 +567,12 @@ params[:import_eq_suggestions] = options['import-eq-suggestions'] ? 1 : 0 params[:auto_approve_imported] = options['auto-approve-imported'] ? 1 : 0 language = options[:language] - project_info = @crowdin.project_info - if @branch_name - branch = project_info['files'].find { |h| h['node_type'] == 'branch' && h['name'] == @branch_name } + branch = @project_info['files'].find { |h| h['node_type'] == 'branch' && h['name'] == @branch_name } if branch params[:branch] = @branch_name branch_files = [] << branch else @@ -587,14 +583,14 @@ # Remove branch directory from a directory path string remote_project_tree[:dirs].map! { |p| p.split('/')[2..-1].unshift('').join('/') } remote_project_tree[:files].map! { |p| p.split('/')[2..-1].unshift('').join('/') } else - remote_project_tree = get_remote_files_hierarchy(project_info['files']) + remote_project_tree = get_remote_files_hierarchy(@project_info['files']) end - project_languages = project_info['languages'].collect { |h| h['code'] } + project_languages = @project_info['languages'].collect { |h| h['code'] } if language == 'all' # do nothing else if project_languages.include?(language) @@ -604,11 +600,11 @@ end end supported_languages = @crowdin.supported_languages - source_language = project_info['details']['source_language']['code'] + source_language = @project_info['details']['source_language']['code'] source_language = supported_languages.find { |lang| lang['crowdin_code'] == source_language } translation_languages = supported_languages.select { |lang| project_languages.include?(lang['crowdin_code']) } translated_files = Hash.new{ |hash, key| hash[key] = Array.new } @@ -733,18 +729,26 @@ c.desc I18n.t('app.commands.download.switches.ignore_match.desc') c.switch ['ignore-match'], negatable: false c.action do |global_options, options, args| + if @branch_name + branch = @project_info['files'].find { |h| h['node_type'] == 'branch' && h['name'] == @branch_name } + + unless branch + exit_now! <<-EOS.strip_heredoc + path `#{@branch_name}' did not match any branch known to Crowdin + EOS + end + end + language = options[:language] supported_languages = @crowdin.supported_languages - project_info = @crowdin.project_info + project_languages = @project_info['languages'].collect { |h| h['code'] } - project_languages = project_info['languages'].collect{ |h| h['code'] } - if language == 'all' if @jipt_language if supported_languages.find { |lang| lang['crowdin_code'] == @jipt_language } project_languages << @jipt_language # crowdin_language_code else @@ -772,11 +776,11 @@ puts "- Skipped" puts "Warning: Export was skipped. Please note that this method can be invoked only once per 30 minutes." end end - source_language = project_info['details']['source_language']['code'] + source_language = @project_info['details']['source_language']['code'] source_language = supported_languages.find { |lang| lang['crowdin_code'] == source_language } translation_languages = supported_languages.select { |lang| project_languages.include?(lang['crowdin_code']) } # keys is all possible files in .ZIP archive @@ -856,27 +860,33 @@ desc I18n.t('app.commands.list.desc') long_desc I18n.t('app.commands.list.long_desc') command :list do |ls_cmd| ls_cmd.desc I18n.t('app.commands.list.commands.project.desc') - ls_cmd.command :project do |proj_cmd| - proj_cmd.desc I18n.t('app.commands.list.switches.tree.desc') - proj_cmd.switch ['tree'], negatable: false + ls_cmd.command :project do |prj_cmd| + prj_cmd.desc I18n.t('app.commands.list.switches.tree.desc') + prj_cmd.switch ['tree'], negatable: false - proj_cmd.desc I18n.t('app.flags.branch.desc') - proj_cmd.arg_name 'branch_name' - proj_cmd.flag [:b, :branch] + prj_cmd.desc I18n.t('app.flags.branch.desc') + prj_cmd.arg_name 'branch_name' + prj_cmd.flag [:b, :branch] - proj_cmd.action do |global_options, options, args| - project_info = @crowdin.project_info - + prj_cmd.action do |global_options, options, args| if @branch_name - branch = project_info['files'].find { |h| h['node_type'] == 'branch' && h['name'] == @branch_name } - branch_files = branch ? [] << branch : [] + branch = @project_info['files'].find { |h| h['node_type'] == 'branch' && h['name'] == @branch_name } + + unless branch + exit_now! <<-EOS.strip_heredoc + path `#{@branch_name}' did not match any branch known to Crowdin + EOS + end + + branch_files = [] << branch + remote_project_tree = get_remote_files_hierarchy(branch_files) else - remote_project_tree = get_remote_files_hierarchy(project_info['files']) + remote_project_tree = get_remote_files_hierarchy(@project_info['files']) end if options[:tree] tree = build_hash_tree(remote_project_tree[:files]) display_tree(tree) @@ -889,14 +899,10 @@ ls_cmd.desc I18n.t('app.commands.list.commands.sources.desc') ls_cmd.command :sources do |src_cmd| src_cmd.desc I18n.t('app.commands.list.switches.tree.desc') src_cmd.switch ['tree'], negatable: false - src_cmd.desc I18n.t('app.flags.branch.desc') - src_cmd.arg_name 'branch_name' - src_cmd.flag [:b, :branch] - src_cmd.action do |global_options, options, args| local_files = [] dest_files = [] @config['files'].each do |file| @@ -963,19 +969,13 @@ ls_cmd.desc I18n.t('app.commands.list.commands.translations.desc') ls_cmd.command :translations do |trans_cmd| trans_cmd.desc I18n.t('app.commands.list.switches.tree.desc') trans_cmd.switch ['tree'], negatable: false - trans_cmd.desc I18n.t('app.flags.branch.desc') - trans_cmd.arg_name 'branch_name' - trans_cmd.flag [:b, :branch] - trans_cmd.action do |global_options, options, args| - project_info = @crowdin.project_info + project_languages = @project_info['languages'].collect { |h| h['code'] } - project_languages = project_info['languages'].collect{ |h| h['code'] } - supported_languages = @crowdin.supported_languages translation_languages = supported_languages.select { |lang| project_languages.include?(lang['crowdin_code']) } translation_files = [] @config['files'].each do |file| @@ -1027,11 +1027,11 @@ end # list translations #ls_cmd.default_command :project end # list -pre do |globals ,command, options, args| +pre do |globals, command, options, args| # Pre logic here # 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 @@ -1167,15 +1167,15 @@ Warning: Configuration file misses parameter `base_path` that defines your project root directory. Using `#{@base_path}` as a root directory. EOS end @branch_name = options[:branch] || nil - @base_path = @branch_name ? File.join(@base_path, @branch_name) : @base_path + # @base_path = @branch_name ? File.join(@base_path, @branch_name) : @base_path unless Dir.exists?(@base_path) exit_now! <<-EOS.strip_heredoc - No such directory `#{@base_path}`. Please make sure that the `base_path` or a branch name is properly set. + No such directory `#{@base_path}`. Please make sure that the `base_path` is properly set. EOS end @preserve_hierarchy = false if @config['preserve_hierarchy'] @@ -1200,10 +1200,10 @@ base_url = @config['base_url'] || 'https://api.crowdin.com' @crowdin = Crowdin::API.new(api_key: @config['api_key'], project_id: @config['project_identifier'], base_url: base_url) begin - @crowdin.project_info + @project_info = @crowdin.project_info rescue Crowdin::API::Errors::Error => err raise err rescue exit_now!("Seems Crowdin server API URL is not valid. Please check the `base_url` parameter in the configuration file.") end