1 // Copyright 2018 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
13 type URLValue struct {
17 func (v URLValue) String() string {
24 func (v URLValue) Set(s string) error {
25 if u, err := url.Parse(s); err != nil {
36 fs := flag.NewFlagSet("ExampleValue", flag.ExitOnError)
37 fs.Var(&URLValue{u}, "url", "URL to parse")
39 fs.Parse([]string{"-url", "https://golang.org/pkg/flag/"})
40 fmt.Printf(`{scheme: %q, host: %q, path: %q}`, u.Scheme, u.Host, u.Path)
43 // {scheme: "https", host: "golang.org", path: "/pkg/flag/"}