summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordemo <demo@antix1>2026-05-30 22:43:19 -0400
committerdemo <demo@antix1>2026-05-30 22:43:19 -0400
commit4f7d3203e44fca492aadb075d03b8b90b99c66c8 (patch)
treeb0b5b2e8aae3f26b2ceaf3347c1bd48b5c96f733
parentedfd7022bc801c2eaa1a71a4c639f843c82dd44b (diff)
feat: use hamlet package to simplify command-line arguments
-rw-r--r--main.go51
1 files changed, 22 insertions, 29 deletions
diff --git a/main.go b/main.go
index 565a2c9..28c2d0d 100644
--- a/main.go
+++ b/main.go
@@ -10,6 +10,8 @@ import (
"runtime/pprof"
"strings"
"time"
+
+ "git.brandonirizarry.xyz/hamlet"
)
func main() {
@@ -36,11 +38,6 @@ func main() {
log.Fatalf("Invalid -c argument: %d", *maxConcurrency)
}
- startRawURL, err := chooseFrom(*urlArg, *shortcode, *shortcodeFilename)
- if err != nil {
- log.Fatal(err)
- }
-
if *maxURLs < 0 {
log.Fatalf("Invalid -max argument: %d", *maxURLs)
}
@@ -49,6 +46,26 @@ func main() {
log.Fatalf("Invalid -depth argument: %d", *maxDepth)
}
+ shortcodePresent := hamlet.New(*shortcode)
+ urlArgPresent := hamlet.New(*urlArg)
+ if hamlet.Iff(urlArgPresent, shortcodePresent).Assert() {
+ log.Fatal("Need exactly one of -url or -shortcode")
+ }
+
+ if !hamlet.If(hamlet.New(*shortcodeFilename), shortcodePresent).Assert() {
+ log.Fatal("-scfile implies use of -shortcode")
+ }
+
+ startRawURL := *urlArg
+
+ if shortcodePresent.Assert() {
+ var err error
+ startRawURL, err = getURLFromShortcode(*shortcodeFilename, *shortcode)
+ if err != nil {
+ log.Fatal(err)
+ }
+ }
+
startURL, err := convertToURL(startRawURL)
if err != nil {
log.Fatal(err)
@@ -61,30 +78,6 @@ func main() {
})
}
-// chooseFrom determines whether to use a -url or -shortcode
-// argument. If both are present or absent, an error is returned. If
-// exactly one is present, return that one.
-func chooseFrom(urlArg, shortcode, shortcodeFilename string) (string, error) {
- urlAbsent := (urlArg == "")
- shortcodeAbsent := (shortcode == "")
-
- if urlAbsent == shortcodeAbsent {
- messageSlug := "present"
-
- if urlAbsent {
- messageSlug = "missing; need exactly one"
- }
-
- return "", fmt.Errorf("-url and -shortcode flags both %s", messageSlug)
- }
-
- if urlAbsent {
- return getURLFromShortcode(shortcodeFilename, shortcode)
- }
-
- return urlArg, nil
-}
-
// convertToURL parses the given rawURL into a [url.URL]. If the
// rawURL is missing a scheme, "https://" is prepended before parsing.
//