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

@@ -82,7 +82,7 @@ func adminCreate(ctx context.Context, app *backpack.App, in bonfire.Input, out b
login = email
}
roleCode := strings.TrimSpace(flagValue(in, "role"))
superuser := flagValue(in, "superuser") == "true"
superuser := bonfire.FlagBool(in, "superuser")
return withAdminDB(ctx, app, func(gdb *gorm.DB) error {
return gdb.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
roleID, err := roleIDByCode(tx, roleCode)

View File

@@ -147,7 +147,7 @@ func adminTokenCreate(ctx context.Context, app *backpack.App, in bonfire.Input,
if details != nil {
return fmt.Errorf("cabana: %s", firstDetail(details))
}
if flagValue(in, "json") == "true" && row != nil {
if bonfire.FlagBool(in, "json") && row != nil {
return printJSON(out, map[string]any{
"id": row.ID,
"name": row.Name,
@@ -163,7 +163,7 @@ func adminTokenCreate(ctx context.Context, app *backpack.App, in bonfire.Input,
func adminTokenList(ctx context.Context, app *backpack.App, in bonfire.Input, out bonfire.Output) error {
identifier := argValue(in, "identifier")
showRevoked := flagValue(in, "revoked") == "true"
showRevoked := bonfire.FlagBool(in, "revoked")
return withAdminDB(ctx, app, func(gdb *gorm.DB) error {
q := gdb.WithContext(ctx).Model(&BackendAPIToken{}).Order("created_at DESC").Order("id DESC")
if identifier != "" {
@@ -214,7 +214,7 @@ func adminTokenList(ctx context.Context, app *backpack.App, in bonfire.Input, ou
formatTimePtr(row.RevokedAt),
})
}
if flagValue(in, "json") == "true" {
if bonfire.FlagBool(in, "json") {
return printJSON(out, list)
}
out.Table(headers, table)
@@ -296,7 +296,7 @@ func adminTokenScopes(ctx context.Context, app *backpack.App, in bonfire.Input,
"permissions": permissions,
})
}
if flagValue(in, "json") == "true" {
if bonfire.FlagBool(in, "json") {
return printJSON(out, list)
}
out.Table(headers, rows)