(inv *serpent.Invocation, shell completion.Shell)
| 71 | } |
| 72 | |
| 73 | func installCompletion(inv *serpent.Invocation, shell completion.Shell) error { |
| 74 | path, err := shell.InstallPath() |
| 75 | if err != nil { |
| 76 | cliui.Error(inv.Stderr, fmt.Sprintf("Failed to determine completion path %v", err)) |
| 77 | return shell.WriteCompletion(inv.Stdout) |
| 78 | } |
| 79 | if !isTTYOut(inv) { |
| 80 | return shell.WriteCompletion(inv.Stdout) |
| 81 | } |
| 82 | choice, err := cliui.Select(inv, cliui.SelectOptions{ |
| 83 | Options: []string{ |
| 84 | "Confirm", |
| 85 | "Print to terminal", |
| 86 | }, |
| 87 | Message: fmt.Sprintf("Install completion for %s at %s?", shell.Name(), path), |
| 88 | HideSearch: true, |
| 89 | }) |
| 90 | if err != nil { |
| 91 | return err |
| 92 | } |
| 93 | if choice == "Print to terminal" { |
| 94 | return shell.WriteCompletion(inv.Stdout) |
| 95 | } |
| 96 | return completion.InstallShellCompletion(shell) |
| 97 | } |
no test coverage detected