add debug mode and update readme

This commit is contained in:
Lunny Xiao
2025-08-26 11:57:12 -07:00
parent 8876fe3cb8
commit e3ecf9b94a
5 changed files with 114 additions and 54 deletions

View File

@ -17,6 +17,7 @@ import (
"time"
"code.gitea.io/sdk/gitea"
"code.gitea.io/tea/modules/debug"
"code.gitea.io/tea/modules/theme"
"code.gitea.io/tea/modules/utils"
"github.com/charmbracelet/huh"
@ -277,6 +278,9 @@ func (l *Login) Client(options ...gitea.ClientOption) *gitea.Client {
}
options = append(options, gitea.SetToken(l.Token), gitea.SetHTTPClient(httpClient))
if debug.IsDebug() {
options = append(options, gitea.SetDebugMode())
}
if ok, err := utils.IsKeyEncrypted(l.SSHKey); ok && err == nil && l.SSHPassphrase == "" {
if err := huh.NewInput().

40
modules/debug/debug.go Normal file
View File

@ -0,0 +1,40 @@
// 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
func IsDebug() bool {
return debug
}
func SetDebug(on bool) {
debug = on
}
func Printf(info string, args ...any) {
if debug {
fmt.Printf("DEBUG: "+info+"\n", args...)
}
}
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
},
}
}