Class: GitHook::CLI

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/git_hook/cli.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ CLI

Returns a new instance of CLI.



12
13
14
15
16
17
# File 'lib/git_hook/cli.rb', line 12

def initialize(*args)
  super(*args)
  GitHook.io.tty = (options['no-color'] ? Thor::Shell::BasicShell.new : shell)
  GitHook.io.verbose!(true) if options['verbose']
  Dir.chdir(GitHook.repo_dir)
end

Class Method Details

.source_rootObject



25
26
27
# File 'lib/git_hook/cli.rb', line 25

def self.source_root
  Pathname.new(File.dirname(__FILE__)).join('template').to_s
end

Instance Method Details

#applyObject



42
43
44
45
46
47
48
49
50
51
# File 'lib/git_hook/cli.rb', line 42

def apply
  opts = {
    with_bundler: File.exist?('Gemfile')
  }
  config.hooks.keys.each do | timing |
    opts[:timing] = timing
    template('hook.tt', ".git/hooks/#{timing}", opts)
    chmod(".git/hooks/#{timing}", 0755)
  end
end

#installObject



30
31
32
33
34
35
36
37
38
39
# File 'lib/git_hook/cli.rb', line 30

def install
  opts = {
    with_bundler: File.exist?('Gemfile')
  }
  unless File.exist?('.githooks')
    template('githooks.tt', '.githooks', opts)
  end

  invoke(:apply)
end

#listObject



54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/git_hook/cli.rb', line 54

def list
  config.hooks.each_pair do | timing, hooks |
    say(timing, :blue)
    hooks.each do | hook |
      say("  #{hook[:class]}", :green, true)
      hook[:options].each_pair do | key, value |
        say(" " * 4 + key.to_s, :yellow, false)
        say(" : #{value}", nil, true)
      end
    end
  end
end

#test(timing, hook) ⇒ Object



68
69
70
71
72
# File 'lib/git_hook/cli.rb', line 68

def test(timing, hook)
  timing = timing.to_s.to_sym
  result = GitHook::Runner.invoke(timing, hook)
  say_status("success", "#{result}", :yellow)
end

#versionObject



20
21
22
# File 'lib/git_hook/cli.rb', line 20

def version
  GitHook.io.info("git-hook version #{GitHook::VERSION}")
end