Skip to content

Commit 81585af

Browse files
綾人綾人
authored andcommitted
support output file name with -o option
1 parent 5cfe69c commit 81585af

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

cmd/cli/main.go

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

33
import (
44
"encoding/base64"
5+
"flag"
56
"fmt"
67
"os"
78
"time"
@@ -11,13 +12,18 @@ import (
1112
)
1213

1314
func main() {
14-
// Get code from command line arguments
15-
if len(os.Args) < 2 {
16-
fmt.Println("Usage: go run main.go '<code string>'")
15+
// Define command line options
16+
output := flag.String("o", "generated_code.png", "Output file name")
17+
flag.Parse()
18+
19+
// Get remaining arguments (non-optional)
20+
args := flag.Args()
21+
if len(args) < 1 {
22+
fmt.Println("Usage: snapcode [-o output.png] '<code string>'")
1723
os.Exit(1)
1824
}
1925

20-
code := os.Args[1]
26+
code := args[0]
2127

2228
// Browser Launch
2329
launchURL := launcher.New().Headless(true).MustLaunch()
@@ -36,10 +42,9 @@ func main() {
3642

3743
// Only the pre element is scrubbed.
3844
pre := page.MustElement("pre")
39-
outputFile := "generated_code.png"
40-
pre.MustScreenshot(outputFile)
45+
pre.MustScreenshot(*output)
4146

42-
fmt.Println("Screenshot saved:", outputFile)
47+
fmt.Println("Saved screenshot to:", *output)
4348
}
4449

4550
// Generate an HTML template from the given code string

0 commit comments

Comments
 (0)