From 4082effa060108595c4d5bf72f8ec0fadcf6d316 Mon Sep 17 00:00:00 2001 From: Christopher Murphy Date: Sun, 1 Mar 2020 16:03:39 -0700 Subject: [PATCH] feat: remove URL flag, use arg instead - Removes the URL flag in favor of a single URL command. The URL option was never really an option as it was the only required argument. Passing the URL in as an argument feels more natural to use. - Updates main_test.go to use args. - Update usage to reflect API changes. --- cmd/creep/main_test.go | 12 ++++++------ pkg/flags/flags.go | 13 +++++++------ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/cmd/creep/main_test.go b/cmd/creep/main_test.go index 4bf523f..54a4d3d 100644 --- a/cmd/creep/main_test.go +++ b/cmd/creep/main_test.go @@ -86,7 +86,7 @@ func TestCreepCLI(t *testing.T) { }) t.Run("DownloadSingleImage", func(t *testing.T) { - args := "-u https://source.unsplash.com/random" + args := "https://source.unsplash.com/random" cmd := exec.Command(cmdPath, strings.Split(args, " ")...) if err := cmd.Run(); err != nil { t.Fatal(err) @@ -94,7 +94,7 @@ func TestCreepCLI(t *testing.T) { }) t.Run("DownloadMultipleImages", func(t *testing.T) { - args := "-u https://source.unsplash.com/random -c 2" + args := "https://source.unsplash.com/random -c 2" cmd := exec.Command(cmdPath, strings.Split(args, " ")...) if err := cmd.Run(); err != nil { t.Fatal(err) @@ -102,15 +102,15 @@ func TestCreepCLI(t *testing.T) { }) t.Run("DownloadSingleImageWithName", func(t *testing.T) { - args := "-u https://source.unsplash.com/random -n test" + args := "https://source.unsplash.com/random -n test" cmd := exec.Command(cmdPath, strings.Split(args, " ")...) if err := cmd.Run(); err != nil { t.Fatal(err) } }) - t.Run("DownloadSingleImageWithOutpath", func(t *testing.T) { - args := "-u https://source.unsplash.com/random -o test" + t.Run("DownloadSingleImageWithPath", func(t *testing.T) { + args := "https://source.unsplash.com/random -o test" cmd := exec.Command(cmdPath, strings.Split(args, " ")...) if err := cmd.Run(); err != nil { t.Fatal(err) @@ -122,7 +122,7 @@ func TestCreepCLI(t *testing.T) { }) t.Run("DownloadMultipleImagesWithThrottle", func(t *testing.T) { - args := "-u https://source.unsplash.com/random -c 2 -t 4" + args := "https://source.unsplash.com/random -c 2 -t 4" cmd := exec.Command(cmdPath, strings.Split(args, " ")...) if err := cmd.Run(); err != nil { t.Fatal(err) diff --git a/pkg/flags/flags.go b/pkg/flags/flags.go index 238a47a..80e4dc9 100644 --- a/pkg/flags/flags.go +++ b/pkg/flags/flags.go @@ -24,8 +24,6 @@ type Config struct { func HandleFlags() (c *Config, err error) { c = &Config{} v := false - flag.StringVar(&c.URL, "url", "", "") - flag.StringVar(&c.URL, "u", "", "") flag.StringVar(&c.Name, "name", "creep", "") flag.StringVar(&c.Name, "n", "creep", "") flag.UintVar(&c.Count, "count", 1, "") @@ -38,6 +36,7 @@ func HandleFlags() (c *Config, err error) { flag.BoolVar(&v, "v", false, "") flag.Usage = generateUsage() flag.Parse() + c.URL = flag.Arg(0) if v { fmt.Println(Version) @@ -71,10 +70,12 @@ func generateUsage() func() { Downloads an image from the given URL a given number of times to the specified directory. Usage: - creep [FLAGS] [OPTIONS] + creep [URL] [FLAGS] [OPTIONS] + +URL: + The URL of the resource to access (required) Options: - -u, --url string The URL of the resource to access (required) -c, --count int The number of times to access the resource (defaults to 1) -n, --name string The base filename to use as output (defaults to "creep") -o, --out string The output directory path (defaults to current directory) @@ -85,8 +86,8 @@ Flags: -v, --version Prints version information Example usage: - creep -u https://thispersondoesnotexist.com/image -c 32 - creep --url=https://source.unsplash.com/random --name=random --out=downloads --count=64 --throttle=3`) + creep https://thispersondoesnotexist.com/image -c 32 + creep https://source.unsplash.com/random --name=random --out=downloads --count=64 --throttle=3`) fmt.Println() os.Exit(0) }