mirror of
				https://gitea.com/gitea/tea.git
				synced 2025-11-03 18:55:26 +01:00 
			
		
		
		
	add debug mode and update readme (#805)
Fix #456 Fix #207 Reviewed-on: https://gitea.com/gitea/tea/pulls/805
This commit is contained in:
		
							
								
								
									
										44
									
								
								modules/debug/debug.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										44
									
								
								modules/debug/debug.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,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
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user