Class: Gitty::HookCommand::Install

Inherits:
Runner show all
Includes:
FileUtils
Defined in:
lib/gitty/commands/install.rb

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) ⇒ Install

Returns a new instance of Install.



3
4
5
6
# File 'lib/gitty/commands/install.rb', line 3

def initialize(args, stdout = STDOUT, stderr = STDERR)
  super
  @hookname = args.shift
end

Instance Method Details

#option_parserObject



18
19
20
21
22
# File 'lib/gitty/commands/install.rb', line 18

def option_parser
  @option_parser ||= super.tap do |opts|
    opts.banner = "Usage: git hook install [opts] hook-name"
  end
end

#runObject



8
9
10
11
12
13
14
15
16
# File 'lib/gitty/commands/install.rb', line 8

def run
  hook = Gitty::Hook.find(@hookname, :installed => false)
  if hook.nil?
    stderr.puts "no hook named '#{@hookname}' found."
    exit 1
  end
  hook.install(:local)
  stdout.puts "#hook #{hook.name} has been installed."
end