File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package main
22
33import (
44 "encoding/base64"
5+ "flag"
56 "fmt"
67 "os"
78 "time"
@@ -11,13 +12,18 @@ import (
1112)
1213
1314func 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
You can’t perform that action at this time.
0 commit comments