summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordemo <demo@antix1>2026-06-11 22:24:26 -0400
committerdemo <demo@antix1>2026-06-11 22:24:26 -0400
commit8ebb4b560658852d300177cc1fa02da644768eab (patch)
tree724e5684bfe79b6b983d5e5a0f20c4b10f9f6372
parent7e3b986baf43a22eda752ef24d367e587cdaef2d (diff)
feat: make stubs for subcommands
-rw-r--r--go.mod1
-rw-r--r--go.sum2
-rw-r--r--main.go80
3 files changed, 23 insertions, 60 deletions
diff --git a/go.mod b/go.mod
index 2e31171..40ca0f9 100644
--- a/go.mod
+++ b/go.mod
@@ -3,7 +3,6 @@ module git.brandonirizarry.xyz/urls
go 1.26.2
require (
- git.brandonirizarry.xyz/hamlet v0.1.2
github.com/urfave/cli/v3 v3.9.1
golang.org/x/net v0.54.0
)
diff --git a/go.sum b/go.sum
index eeb0d15..87e9e1a 100644
--- a/go.sum
+++ b/go.sum
@@ -1,5 +1,3 @@
-git.brandonirizarry.xyz/hamlet v0.1.2 h1:yKzEAelhDkN9R098HVY26xVHmrpqqvgFnY9tvlLl814=
-git.brandonirizarry.xyz/hamlet v0.1.2/go.mod h1:J+v/AHboHRz0Tp04nRODRacbmyk6V+f1w2EwA3HQ1Og=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
diff --git a/main.go b/main.go
index a4f6d46..3b40dad 100644
--- a/main.go
+++ b/main.go
@@ -3,7 +3,7 @@
package main
import (
- "flag"
+ "context"
"fmt"
"log"
"net/url"
@@ -12,7 +12,7 @@ import (
"strings"
"time"
- "git.brandonirizarry.xyz/hamlet"
+ "github.com/urfave/cli/v3"
)
func main() {
@@ -24,65 +24,31 @@ func main() {
// without returning them.
log.SetFlags(log.LstdFlags | log.Lshortfile)
- maxConcurrency := flag.Int("c", 0, "Maximum number of concurrent queue pushes")
- urlArg := flag.String("url", "", "Entry-point URL")
- maxURLs := flag.Int("max", 0, "Maximum number of URLs to collect (omitted or 0 means no limit)")
- maxDepth := flag.Int("depth", 0, "Maximum URL depth (omitted or 0 means no limit)")
- shortcode := flag.String("shortcode", "", "URL shortcode")
- shortcodeFilename := flag.String("scfile", "urls.csv", "Shortcode CSV file")
-
- flag.Parse()
-
- // Vet the given CLI arguments for things like negative or
- // missing values.
- if *maxConcurrency == 0 {
- log.Fatal("Missing -c argument")
- }
-
- if *maxConcurrency < 1 {
- log.Fatalf("Invalid -c argument: %d", *maxConcurrency)
- }
-
- if *maxURLs < 0 {
- log.Fatalf("Invalid -max argument: %d", *maxURLs)
- }
-
- if *maxDepth < 0 {
- log.Fatalf("Invalid -depth argument: %d", *maxDepth)
- }
-
- // Use hamlet to vet the validity of the given command-line
- // argument configuration provided by the user.
- shortcodePresent := hamlet.Present(*shortcode)
- urlArgPresent := hamlet.Present(*urlArg)
- if hamlet.Xor(urlArgPresent, shortcodePresent).Deny() {
- log.Fatal("Need exactly one of -url or -shortcode")
- }
-
- if hamlet.If(hamlet.Present(*shortcodeFilename), shortcodePresent).Deny() {
- log.Fatal("-scfile implies use of -shortcode")
+ cmd := &cli.Command{
+ Usage: "A configurable web crawler",
+ Commands: []*cli.Command{
+ {
+ Name: "get",
+ Usage: "Crawl the target",
+ Action: func(ctx context.Context, cmd *cli.Command) error {
+ fmt.Println("get!")
+ return nil
+ },
+ },
+ {
+ Name: "shortcode",
+ Usage: "Configure shortcodes",
+ Action: func(ctx context.Context, cmd *cli.Command) error {
+ fmt.Println("shortcode!")
+ return nil
+ },
+ },
+ },
}
- 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 {
+ if err := cmd.Run(context.Background(), os.Args); err != nil {
log.Fatal(err)
}
-
- // Our web crawlers use concurrency: check if any goroutines
- // have leaked.
- getLeakProfile(func() {
- classic(startURL, *maxConcurrency, *maxURLs, *maxDepth)
- })
}
// convertToURL parses the given rawURL into a [url.URL]. If the