Sha256: d2dec5d1798dfc628b28dbb88946a6e10d60eb93d4c0b6160ebb924ce2be56e9

Contents?: true

Size: 885 Bytes

Versions: 1

Compression:

Stored size: 885 Bytes

Contents

require 'forwardable'

module PGit
  class Command
    class Add
      extend Forwardable
      def_delegators :@app, :commands, :command, :args, :global_opts, :opts, :current_project
      def_delegators :command, :name

      def initialize(app)
        @app = app
      end

      def execute!
        check_command_exists_for_add

        command.save!
        display_success_msg(:added, :to)
      end

      private

      def exists?
        commands.find { |c| c.name == name }
      end

      def display_success_msg(event, preposition)
        puts "Successfully #{event} command '#{name}' #{preposition} the current project!"
      end

      def check_command_exists_for_add
        raise PGit::Error::User.new "Command '#{name}' already exists in the current project. If you want to update the command, see `pgit cmd edit --help`" if exists?
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pgit-1.0.0 lib/pgit/command/add.rb