feat(bonfire): add FlagBool and read every bare switch with it (IN-04, quick-261028-rqd)

This commit is contained in:
Jakub Zych
2026-10-28 20:32:38 +01:00
parent e34d113c80
commit 795c4f6b29
15 changed files with 86 additions and 54 deletions

View File

@@ -3,6 +3,7 @@ package bonfire
import (
"context"
"errors"
"strconv"
"strings"
"github.com/spf13/cobra"
@@ -134,6 +135,23 @@ func (in cobraInput) Flag(name string) (string, bool) {
return val, true
}
// FlagBool reports whether the bare switch name is on: the flag is set and
// its value parses with strconv.ParseBool as true (--name, --name=true,
// --name=1, --name=t, TRUE, True). Unset, empty and unparsable values
// (--name=yes) are false, and a nil Input has no flags. Read every Bare
// flag with it, so --json=1 works like --json.
func FlagBool(in Input, name string) bool {
if in == nil {
return false
}
v, ok := in.Flag(name)
if !ok {
return false
}
on, err := strconv.ParseBool(v)
return err == nil && on
}
func validCommandName(name string) bool {
switch name {
case "build", "dev", "new", "serve", "migrate":