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