lib/site_hook/deprecate.rb in site_hook-0.8.2 vs lib/site_hook/deprecate.rb in site_hook-0.9.3

- old
+ new

@@ -1,25 +1,48 @@ +require 'paint/util' module SiteHook + + class DeprecationError < SiteHookError + def initialize(msg) + super(msg, 99) + end + end class Deprecation - attr_reader :instructions - def initialize(message, situation, instructions) - @str = "▼▼▼ [#{Paint['DEPRECATION ERROR', :red, :bold]}] —— The following situation is deprecated! ▼▼▼" - @situation = situation - @str << "\n#{@situation}" - @instructions = instructions - @str << "\n#{@instructions}" + + def self.deprecate(command, situation, instructions, continue) + @@exe_name = command.topmost_ancestor.parent.exe_name + @@str = "▼▼▼ [#{Paint['DEPRECATION ERROR', 'red', :bold]}] —— #{Paint['The following situation is deprecated', 'yellow', :bold, :blink]}! ▼▼▼" + @@situation = situation + @@str << "\n#{@@situation}" + @@instructions = instructions + @@str << "\n#{@@instructions}" + + return {msg: @@str, exit: !continue} end - def self.deprecate(situation, instructions, continue) - puts @str if @str - return continue + def self.deprecate_config(command) + return self.deprecate( + command, + "'#{Paint[SiteHook::Paths.old_config.to_s, 'red']}' is deprecated in favor of '#{Paint[SiteHook::Paths.config, 'green']}'", + <<~INSTRUCT, + Please run `#{Paint["#{command.topmost_ancestor.parent.exe_name} config upgrade-shrc", 'red', :blink]}` to rectify this. + Once version 1.0.0 is released, '#{Paint["#{SiteHook::Paths.config}", 'green']}' will + be the only config file option, and '#{Paint["#{SiteHook::Paths.old_config}", 'orange']}' will not be allowed. + any existance of '#{Paint["#{Dir.home}/.jph", 'red']}' after the #{Paint['1.0.0', :bold]} release will result in an Exception being raised. + #{"#{Paint['Once the exception is raised', 'red']}, site_hook will #{Paint['exit', 'red']} and return a #{Paint['99', 'red']} status code."} + INSTRUCT + true + ) end + def self.raise_error(msg) + raise DeprecationError.new(msg) + end end class NotImplemented attr_reader :command_object def initialize(command) @command_object = command - @exe_name = @command_object.parent.parent.exe_name + @exe_name = @command_object.topmost_ancestor.parent.exe_name @output_string = "Command `#{@exe_name} #{command.name_for_help.join(' ')}" end def self.declare(command) instance = self.new(command) instance.instance_variable_set(