From 1e8f0e20ee895394209f070b05137b1bec609534 Mon Sep 17 00:00:00 2001 From: demo Date: Fri, 12 Jun 2026 11:26:53 -0400 Subject: refactor: move Action code to separate function --- main.go | 52 +++++++++++++++++++++++++++------------------------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/main.go b/main.go index 5c9534f..cfe7b3a 100644 --- a/main.go +++ b/main.go @@ -73,31 +73,7 @@ func main() { DefaultText: "no limit", }, }, - Action: func(ctx context.Context, cmd *cli.Command) error { - rawURL := cmd.String("url") - - // If rawURL is empty, it - // means that we supplied - // --shortcode instead, so use - // that. - if rawURL == "" { - var err error - shortcode := cmd.String("shortcode") - - rawURL, err = getURLFromShortcode(shortcodeFilename, shortcode) - if err != nil { - return err - } - } - - u, err := convertToURL(rawURL) - if err != nil { - return err - } - - classic(u, cmd.Int("concurrency"), cmd.Int("maxurls"), cmd.Int("depth")) - return nil - }, + Action: run, }, { Name: "shortcode", @@ -116,6 +92,32 @@ func main() { } } +func run(ctx context.Context, cmd *cli.Command) error { + rawURL := cmd.String("url") + + // If rawURL is empty, it + // means that we supplied + // --shortcode instead, so use + // that. + if rawURL == "" { + var err error + shortcode := cmd.String("shortcode") + + rawURL, err = getURLFromShortcode(shortcodeFilename, shortcode) + if err != nil { + return err + } + } + + u, err := convertToURL(rawURL) + if err != nil { + return err + } + + classic(u, cmd.Int("concurrency"), cmd.Int("maxurls"), cmd.Int("depth")) + return nil +} + // convertToURL parses the given rawURL into a [url.URL]. If the // rawURL is missing a scheme, "https://" is prepended before parsing. // -- cgit v1.2.3