woodpecker/vendor/github.com/julz/importas/flags.go
6543 56a854fe14
Update deps (#789)
* update github.com/docker/cli

* update github.com/docker/distribution

* update github.com/docker/docker

* update github.com/gin-gonic/gin

* update github.com/golang-jwt/jwt/v4

* update github.com/golangci/golangci-lint

* update github.com/gorilla/securecookie

* update github.com/mattn/go-sqlite3

* update github.com/moby/moby

* update github.com/prometheus/client_golang

* update github.com/xanzy/go-gitlab
2022-02-24 17:33:24 +01:00

32 lines
783 B
Go

package importas
import (
"errors"
"flag"
"fmt"
"strings"
)
func flags(config *Config) flag.FlagSet {
fs := flag.FlagSet{}
fs.Var(stringMap(config.RequiredAlias), "alias", "required import alias in form path:alias")
fs.BoolVar(&config.DisallowUnaliased, "no-unaliased", false, "do not allow unaliased imports of aliased packages")
fs.BoolVar(&config.DisallowExtraAliases, "no-extra-aliases", false, "do not allow non-required aliases")
return fs
}
type stringMap map[string]string
func (v stringMap) Set(val string) error {
spl := strings.SplitN(val, ":", 2)
if len(spl) != 2 {
return errors.New("import flag must be of form path:alias")
}
v[spl[0]] = spl[1]
return nil
}
func (v stringMap) String() string {
return fmt.Sprintf("%v", (map[string]string)(v))
}