Call this function at the beginning of a command handler if you want to require the user to update their CLI first.
(cmd *cobra.Command, args []string)
| 116 | // Call this function at the beginning of a command handler |
| 117 | // if you want to require the user to update their CLI first. |
| 118 | func requireUpdated(cmd *cobra.Command, args []string) { |
| 119 | info := version.FromContext(cmd.Context()) |
| 120 | if info == nil { |
| 121 | if !promptToContinue( |
| 122 | "WARNING: Can't get version info", |
| 123 | "Unable to check whether your bootdev CLI is up to date.", |
| 124 | "Continue anyway?", |
| 125 | ) { |
| 126 | os.Exit(1) |
| 127 | } |
| 128 | return |
| 129 | } |
| 130 | if info.FailedToFetch != nil { |
| 131 | if !promptToContinue( |
| 132 | "WARNING: Can't get version info", |
| 133 | fmt.Sprintf("Unable to check whether your bootdev CLI is up to date: %s", info.FailedToFetch.Error()), |
| 134 | "Continue anyway?", |
| 135 | ) { |
| 136 | os.Exit(1) |
| 137 | } |
| 138 | return |
| 139 | } |
| 140 | if info.IsUpdateRequired { |
| 141 | info.PromptUpdateIfAvailable() |
| 142 | os.Exit(1) |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | func promptToContinue(title string, message string, prompt string) bool { |
| 147 | fmt.Fprintln(os.Stderr, title) |
nothing calls this directly
no test coverage detected