feat(cli): add global pretend quiet and dry-run alias

This commit is contained in:
Micheal Wilkinson
2026-03-20 18:09:54 +00:00
parent 7f8a5d24e3
commit ad8ec1bd6c
3 changed files with 50 additions and 11 deletions

View File

@@ -14,6 +14,8 @@ import (
)
func Run(args []string, stdout io.Writer, stderr io.Writer) int {
model := &cliModel{}
app, err := core.New(stdout, stderr)
if err != nil {
_, _ = fmt.Fprintf(stderr, "error: %v\n", err)
@@ -21,7 +23,7 @@ func Run(args []string, stdout io.Writer, stderr io.Writer) int {
}
parser, err := kong.New(
&cliModel{},
model,
kong.Name(programName()),
kong.Description("Your home is your castle. Don't leave your precious dotfiles behind."),
kong.Writers(stdout, stderr),
@@ -51,6 +53,9 @@ func Run(args []string, stdout io.Writer, stderr io.Writer) int {
return 1
}
app.Quiet = model.Quiet
app.Pretend = model.Pretend || model.DryRun
if err := ctx.Run(app); err != nil {
var exitErr *cliExitError
if errors.As(err, &exitErr) {
@@ -64,6 +69,10 @@ func Run(args []string, stdout io.Writer, stderr io.Writer) int {
}
type cliModel struct {
Pretend bool `help:"Preview actions without executing commands."`
DryRun bool `name:"dry-run" help:"Alias for --pretend."`
Quiet bool `help:"Suppress status output."`
Clone cloneCmd `cmd:"" help:"Clone a castle."`
List listCmd `cmd:"" help:"List castles."`
ShowPath showPathCmd `cmd:"" name:"show_path" help:"Show the path of a castle."`