Class: XcodeYamlizer::Cli

Inherits:
Object
  • Object
show all
Defined in:
lib/xcode-yamlizer/cli.rb

Constant Summary collapse

HOOK_PATHS =
{
  "pre-commit-hook" =>'.git/hooks/pre-commit',
  "post-merge-hook" =>'.git/hooks/post-merge-hook',
}

Instance Method Summary collapse

Instance Method Details

#answered_yes?(answer) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/xcode-yamlizer/cli.rb', line 10

def answered_yes?(answer)
  answer =~ /y\n/i || answer == "\n"
end

#ask_to_overwrite(hook_name) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/xcode-yamlizer/cli.rb', line 27

def ask_to_overwrite(hook_name)
  puts "xcode-yamlizer: WARNING There is already a #{hook_name} installed in this git repo."
  print "Would you like to overwrite it? [Yn] "
  answer = $stdin.gets

  if answered_yes?(answer)
    FileUtils.rm(HOOK_PATHS[hook_name])
  else
    puts "Not overwriting existing hook: #{HOOK_PATHS[hook_name]}"
    puts
    exit(1)
  end
end

#install(hook_name) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/xcode-yamlizer/cli.rb', line 19

def install(hook_name)
  if File.exists?(HOOK_PATHS[hook_name])
    ask_to_overwrite hook_name
  end

  install_hook hook_name
end

#install_allObject



14
15
16
17
18
# File 'lib/xcode-yamlizer/cli.rb', line 14

def install_all
  HOOK_PATHS.each_key do |key|
    install key
  end
end

#install_hook(hook_name) ⇒ Object



41
42
43
44
45
# File 'lib/xcode-yamlizer/cli.rb', line 41

def install_hook (hook_name)
  hook = File.join(XcodeYamlizer.root, 'templates', hook_name)
  FileUtils.cp(hook, HOOK_PATHS[hook_name])
  FileUtils.chmod(0755, HOOK_PATHS[hook_name])
end