diff --git a/main.go b/main.go index 641dc05..8f8dc0f 100644 --- a/main.go +++ b/main.go @@ -19,6 +19,7 @@ import ( var ( version = "v1.1.0" help = flag.Bool("help", false, "Show help message.") + debug = flag.Bool("debug", false, "Print debug messages.") v = flag.Bool("v", false, "Show app version.") add = flag.Bool("a", false, "Add the following arg to the clipboard history.") copyInput = flag.Bool("c", false, "Copy the input to your systems clipboard.") @@ -41,11 +42,11 @@ func main() { flag.Parse() logPath, displayServer, imgEnabled, err := config.Init() utils.HandleError(err) - utils.SetUpLogger(logPath) + utils.SetUpLogger(logPath, *debug) switch { - case flag.NFlag() == 0: + case flag.NFlag() == 0 || (flag.NFlag() == 1 && *debug): if len(os.Args) > 2 { fmt.Println("Too many args provided. See usage:") flag.PrintDefaults() @@ -54,7 +55,9 @@ func main() { launchTUI() case flag.NFlag() > 1: - fmt.Printf("Too many flags provided. Use %s --help for more info.", os.Args[0]) + if !*debug || flag.NFlag() > 2 { + fmt.Printf("Too many flags provided. Use %s --help for more info.", os.Args[0]) + } case *help: flag.PrintDefaults() diff --git a/utils/logger.go b/utils/logger.go index 5e00037..51aa1c3 100644 --- a/utils/logger.go +++ b/utils/logger.go @@ -6,8 +6,11 @@ import ( ) var logger *log.Logger +var debugging = false + +func SetUpLogger(logFilePath string, debug bool) { + debugging = debug -func SetUpLogger(logFilePath string) { file, err := os.OpenFile(logFilePath, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666) if err != nil { log.Fatalf("Failed to open log file: %s", err) @@ -26,3 +29,9 @@ func LogINFO(message string) { func LogWARN(message string) { logger.Printf("WARN: %s", message) } + +func LogDEBUG(message string) { + if debugging { + logger.Printf("DEBUG: %s", message) + } +}