Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
var (
version = "v1.1.0"
help = flag.Bool("help", false, "Show help message.")
debug = flag.Bool("debug", false, "Print debug messages.")

Check failure on line 22 in main.go

View workflow job for this annotation

GitHub Actions / golangci-all-codebase

File is not properly formatted (gci)

Check failure on line 22 in main.go

View workflow job for this annotation

GitHub Actions / golangci-updated-code

File is not properly formatted (gci)
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.")
Expand All @@ -41,11 +42,11 @@
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()
Expand All @@ -54,7 +55,9 @@
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()
Expand Down
11 changes: 10 additions & 1 deletion utils/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
}
Loading