Skip to content

Commit

Permalink
feat: remove URL flag, use arg instead
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
Splode committed Mar 1, 2020
1 parent bc942cb commit 4082eff
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
12 changes: 6 additions & 6 deletions cmd/creep/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,31 +86,31 @@ 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)
}
})

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)
}
})

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)
Expand All @@ -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)
Expand Down
13 changes: 7 additions & 6 deletions pkg/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "")
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
}
Expand Down

0 comments on commit 4082eff

Please sign in to comment.