class GitSmart

Public Class Methods

commands() click to toggle source
# File lib/git-smart/git_smart.rb, line 25
def self.commands
  @commands ||= {}
end
register(code, &blk) click to toggle source

Used like this: GitSmart.register ‘my-command’ do |repo, args|

# File lib/git-smart/git_smart.rb, line 19
def self.register(code, &blk)
  commands[code] = lambda { |args|
    ExecutionContext.new.instance_exec(GitRepo.new("."), args, &blk)
  }
end
run(code, args) click to toggle source
# File lib/git-smart/git_smart.rb, line 2
def self.run(code, args)
  lambda = commands[code]
  if lambda
    begin
      lambda.call(args)
    rescue GitSmart::Exception => e
      if e.message && !e.message.empty?
        puts e.message.red
      end
    end
  else
    puts "No command #{code.inspect} defined! Available commands are #{commands.keys.sort.inspect}"
  end
end