(stdin io.Reader, repo *repo.Repo, shimPath string)
| 72 | } |
| 73 | |
| 74 | func promptForInstallShim(stdin io.Reader, repo *repo.Repo, shimPath string) (bool, error) { |
| 75 | _, err := os.Stat(path.Join(repo.Root, shimPath)) |
| 76 | exists := true |
| 77 | if os.IsNotExist(err) { |
| 78 | exists = false |
| 79 | } else if err != nil { |
| 80 | return false, err |
| 81 | } |
| 82 | |
| 83 | var message string |
| 84 | if exists { |
| 85 | message = fmt.Sprintf("Overwrite existing file %v?", shimPath) |
| 86 | } else { |
| 87 | message = fmt.Sprintf("Create file %v?", shimPath) |
| 88 | } |
| 89 | |
| 90 | scanner := bufio.NewScanner(stdin) |
| 91 | for { |
| 92 | fmt.Printf("%v [yn] ", message) |
| 93 | |
| 94 | if !scanner.Scan() { |
| 95 | return false, scanner.Err() |
| 96 | } |
| 97 | reply := strings.ToLower(scanner.Text()) |
| 98 | if len(reply) == 0 { |
| 99 | continue |
| 100 | } |
| 101 | |
| 102 | switch reply[0] { |
| 103 | case 'y': |
| 104 | return true, nil |
| 105 | case 'n': |
| 106 | return false, nil |
| 107 | default: |
| 108 | continue |
| 109 | } |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | func installShim(repo *repo.Repo, shimPath, quickhook, hook string, prompt bool) error { |
| 114 | command, err := shimCommandForHook(quickhook, hook) |
no outgoing calls