Class: Gitty::HookCommand

Inherits:
Runner show all
Defined in:
lib/gitty/hook_command.rb

Defined Under Namespace

Classes: Init, Install, List, Publish, Share, Shell, Show, Uninstall

Constant Summary collapse

COMMANDS =
%w[
  init
  list
  share
  show
  install
  uninstall
  publish
  shell
]

Instance Attribute Summary

Attributes inherited from Runner

#args, #stderr, #stdout

Instance Method Summary collapse

Methods inherited from Runner

#handle_show_help, #options, run

Constructor Details

#initialize(args, stdout = STDOUT, stderr = STDERR) ⇒ HookCommand

Returns a new instance of HookCommand.



16
17
18
19
20
21
22
23
# File 'lib/gitty/hook_command.rb', line 16

def initialize(args, stdout = STDOUT, stderr = STDERR)
  @args, @stdout, @stderr = args, stdout, stderr
  if COMMANDS.include?(args.first)
    @target = Gitty::HookCommand.const_get(args.shift.classify).new(args, stdout, stderr)
  else
    parse_args!
  end
end

Instance Method Details

#option_parserObject



25
26
27
28
29
# File 'lib/gitty/hook_command.rb', line 25

def option_parser
  @option_parser ||= super.tap do |opts|
    opts.banner = "Usage: git hook [command]\nCommands are: #{COMMANDS.join(', ')}"
  end
end

#parse_args!Object



39
40
41
42
43
# File 'lib/gitty/hook_command.rb', line 39

def parse_args!
  opt_p = option_parser
  opt_p.parse!(args)
  puts opt_p
end

#runObject



31
32
33
34
35
36
37
# File 'lib/gitty/hook_command.rb', line 31

def run
  unless File.directory?(".git")
    stderr.puts "You must run git hook from the root of a git repository"
    exit 1
  end
  @target && @target.run
end