1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
// Copyright 2025 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package debug
import (
"context"
"fmt"
"github.com/urfave/cli/v3"
)
var debug bool
// IsDebug returns true if debug mode is enabled
func IsDebug() bool {
return debug
}
// SetDebug sets the debug mode
func SetDebug(on bool) {
debug = on
}
// Printf prints debug information if debug mode is enabled
func Printf(info string, args ...any) {
if debug {
fmt.Printf("DEBUG: "+info+"\n", args...)
}
}
// CliFlag returns the CLI flag for debug mode
func CliFlag() cli.Flag {
return &cli.BoolFlag{
Name: "debug",
Aliases: []string{"vvv"},
Usage: "Enable debug mode",
Value: false,
Action: func(ctx context.Context, cmd *cli.Command, v bool) error {
SetDebug(v)
return nil
},
}
}
|