Skip to content

Commit

Permalink
feat: specific error when no -url was given
Browse files Browse the repository at this point in the history
  • Loading branch information
scop committed Nov 16, 2023
1 parent 6c4651f commit 6cc6f28
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Usage of wrun:
-http-timeout duration
HTTP client timeout (default 5m0s)
-url value
[<OS>/<architecture>=]URL (at least one required to match)
[<OS>/<architecture>=]URL (at least one required)
-use-pre-commit-cache
Use pre-commit's cache dir

Expand Down
8 changes: 7 additions & 1 deletion wrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ type config struct {
func parseFlags(set *flag.FlagSet, args []string) (config, error) {
cfg := config{}
cfg.urlMatches = make([]urlMatch, 0, len(args)/2+3)
set.Func("url", "[<OS>/<architecture>=]URL (at least one required to match)", func(s string) error {
set.Func("url", "[<OS>/<architecture>=]URL (at least one required)", func(s string) error {
pattern, ur, found := strings.Cut(s, "=")
if found {
if strings.Contains(pattern, "://") {
Expand Down Expand Up @@ -176,6 +176,12 @@ func parseFlags(set *flag.FlagSet, args []string) (config, error) {
if err := set.Parse(args); err != nil {
return config{}, err
}
if len(cfg.urlMatches) == 0 {
err := errors.New("flag must occur at least once: -url")
_, _ = fmt.Fprintln(set.Output(), err)
set.Usage()
return config{}, err
}
return cfg, nil
}

Expand Down

0 comments on commit 6cc6f28

Please sign in to comment.