Multi-args instead of comma-separated

main
Brian Picciano 5 months ago
parent db3e6029b9
commit f012eeebbf
  1. 10
      README.md
  2. 29
      cmd/deadlinks/flag.go
  3. 18
      cmd/deadlinks/main.go

@ -19,11 +19,11 @@ The command-line utility can be installed using `go install`:
go install code.betamike.com/mediocregopher/deadlinks/cmd/deadlinks
```
The `-urls` parameter is required. Given one or more URLs it will check each one
for any dead links:
The `-url` parameter is required. Given a URL it will check it for
any dead links. Can be specified more than once:
```
deadlinks -urls 'https://mediocregopher.com,gemini://mediocregopher.com'
deadlinks -url='https://mediocregopher.com' -url='gemini://mediocregopher.com'
```
Any links which are dead will be output to stdout as YAML objects, each
@ -36,8 +36,8 @@ so on):
```
deadlinks \
-urls 'https://mediocregopher.com,gemini://mediocregopher.com' \
-patterns '://mediocregopher.com'
-url='https://mediocregopher.com' -url='gemini://mediocregopher.com' \
-pattern='://mediocregopher.com'
```
There are further options available which affect the utility's behavior, see

@ -0,0 +1,29 @@
package main
import (
"flag"
"strings"
)
// Created so that multiple inputs can be accecpted
type arrayFlags struct {
strs *[]string
}
func flagStrings(name, usage string) arrayFlags {
f := arrayFlags{new([]string)}
flag.Var(&f, name, usage)
return f
}
func (i arrayFlags) String() string {
if i.strs == nil {
return ""
}
return strings.Join(*i.strs, ", ")
}
func (i arrayFlags) Set(value string) error {
*i.strs = append(*i.strs, strings.TrimSpace(value))
return nil
}

@ -8,7 +8,6 @@ import (
"os"
"os/signal"
"runtime"
"strings"
"time"
"code.betamike.com/mediocregopher/deadlinks"
@ -33,21 +32,16 @@ func main() {
var (
storePath = flag.String("store-path", "", "Path to sqlite storage file. If not given then a temporary in-memory storage is used")
maxAge = flag.Duration("max-age", 0, "Maximum duration since last check of a resource, before it must be checked again. Must be used with -store-path")
urls = flag.String("urls", "", `Comma-separated list of URLs which are always checked. At least one is required`)
patternsStr = flag.String("patterns", "", "Comma-separated list of regexps. All URLs which match one of these will have their links checked as well")
urls = flagStrings("url", "URL which is always checked. Must be given at least once")
patterns = flagStrings("pattern", "URLs matching this regex will have their links checked as well. Can be specified multiple times")
concurrency = flag.Int("concurrency", runtime.NumCPU()/2, "Number simultaneous requests to make at a time")
httpUserAgent = flag.String("http-user-agent", "", "User-agent to use for http requests")
)
flag.Parse()
if *urls == "" {
log.Fatal("-urls is required")
}
var patterns []string
if *patternsStr != "" {
patterns = strings.Split(*patternsStr, ",")
if len(*urls.strs) == 0 {
log.Fatal("at least one -url is required")
}
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
@ -61,8 +55,8 @@ func main() {
dl, err := deadlinks.New(
ctx,
store,
strings.Split(*urls, ","),
patterns,
*urls.strs,
*patterns.strs,
&deadlinks.Opts{
NewClient: func() deadlinks.Client {
return loggingClient{deadlinks.NewClient(&deadlinks.ClientOpts{

Loading…
Cancel
Save