Skip to content
This repository was archived by the owner on Oct 11, 2025. It is now read-only.

Commit ce988b0

Browse files
author
Tuxx
committed
Show usage by default with no parameters.
1 parent 5801a22 commit ce988b0

File tree

1 file changed

+39
-22
lines changed

1 file changed

+39
-22
lines changed

main.go

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package main
22

33
import (
44
"flag"
5+
"fmt"
6+
"log"
57
"os"
68
"path/filepath"
79
)
@@ -13,26 +15,46 @@ func main() {
1315

1416
lockScreen := flag.Bool("l", false, "Lock the screen immediately")
1517
flag.BoolVar(lockScreen, "lock", false, "Lock the screen immediately")
18+
19+
helpFlag := flag.Bool("h", false, "Display help information")
20+
flag.BoolVar(helpFlag, "help", false, "Display help information")
21+
debugExit := flag.Bool("debug-exit", false, "Enable exit with ESC or Q key (for debugging)")
1622

17-
debugExit := flag.Bool("debug-exit", false, "Enable exit with ESC or Q key (for debugging)")
18-
19-
// Add debug mode flag
20-
debugMode := flag.Bool("log", false, "Enable debug logging")
23+
// Add debug mode flag
24+
debugMode := flag.Bool("log", false, "Enable debug logging")
25+
26+
// Set custom usage output
27+
flag.Usage = func() {
28+
fmt.Fprintf(os.Stderr, "FancyLock: A media-playing screen locker\n\n")
29+
fmt.Fprintf(os.Stderr, "Usage: %s [options]\n\n", os.Args[0])
30+
fmt.Fprintf(os.Stderr, "Options:\n")
31+
flag.PrintDefaults()
32+
fmt.Fprintf(os.Stderr, "\nExamples:\n")
33+
fmt.Fprintf(os.Stderr, " %s -l # Lock screen immediately\n", os.Args[0])
34+
fmt.Fprintf(os.Stderr, " %s -c /path/to/config # Use specific config file\n", os.Args[0])
35+
}
2136

2237
flag.Parse()
2338

24-
// Initialize the logger
25-
if *debugMode {
26-
InitLogger(LevelDebug, true)
27-
Debug("Debug logging enabled")
28-
} else {
29-
InitLogger(LevelError, false)
39+
// Initialize the logger
40+
if *debugMode {
41+
InitLogger(LevelDebug, true)
42+
Debug("Debug logging enabled")
43+
} else {
44+
InitLogger(LevelError, false)
45+
}
46+
47+
// Show help if explicitly requested or if no arguments provided and no action flags set
48+
if *helpFlag || (flag.NFlag() == 0 && !*lockScreen) {
49+
flag.Usage()
50+
return
3051
}
3152

3253
// Load default configuration
3354
config := DefaultConfig()
3455
config.LockScreen = *lockScreen
35-
config.DebugExit = *debugExit
56+
config.DebugExit = *debugExit
57+
3658

3759
// Try to find and load config file
3860
if *configPath == "" {
@@ -42,7 +64,7 @@ func main() {
4264
defaultConfigPath := filepath.Join(homeDir, ".config", "fancylock", "config.json")
4365
if _, err := os.Stat(defaultConfigPath); err == nil {
4466
// Default config exists, use it
45-
Info("Using default config file: %s", defaultConfigPath)
67+
log.Printf("Using default config file: %s", defaultConfigPath)
4668
*configPath = defaultConfigPath
4769
}
4870
}
@@ -52,37 +74,32 @@ func main() {
5274
if *configPath != "" {
5375
err := LoadConfig(*configPath, &config)
5476
if err != nil {
55-
Error("loading config: %v", err)
77+
log.Printf("Error loading config: %v", err)
5678
// Continue with default config
5779
}
5880
}
5981

6082
// Initialize display server detection
6183
displayServer := DetectDisplayServer()
62-
Info("Detected display server: %s\n", displayServer)
84+
fmt.Printf("Detected display server: %s\n", displayServer)
6385

6486
// Initialize the screen locker based on display server
6587
var locker ScreenLocker
6688

6789
switch displayServer {
6890
case "wayland":
6991
// We'll implement Wayland support later
70-
Fatal("Wayland support not yet implemented")
92+
log.Fatalf("Wayland support not yet implemented")
7193
case "x11":
7294
locker = NewX11Locker(config)
7395
default:
74-
Fatal("Unsupported display server: %s", displayServer)
96+
log.Fatalf("Unsupported display server: %s", displayServer)
7597
}
7698

7799
// If -l/--lock flag is set, lock immediately
78100
if config.LockScreen {
79101
if err := locker.Lock(); err != nil {
80-
Fatal("Failed to lock screen: %v", err)
81-
}
82-
} else {
83-
// Otherwise start in screensaver/idle monitor mode
84-
if err := locker.StartIdleMonitor(); err != nil {
85-
Fatal("Failed to start idle monitor: %v", err)
102+
log.Fatalf("Failed to lock screen: %v", err)
86103
}
87104
}
88105
}

0 commit comments

Comments
 (0)