Method: WebTranslateIt::CommandLine#rm
- Defined in:
- lib/web_translate_it/command_line.rb
#rm ⇒ Object
rubocop:todo Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/MethodLength, Metrics/PerceivedComplexity
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/web_translate_it/command_line.rb', line 177 def rm # rubocop:todo Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/MethodLength, Metrics/PerceivedComplexity complete_success = true $stdout.sync = true if parameters == [] puts StringUtil.failure('Error: You must provide the path to the master file to remove.') puts 'Usage: wti rm path/to/master_file_1 path/to/master_file_2 ...' exit end WebTranslateIt::Connection.new(configuration.api_key) do |http| # rubocop:todo Metrics/BlockLength parameters.each do |param| next unless Util.ask_yes_no("Are you sure you want to delete the master file #{param}?\nThis will also delete its target files and translations.", false) files = configuration.files.find_all { |file| file.file_path == param } if files.any? files.each do |master_file| master_file.delete(http) # delete files if File.exist?(master_file.file_path) success = File.delete(master_file.file_path) puts StringUtil.success("Deleted 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) puts StringUtil.success("Deleted target file #{target_file.file_path}.") if success else puts StringUtil.failure("Target file #{target_file.file_path} doesn’t exist locally") end complete_success = false unless success end end puts StringUtil.success('All done.') if complete_success else puts StringUtil.failure("#{param}: File doesn’t exist on project.") end end end complete_success end |