Sha256: ee96927eba4a58d91c088b7b8ddaa478300c7e3c9b1862639002ffd5451c62b6

Contents?: true

Size: 1.73 KB

Versions: 24

Compression:

Stored size: 1.73 KB

Contents

#!/usr/bin/env ruby
# frozen_string_literal: true

require "json"

old_command_name = ARGV[0]&.downcase
new_command_name = ARGV[1]&.downcase

abort("ERROR: Must provide old and new command names.") unless old_command_name && new_command_name

old_file_name = old_command_name.gsub(/[^A-Za-z]/, "_")
old_file_path = "#{__dir__}/../lib/command/#{old_file_name}.rb"

abort("ERROR: Command '#{old_command_name}' does not exist.") unless File.exist?(old_file_path)

new_file_name = new_command_name.gsub(/[^A-Za-z]/, "_")
new_file_path = "#{__dir__}/../lib/command/#{new_file_name}.rb"

abort("ERROR: Command '#{new_command_name}' already exists.") if File.exist?(new_file_path)

old_class_name = old_file_name.split("_").map(&:capitalize).join
new_class_name = new_file_name.split("_").map(&:capitalize).join

file_data = File.binread(old_file_path)
file_data.gsub!(old_class_name, new_class_name)
file_data.gsub!(old_command_name, new_command_name)
File.binwrite(new_file_path, file_data)
File.delete(old_file_path)

# Add old command name to deprecated commands
deprecated_commands_file_path = "#{__dir__}/../lib/deprecated_commands.json"
old_deprecated_commands_data = File.binread(deprecated_commands_file_path)
deprecated_commands = JSON.parse(old_deprecated_commands_data)
deprecated_commands = deprecated_commands.to_h do |current_old_command_name, current_new_command_name|
  if current_new_command_name == old_command_name
    [current_old_command_name, new_command_name]
  else
    [current_old_command_name, current_new_command_name]
  end
end
deprecated_commands[old_command_name] = new_command_name
new_deprecated_commands_data = "#{JSON.pretty_generate(deprecated_commands.sort.to_h)}\n"
File.binwrite(deprecated_commands_file_path, new_deprecated_commands_data)

Version data entries

24 entries across 24 versions & 2 rubygems

Version Path
cpflow-4.0.1 script/rename_command
cpflow-4.0.0 script/rename_command
cpflow-3.0.1 script/rename_command
cpflow-3.0.0 script/rename_command
cpl-2.2.4 script/rename_command
cpl-2.2.2 script/rename_command
cpl-2.2.1 script/rename_command
cpl-2.2.0 script/rename_command
cpl-1.4.0 script/rename_command
cpl-1.3.0 script/rename_command
cpl-1.2.0 script/rename_command
cpl-1.1.2 script/rename_command
cpl-1.1.2.rc.0 script/rename_command
cpl-1.1.1 script/rename_command
cpl-1.1.0 script/rename_command
cpl-1.0.4 script/rename_command
cpl-1.0.3 script/rename_command
cpl-1.0.2 script/rename_command
cpl-1.0.1 script/rename_command
cpl-1.0.0 script/rename_command