Method: WebTranslateIt::CommandLine#mv
- Defined in:
- lib/web_translate_it/command_line.rb
#mv ⇒ Object
rubocop:todo Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/MethodLength, Metrics/PerceivedComplexity
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 |
# File 'lib/web_translate_it/command_line.rb', line 218 def mv # rubocop:todo Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/MethodLength, Metrics/PerceivedComplexity complete_success = true $stdout.sync = true if parameters.count != 2 puts StringUtil.failure('Error: You must provide the source path and destination path of the master file to move.') puts 'Usage: wti mv path/to/master_file_old_path path/to/master_file_new_path ...' exit end source = parameters[0] destination = parameters[1] WebTranslateIt::Connection.new(configuration.api_key) do |http| if Util.ask_yes_no("Are you sure you want to move the master file #{source} and its target files?", true) configuration.files.find_all { |file| file.file_path == source }.each do |master_file| master_file.upload(http, false, false, nil, false, true, true, destination) # move master file if File.exist?(source) success = File.rename(source, destination) if File.exist?(source) puts StringUtil.success("Moved master file #{master_file.file_path}.") if success end complete_success = false unless success configuration.files.find_all { |file| file.master_id == master_file.id }.each do |target_file| if File.exist?(target_file.file_path) success = File.delete(target_file.file_path) complete_success = false unless success end end configuration.reload configuration.files.find_all { |file| file.master_id == master_file.id }.each do |target_file| success = target_file.fetch(http) complete_success = false unless success end puts StringUtil.success('All done.') if complete_success end end end complete_success end |