Skip to content

Commit f08d031

Browse files
committed
feat: require explicit subcommands and update usage documentation
- Add usage instructions for version, help, and server commands - Update documentation and examples to use the server subcommand when running the application - Change Dockerfile to start the server using the server subcommand - Implement subcommand parsing in main.go, requiring an explicit command to start the server - Add a usage/help function to display available commands and options Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
1 parent 3c8d64c commit f08d031

File tree

4 files changed

+52
-8
lines changed

4 files changed

+52
-8
lines changed

CLAUDE.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ AuthGate is an OAuth 2.0 Device Authorization Grant (RFC 8628) server built with
1313
make build # Build to bin/authgate with version info in LDFLAGS
1414

1515
# Run
16-
./bin/authgate # Run after make build
16+
./bin/authgate -v # Show version information
17+
./bin/authgate -h # Show help
18+
./bin/authgate server # Start the OAuth server
1719

1820
# Test & Lint
1921
make test # Run tests with coverage report (outputs coverage.txt)

README.md

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
- [Docker Features](#docker-features)
2424
- [Docker Compose Example](#docker-compose-example)
2525
- [Test with the Example CLI](#test-with-the-example-cli)
26+
- [User Interface](#user-interface)
27+
- [1. Login Page](#1-login-page)
28+
- [2. Device Authorization Page](#2-device-authorization-page)
29+
- [3. Authorization Success](#3-authorization-success)
2630
- [How It Works](#how-it-works)
2731
- [Device Flow Sequence](#device-flow-sequence)
2832
- [Key Endpoints](#key-endpoints)
@@ -180,11 +184,18 @@ go build -o bin/authgate .
180184
### Run the Server
181185

182186
```bash
183-
# After make build
184-
./bin/authgate
187+
# Show version information
188+
./bin/authgate -v
189+
./bin/authgate --version
190+
191+
# Show help
192+
./bin/authgate -h
193+
194+
# Start the server
195+
./bin/authgate server
185196

186197
# Or directly with Go
187-
go run .
198+
go run . server
188199
```
189200

190201
The server will start on `http://localhost:8080` by default.
@@ -665,7 +676,7 @@ After=network.target
665676
Type=simple
666677
User=authgate
667678
WorkingDirectory=/var/lib/authgate
668-
ExecStart=/usr/local/bin/authgate
679+
ExecStart=/usr/local/bin/authgate server
669680
Restart=on-failure
670681
RestartSec=10
671682
@@ -880,7 +891,7 @@ db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{})
880891
Enable debug logging by setting Gin to debug mode:
881892

882893
```bash
883-
GIN_MODE=debug ./bin/authgate
894+
GIN_MODE=debug ./bin/authgate server
884895
```
885896

886897
---

docker/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ VOLUME ["/app/data"]
3838
# Set default environment
3939
ENV DATABASE_PATH=/app/data/oauth.db
4040

41-
CMD ["/bin/authgate"]
41+
CMD ["/bin/authgate", "server"]

main.go

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"embed"
66
"flag"
7+
"fmt"
78
"html/template"
89
"io/fs"
910
"log"
@@ -31,9 +32,10 @@ var templatesFS embed.FS
3132
var staticFS embed.FS
3233

3334
func main() {
34-
// Parse command line flags
35+
// Define flags
3536
showVersion := flag.Bool("version", false, "Show version information")
3637
flag.BoolVar(showVersion, "v", false, "Show version information (shorthand)")
38+
flag.Usage = printUsage
3739
flag.Parse()
3840

3941
// Show version and exit if requested
@@ -42,6 +44,35 @@ func main() {
4244
os.Exit(0)
4345
}
4446

47+
// Check if command is provided
48+
args := flag.Args()
49+
if len(args) == 0 {
50+
printUsage()
51+
os.Exit(1)
52+
}
53+
54+
// Handle subcommands
55+
switch args[0] {
56+
case "server":
57+
runServer()
58+
default:
59+
fmt.Printf("Unknown command: %s\n\n", args[0])
60+
printUsage()
61+
os.Exit(1)
62+
}
63+
}
64+
65+
func printUsage() {
66+
fmt.Printf("Usage: %s [OPTIONS] COMMAND\n\n", os.Args[0])
67+
fmt.Println("OAuth 2.0 Device Authorization Grant server")
68+
fmt.Println("\nCommands:")
69+
fmt.Println(" server Start the OAuth server")
70+
fmt.Println("\nOptions:")
71+
fmt.Println(" -v, --version Show version information")
72+
fmt.Println(" -h, --help Show this help message")
73+
}
74+
75+
func runServer() {
4576
// Load configuration
4677
cfg := config.Load()
4778

0 commit comments

Comments
 (0)