Sha256: e09f3cefb1166c2ec398997c5b91ffaa047567e681d214ad2d4b202587c3a69b

Contents?: true

Size: 1.24 KB

Versions: 5

Compression:

Stored size: 1.24 KB

Contents

# rubocop:disable Naming/FileName
# rubocop:enable Naming/FileName
# frozen_string_literal: true

module EasyCommand
  class Result
    module ClassMethods
      def [](*args, **kwargs)
        new(*args, **kwargs)
      end
    end
    extend ClassMethods
  end

  module ClassMethods
    def call(*args, **kwargs)
      new(*args, **kwargs).call
    end
  end

  def abort(*args, **kwargs)
    errors.add(*args, **kwargs)
    raise ExitError
  end

  module LegacyErrorHandling
    # Convenience/retrocompatibility aliases
    def self.errors_legacy_alias(method, errors_method)
      define_method method do |*args, **kwargs|
        warn "/!\\ #{method} is deprecated, please use errors.#{errors_method} instead."
        errors.__send__ errors_method, *args, **kwargs
      end
    end
  end

  def assert_subcommand(klass, *args, **kwargs)
    command_instance = klass.new(*args, **kwargs).as_sub_command
    (@sub_commands ||= []) << command_instance
    command = command_instance.call
    return command.result if command.success?
    errors.merge_from(command)
    raise ExitError.new(result: command.result)
  end

  def assert_sub(...)
    warn "/!\\ 'assert_sub' is deprecated, please use 'assert_subcommand' instead."
    assert_subcommand(...)
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
easy_command-1.0.1 lib/easy_command/ruby-3-specific.rb
easy_command-1.0.0 lib/easy_command/ruby-3-specific.rb
easy_command-1.0.0.pre.rc3 lib/easy_command/ruby-3-specific.rb
easy_command-1.0.0.pre.rc2 lib/easy_command/ruby-3-specific.rb
easy_command-1.0.0.pre.rc1 lib/easy_command/ruby-3-specific.rb