cmd/headscale/cli: add confirmAction helper for force/prompt patterns

Centralise the repeated force-flag-check + YesNo-prompt logic into a
single confirmAction(cmd, prompt) helper.  Callers still decide what
to return on decline (error, message, or nil).
This commit is contained in:
Kristoffer Dalby 2026-02-18 14:51:42 +00:00
parent 7b7b270126
commit 6c08b49d63
4 changed files with 36 additions and 130 deletions

View file

@ -221,6 +221,17 @@ func printOutput(cmd *cobra.Command, result any, override string) error {
return nil
}
// confirmAction returns true when the user confirms a prompt, or when
// --force is set. Callers decide what to do when it returns false.
func confirmAction(cmd *cobra.Command, prompt string) bool {
force, _ := cmd.Flags().GetBool("force")
if force {
return true
}
return util.YesNo(prompt)
}
// printListOutput checks the --output flag: when a machine-readable format is
// requested it serialises data as JSON/YAML; otherwise it calls renderTable
// to produce the human-readable pterm table.