├── .github └── workflows │ └── ci.yaml ├── README.md ├── cmd └── readability │ └── main.go ├── go.mod ├── go.sum ├── readability.go ├── readability_test.go ├── test_fixtures ├── blogpost_with_links.html ├── channel4-1.html ├── foxnews-india1.html └── globemail-ottowa_cuts.html └── vendor ├── github.com ├── PuerkitoBio │ └── goquery │ │ ├── .gitattributes │ │ ├── .gitignore │ │ ├── .travis.yml │ │ ├── LICENSE │ │ ├── README.md │ │ ├── array.go │ │ ├── doc.go │ │ ├── expand.go │ │ ├── filter.go │ │ ├── go.mod │ │ ├── go.sum │ │ ├── iteration.go │ │ ├── manipulation.go │ │ ├── property.go │ │ ├── query.go │ │ ├── traversal.go │ │ ├── type.go │ │ └── utilities.go ├── andybalholm │ └── cascadia │ │ ├── .travis.yml │ │ ├── LICENSE │ │ ├── README.md │ │ ├── go.mod │ │ ├── parser.go │ │ ├── selector.go │ │ ├── serialize.go │ │ └── specificity.go ├── inconshreveable │ └── mousetrap │ │ ├── LICENSE │ │ ├── README.md │ │ ├── trap_others.go │ │ ├── trap_windows.go │ │ └── trap_windows_1.4.go └── spf13 │ ├── cobra │ ├── .gitignore │ ├── .mailmap │ ├── .travis.yml │ ├── CHANGELOG.md │ ├── CONTRIBUTING.md │ ├── LICENSE.txt │ ├── Makefile │ ├── README.md │ ├── args.go │ ├── bash_completions.go │ ├── bash_completions.md │ ├── cobra.go │ ├── command.go │ ├── command_notwin.go │ ├── command_win.go │ ├── custom_completions.go │ ├── fish_completions.go │ ├── fish_completions.md │ ├── go.mod │ ├── go.sum │ ├── powershell_completions.go │ ├── powershell_completions.md │ ├── projects_using_cobra.md │ ├── shell_completions.go │ ├── shell_completions.md │ ├── zsh_completions.go │ └── zsh_completions.md │ └── pflag │ ├── .gitignore │ ├── .travis.yml │ ├── LICENSE │ ├── README.md │ ├── bool.go │ ├── bool_slice.go │ ├── bytes.go │ ├── count.go │ ├── duration.go │ ├── duration_slice.go │ ├── flag.go │ ├── float32.go │ ├── float32_slice.go │ ├── float64.go │ ├── float64_slice.go │ ├── go.mod │ ├── go.sum │ ├── golangflag.go │ ├── int.go │ ├── int16.go │ ├── int32.go │ ├── int32_slice.go │ ├── int64.go │ ├── int64_slice.go │ ├── int8.go │ ├── int_slice.go │ ├── ip.go │ ├── ip_slice.go │ ├── ipmask.go │ ├── ipnet.go │ ├── string.go │ ├── string_array.go │ ├── string_slice.go │ ├── string_to_int.go │ ├── string_to_int64.go │ ├── string_to_string.go │ ├── uint.go │ ├── uint16.go │ ├── uint32.go │ ├── uint64.go │ ├── uint8.go │ └── uint_slice.go ├── golang.org └── x │ └── net │ ├── AUTHORS │ ├── CONTRIBUTORS │ ├── LICENSE │ ├── PATENTS │ └── html │ ├── atom │ ├── atom.go │ └── table.go │ ├── const.go │ ├── doc.go │ ├── doctype.go │ ├── entity.go │ ├── escape.go │ ├── foreign.go │ ├── node.go │ ├── parse.go │ ├── render.go │ └── token.go └── modules.txt /.github/workflows/ci.yaml: -------------------------------------------------------------------------------- 1 | name: build 2 | 3 | on: 4 | push: 5 | branches: 6 | tags: 7 | pull_request: 8 | 9 | jobs: 10 | build: 11 | runs-on: ubuntu-latest 12 | 13 | steps: 14 | - name: set up go 1.16 15 | uses: actions/setup-go@v1 16 | with: 17 | go-version: 1.16 18 | id: go 19 | 20 | - name: checkout 21 | uses: actions/checkout@v2 22 | 23 | - name: build and test 24 | run: | 25 | go test -timeout=60s -race ./... 26 | go build -race 27 | 28 | - name: install golangci-lint and goveralls 29 | run: | 30 | curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b $GITHUB_WORKSPACE v1.41.1 31 | - name: run linters 32 | run: $GITHUB_WORKSPACE/golangci-lint run --out-format=github-actions 33 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # go-readability 2 | 3 | go-readability is library for extracting the main content off of an HTML page. This library implements the readability algorithm created by arc90 labs and was heavily inspired by https://github.com/cantino/ruby-readability. 4 | 5 | ## Installation 6 | 7 | `go install github.com/mauidude/go-readability` 8 | 9 | ## CLI Tool 10 | 11 | You can run readability via the command line to extract content from a single HTML file by running the following command: 12 | 13 | ```bash 14 | $ readability path/to/file.html 15 | ``` 16 | 17 | For help with usage and options you can run the following: 18 | 19 | ```bash 20 | $ readability --help 21 | ``` 22 | 23 | ## Example 24 | 25 | ``` 26 | import( 27 | "github.com/mauidude/go-readability" 28 | ) 29 | 30 | ... 31 | 32 | doc, err := readability.NewDocument(html) 33 | if err != nil { 34 | // do something ... 35 | } 36 | 37 | content := doc.Content() 38 | // do something with my content 39 | 40 | ``` 41 | 42 | 43 | ## Tests 44 | 45 | To run tests 46 | `go test github.com/mauidude/go-readability` 47 | -------------------------------------------------------------------------------- /cmd/readability/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "io/ioutil" 6 | "os" 7 | 8 | "github.com/mauidude/go-readability" 9 | "github.com/spf13/cobra" 10 | ) 11 | 12 | func main() { 13 | var rootCmd = &cobra.Command{ 14 | Use: "readability [file]", 15 | Short: "Readability is a CLI tool to extract content from an HTML page", 16 | Args: cobra.ExactArgs(1), 17 | RunE: func(cmd *cobra.Command, args []string) error { 18 | content, err := ioutil.ReadFile(args[0]) 19 | if err != nil { 20 | return fmt.Errorf("unable to read file: %w", err) 21 | } 22 | 23 | doc, err := readability.NewDocument(string(content)) 24 | if err != nil { 25 | return fmt.Errorf("unable to create document: %w", err) 26 | } 27 | 28 | doc.MinTextLength, _ = cmd.Flags().GetInt("min-text-length") 29 | 30 | html := doc.Content() 31 | fmt.Println(html) 32 | 33 | return nil 34 | }, 35 | } 36 | 37 | rootCmd.Flags().IntP("min-text-length", "l", 0, "minimum text length to consider a node") 38 | 39 | if err := rootCmd.Execute(); err != nil { 40 | fmt.Fprintln(os.Stderr, err) 41 | os.Exit(1) 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/mauidude/go-readability 2 | 3 | go 1.16 4 | 5 | require ( 6 | github.com/PuerkitoBio/goquery v1.6.0 7 | github.com/andybalholm/cascadia v1.2.0 // indirect 8 | github.com/spf13/cobra v1.1.1 9 | golang.org/x/net v0.0.0-20201031054903-ff519b6c9102 10 | ) 11 | -------------------------------------------------------------------------------- /vendor/github.com/PuerkitoBio/goquery/.gitattributes: -------------------------------------------------------------------------------- 1 | testdata/* linguist-vendored 2 | -------------------------------------------------------------------------------- /vendor/github.com/PuerkitoBio/goquery/.gitignore: -------------------------------------------------------------------------------- 1 | # editor temporary files 2 | *.sublime-* 3 | .DS_Store 4 | *.swp 5 | #*.*# 6 | tags 7 | 8 | # direnv config 9 | .env* 10 | 11 | # test binaries 12 | *.test 13 | 14 | # coverage and profilte outputs 15 | *.out 16 | 17 | -------------------------------------------------------------------------------- /vendor/github.com/PuerkitoBio/goquery/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | go: 4 | - 1.2.x 5 | - 1.3.x 6 | - 1.4.x 7 | - 1.5.x 8 | - 1.6.x 9 | - 1.7.x 10 | - 1.8.x 11 | - 1.9.x 12 | - 1.10.x 13 | - 1.11.x 14 | - 1.12.x 15 | - 1.13.x 16 | - tip 17 | 18 | -------------------------------------------------------------------------------- /vendor/github.com/PuerkitoBio/goquery/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012-2016, Martin Angers & Contributors 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 5 | 6 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 7 | 8 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | 10 | * Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 11 | 12 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 13 | -------------------------------------------------------------------------------- /vendor/github.com/PuerkitoBio/goquery/array.go: -------------------------------------------------------------------------------- 1 | package goquery 2 | 3 | import ( 4 | "golang.org/x/net/html" 5 | ) 6 | 7 | const ( 8 | maxUint = ^uint(0) 9 | maxInt = int(maxUint >> 1) 10 | 11 | // ToEnd is a special index value that can be used as end index in a call 12 | // to Slice so that all elements are selected until the end of the Selection. 13 | // It is equivalent to passing (*Selection).Length(). 14 | ToEnd = maxInt 15 | ) 16 | 17 | // First reduces the set of matched elements to the first in the set. 18 | // It returns a new Selection object, and an empty Selection object if the 19 | // the selection is empty. 20 | func (s *Selection) First() *Selection { 21 | return s.Eq(0) 22 | } 23 | 24 | // Last reduces the set of matched elements to the last in the set. 25 | // It returns a new Selection object, and an empty Selection object if 26 | // the selection is empty. 27 | func (s *Selection) Last() *Selection { 28 | return s.Eq(-1) 29 | } 30 | 31 | // Eq reduces the set of matched elements to the one at the specified index. 32 | // If a negative index is given, it counts backwards starting at the end of the 33 | // set. It returns a new Selection object, and an empty Selection object if the 34 | // index is invalid. 35 | func (s *Selection) Eq(index int) *Selection { 36 | if index < 0 { 37 | index += len(s.Nodes) 38 | } 39 | 40 | if index >= len(s.Nodes) || index < 0 { 41 | return newEmptySelection(s.document) 42 | } 43 | 44 | return s.Slice(index, index+1) 45 | } 46 | 47 | // Slice reduces the set of matched elements to a subset specified by a range 48 | // of indices. The start index is 0-based and indicates the index of the first 49 | // element to select. The end index is 0-based and indicates the index at which 50 | // the elements stop being selected (the end index is not selected). 51 | // 52 | // The indices may be negative, in which case they represent an offset from the 53 | // end of the selection. 54 | // 55 | // The special value ToEnd may be specified as end index, in which case all elements 56 | // until the end are selected. This works both for a positive and negative start 57 | // index. 58 | func (s *Selection) Slice(start, end int) *Selection { 59 | if start < 0 { 60 | start += len(s.Nodes) 61 | } 62 | if end == ToEnd { 63 | end = len(s.Nodes) 64 | } else if end < 0 { 65 | end += len(s.Nodes) 66 | } 67 | return pushStack(s, s.Nodes[start:end]) 68 | } 69 | 70 | // Get retrieves the underlying node at the specified index. 71 | // Get without parameter is not implemented, since the node array is available 72 | // on the Selection object. 73 | func (s *Selection) Get(index int) *html.Node { 74 | if index < 0 { 75 | index += len(s.Nodes) // Negative index gets from the end 76 | } 77 | return s.Nodes[index] 78 | } 79 | 80 | // Index returns the position of the first element within the Selection object 81 | // relative to its sibling elements. 82 | func (s *Selection) Index() int { 83 | if len(s.Nodes) > 0 { 84 | return newSingleSelection(s.Nodes[0], s.document).PrevAll().Length() 85 | } 86 | return -1 87 | } 88 | 89 | // IndexSelector returns the position of the first element within the 90 | // Selection object relative to the elements matched by the selector, or -1 if 91 | // not found. 92 | func (s *Selection) IndexSelector(selector string) int { 93 | if len(s.Nodes) > 0 { 94 | sel := s.document.Find(selector) 95 | return indexInSlice(sel.Nodes, s.Nodes[0]) 96 | } 97 | return -1 98 | } 99 | 100 | // IndexMatcher returns the position of the first element within the 101 | // Selection object relative to the elements matched by the matcher, or -1 if 102 | // not found. 103 | func (s *Selection) IndexMatcher(m Matcher) int { 104 | if len(s.Nodes) > 0 { 105 | sel := s.document.FindMatcher(m) 106 | return indexInSlice(sel.Nodes, s.Nodes[0]) 107 | } 108 | return -1 109 | } 110 | 111 | // IndexOfNode returns the position of the specified node within the Selection 112 | // object, or -1 if not found. 113 | func (s *Selection) IndexOfNode(node *html.Node) int { 114 | return indexInSlice(s.Nodes, node) 115 | } 116 | 117 | // IndexOfSelection returns the position of the first node in the specified 118 | // Selection object within this Selection object, or -1 if not found. 119 | func (s *Selection) IndexOfSelection(sel *Selection) int { 120 | if sel != nil && len(sel.Nodes) > 0 { 121 | return indexInSlice(s.Nodes, sel.Nodes[0]) 122 | } 123 | return -1 124 | } 125 | -------------------------------------------------------------------------------- /vendor/github.com/PuerkitoBio/goquery/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012-2016, Martin Angers & Contributors 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modification, 5 | // are permitted provided that the following conditions are met: 6 | // 7 | // * Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above copyright notice, 10 | // this list of conditions and the following disclaimer in the documentation and/or 11 | // other materials provided with the distribution. 12 | // * Neither the name of the author nor the names of its contributors may be used to 13 | // endorse or promote products derived from this software without specific prior written permission. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS 16 | // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 17 | // AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 18 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 21 | // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY 22 | // WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | /* 25 | Package goquery implements features similar to jQuery, including the chainable 26 | syntax, to manipulate and query an HTML document. 27 | 28 | It brings a syntax and a set of features similar to jQuery to the Go language. 29 | It is based on Go's net/html package and the CSS Selector library cascadia. 30 | Since the net/html parser returns nodes, and not a full-featured DOM 31 | tree, jQuery's stateful manipulation functions (like height(), css(), detach()) 32 | have been left off. 33 | 34 | Also, because the net/html parser requires UTF-8 encoding, so does goquery: it is 35 | the caller's responsibility to ensure that the source document provides UTF-8 encoded HTML. 36 | See the repository's wiki for various options on how to do this. 37 | 38 | Syntax-wise, it is as close as possible to jQuery, with the same method names when 39 | possible, and that warm and fuzzy chainable interface. jQuery being the 40 | ultra-popular library that it is, writing a similar HTML-manipulating 41 | library was better to follow its API than to start anew (in the same spirit as 42 | Go's fmt package), even though some of its methods are less than intuitive (looking 43 | at you, index()...). 44 | 45 | It is hosted on GitHub, along with additional documentation in the README.md 46 | file: https://github.com/puerkitobio/goquery 47 | 48 | Please note that because of the net/html dependency, goquery requires Go1.1+. 49 | 50 | The various methods are split into files based on the category of behavior. 51 | The three dots (...) indicate that various "overloads" are available. 52 | 53 | * array.go : array-like positional manipulation of the selection. 54 | - Eq() 55 | - First() 56 | - Get() 57 | - Index...() 58 | - Last() 59 | - Slice() 60 | 61 | * expand.go : methods that expand or augment the selection's set. 62 | - Add...() 63 | - AndSelf() 64 | - Union(), which is an alias for AddSelection() 65 | 66 | * filter.go : filtering methods, that reduce the selection's set. 67 | - End() 68 | - Filter...() 69 | - Has...() 70 | - Intersection(), which is an alias of FilterSelection() 71 | - Not...() 72 | 73 | * iteration.go : methods to loop over the selection's nodes. 74 | - Each() 75 | - EachWithBreak() 76 | - Map() 77 | 78 | * manipulation.go : methods for modifying the document 79 | - After...() 80 | - Append...() 81 | - Before...() 82 | - Clone() 83 | - Empty() 84 | - Prepend...() 85 | - Remove...() 86 | - ReplaceWith...() 87 | - Unwrap() 88 | - Wrap...() 89 | - WrapAll...() 90 | - WrapInner...() 91 | 92 | * property.go : methods that inspect and get the node's properties values. 93 | - Attr*(), RemoveAttr(), SetAttr() 94 | - AddClass(), HasClass(), RemoveClass(), ToggleClass() 95 | - Html() 96 | - Length() 97 | - Size(), which is an alias for Length() 98 | - Text() 99 | 100 | * query.go : methods that query, or reflect, a node's identity. 101 | - Contains() 102 | - Is...() 103 | 104 | * traversal.go : methods to traverse the HTML document tree. 105 | - Children...() 106 | - Contents() 107 | - Find...() 108 | - Next...() 109 | - Parent[s]...() 110 | - Prev...() 111 | - Siblings...() 112 | 113 | * type.go : definition of the types exposed by goquery. 114 | - Document 115 | - Selection 116 | - Matcher 117 | 118 | * utilities.go : definition of helper functions (and not methods on a *Selection) 119 | that are not part of jQuery, but are useful to goquery. 120 | - NodeName 121 | - OuterHtml 122 | */ 123 | package goquery 124 | -------------------------------------------------------------------------------- /vendor/github.com/PuerkitoBio/goquery/expand.go: -------------------------------------------------------------------------------- 1 | package goquery 2 | 3 | import "golang.org/x/net/html" 4 | 5 | // Add adds the selector string's matching nodes to those in the current 6 | // selection and returns a new Selection object. 7 | // The selector string is run in the context of the document of the current 8 | // Selection object. 9 | func (s *Selection) Add(selector string) *Selection { 10 | return s.AddNodes(findWithMatcher([]*html.Node{s.document.rootNode}, compileMatcher(selector))...) 11 | } 12 | 13 | // AddMatcher adds the matcher's matching nodes to those in the current 14 | // selection and returns a new Selection object. 15 | // The matcher is run in the context of the document of the current 16 | // Selection object. 17 | func (s *Selection) AddMatcher(m Matcher) *Selection { 18 | return s.AddNodes(findWithMatcher([]*html.Node{s.document.rootNode}, m)...) 19 | } 20 | 21 | // AddSelection adds the specified Selection object's nodes to those in the 22 | // current selection and returns a new Selection object. 23 | func (s *Selection) AddSelection(sel *Selection) *Selection { 24 | if sel == nil { 25 | return s.AddNodes() 26 | } 27 | return s.AddNodes(sel.Nodes...) 28 | } 29 | 30 | // Union is an alias for AddSelection. 31 | func (s *Selection) Union(sel *Selection) *Selection { 32 | return s.AddSelection(sel) 33 | } 34 | 35 | // AddNodes adds the specified nodes to those in the 36 | // current selection and returns a new Selection object. 37 | func (s *Selection) AddNodes(nodes ...*html.Node) *Selection { 38 | return pushStack(s, appendWithoutDuplicates(s.Nodes, nodes, nil)) 39 | } 40 | 41 | // AndSelf adds the previous set of elements on the stack to the current set. 42 | // It returns a new Selection object containing the current Selection combined 43 | // with the previous one. 44 | // Deprecated: This function has been deprecated and is now an alias for AddBack(). 45 | func (s *Selection) AndSelf() *Selection { 46 | return s.AddBack() 47 | } 48 | 49 | // AddBack adds the previous set of elements on the stack to the current set. 50 | // It returns a new Selection object containing the current Selection combined 51 | // with the previous one. 52 | func (s *Selection) AddBack() *Selection { 53 | return s.AddSelection(s.prevSel) 54 | } 55 | 56 | // AddBackFiltered reduces the previous set of elements on the stack to those that 57 | // match the selector string, and adds them to the current set. 58 | // It returns a new Selection object containing the current Selection combined 59 | // with the filtered previous one 60 | func (s *Selection) AddBackFiltered(selector string) *Selection { 61 | return s.AddSelection(s.prevSel.Filter(selector)) 62 | } 63 | 64 | // AddBackMatcher reduces the previous set of elements on the stack to those that match 65 | // the mateher, and adds them to the curernt set. 66 | // It returns a new Selection object containing the current Selection combined 67 | // with the filtered previous one 68 | func (s *Selection) AddBackMatcher(m Matcher) *Selection { 69 | return s.AddSelection(s.prevSel.FilterMatcher(m)) 70 | } 71 | -------------------------------------------------------------------------------- /vendor/github.com/PuerkitoBio/goquery/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/PuerkitoBio/goquery 2 | 3 | require ( 4 | github.com/andybalholm/cascadia v1.1.0 5 | golang.org/x/net v0.0.0-20200202094626-16171245cfb2 6 | ) 7 | 8 | go 1.13 9 | -------------------------------------------------------------------------------- /vendor/github.com/PuerkitoBio/goquery/go.sum: -------------------------------------------------------------------------------- 1 | github.com/andybalholm/cascadia v1.1.0 h1:BuuO6sSfQNFRu1LppgbD25Hr2vLYW25JvxHs5zzsLTo= 2 | github.com/andybalholm/cascadia v1.1.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y= 3 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 4 | golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 5 | golang.org/x/net v0.0.0-20200202094626-16171245cfb2 h1:CCH4IOTTfewWjGOlSp+zGcjutRKlBEZQ6wTn8ozI/nI= 6 | golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 7 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 8 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 9 | -------------------------------------------------------------------------------- /vendor/github.com/PuerkitoBio/goquery/iteration.go: -------------------------------------------------------------------------------- 1 | package goquery 2 | 3 | // Each iterates over a Selection object, executing a function for each 4 | // matched element. It returns the current Selection object. The function 5 | // f is called for each element in the selection with the index of the 6 | // element in that selection starting at 0, and a *Selection that contains 7 | // only that element. 8 | func (s *Selection) Each(f func(int, *Selection)) *Selection { 9 | for i, n := range s.Nodes { 10 | f(i, newSingleSelection(n, s.document)) 11 | } 12 | return s 13 | } 14 | 15 | // EachWithBreak iterates over a Selection object, executing a function for each 16 | // matched element. It is identical to Each except that it is possible to break 17 | // out of the loop by returning false in the callback function. It returns the 18 | // current Selection object. 19 | func (s *Selection) EachWithBreak(f func(int, *Selection) bool) *Selection { 20 | for i, n := range s.Nodes { 21 | if !f(i, newSingleSelection(n, s.document)) { 22 | return s 23 | } 24 | } 25 | return s 26 | } 27 | 28 | // Map passes each element in the current matched set through a function, 29 | // producing a slice of string holding the returned values. The function 30 | // f is called for each element in the selection with the index of the 31 | // element in that selection starting at 0, and a *Selection that contains 32 | // only that element. 33 | func (s *Selection) Map(f func(int, *Selection) string) (result []string) { 34 | for i, n := range s.Nodes { 35 | result = append(result, f(i, newSingleSelection(n, s.document))) 36 | } 37 | 38 | return result 39 | } 40 | -------------------------------------------------------------------------------- /vendor/github.com/PuerkitoBio/goquery/query.go: -------------------------------------------------------------------------------- 1 | package goquery 2 | 3 | import "golang.org/x/net/html" 4 | 5 | // Is checks the current matched set of elements against a selector and 6 | // returns true if at least one of these elements matches. 7 | func (s *Selection) Is(selector string) bool { 8 | return s.IsMatcher(compileMatcher(selector)) 9 | } 10 | 11 | // IsMatcher checks the current matched set of elements against a matcher and 12 | // returns true if at least one of these elements matches. 13 | func (s *Selection) IsMatcher(m Matcher) bool { 14 | if len(s.Nodes) > 0 { 15 | if len(s.Nodes) == 1 { 16 | return m.Match(s.Nodes[0]) 17 | } 18 | return len(m.Filter(s.Nodes)) > 0 19 | } 20 | 21 | return false 22 | } 23 | 24 | // IsFunction checks the current matched set of elements against a predicate and 25 | // returns true if at least one of these elements matches. 26 | func (s *Selection) IsFunction(f func(int, *Selection) bool) bool { 27 | return s.FilterFunction(f).Length() > 0 28 | } 29 | 30 | // IsSelection checks the current matched set of elements against a Selection object 31 | // and returns true if at least one of these elements matches. 32 | func (s *Selection) IsSelection(sel *Selection) bool { 33 | return s.FilterSelection(sel).Length() > 0 34 | } 35 | 36 | // IsNodes checks the current matched set of elements against the specified nodes 37 | // and returns true if at least one of these elements matches. 38 | func (s *Selection) IsNodes(nodes ...*html.Node) bool { 39 | return s.FilterNodes(nodes...).Length() > 0 40 | } 41 | 42 | // Contains returns true if the specified Node is within, 43 | // at any depth, one of the nodes in the Selection object. 44 | // It is NOT inclusive, to behave like jQuery's implementation, and 45 | // unlike Javascript's .contains, so if the contained 46 | // node is itself in the selection, it returns false. 47 | func (s *Selection) Contains(n *html.Node) bool { 48 | return sliceContains(s.Nodes, n) 49 | } 50 | -------------------------------------------------------------------------------- /vendor/github.com/PuerkitoBio/goquery/type.go: -------------------------------------------------------------------------------- 1 | package goquery 2 | 3 | import ( 4 | "errors" 5 | "io" 6 | "net/http" 7 | "net/url" 8 | 9 | "github.com/andybalholm/cascadia" 10 | 11 | "golang.org/x/net/html" 12 | ) 13 | 14 | // Document represents an HTML document to be manipulated. Unlike jQuery, which 15 | // is loaded as part of a DOM document, and thus acts upon its containing 16 | // document, GoQuery doesn't know which HTML document to act upon. So it needs 17 | // to be told, and that's what the Document class is for. It holds the root 18 | // document node to manipulate, and can make selections on this document. 19 | type Document struct { 20 | *Selection 21 | Url *url.URL 22 | rootNode *html.Node 23 | } 24 | 25 | // NewDocumentFromNode is a Document constructor that takes a root html Node 26 | // as argument. 27 | func NewDocumentFromNode(root *html.Node) *Document { 28 | return newDocument(root, nil) 29 | } 30 | 31 | // NewDocument is a Document constructor that takes a string URL as argument. 32 | // It loads the specified document, parses it, and stores the root Document 33 | // node, ready to be manipulated. 34 | // 35 | // Deprecated: Use the net/http standard library package to make the request 36 | // and validate the response before calling goquery.NewDocumentFromReader 37 | // with the response's body. 38 | func NewDocument(url string) (*Document, error) { 39 | // Load the URL 40 | res, e := http.Get(url) 41 | if e != nil { 42 | return nil, e 43 | } 44 | return NewDocumentFromResponse(res) 45 | } 46 | 47 | // NewDocumentFromReader returns a Document from an io.Reader. 48 | // It returns an error as second value if the reader's data cannot be parsed 49 | // as html. It does not check if the reader is also an io.Closer, the 50 | // provided reader is never closed by this call. It is the responsibility 51 | // of the caller to close it if required. 52 | func NewDocumentFromReader(r io.Reader) (*Document, error) { 53 | root, e := html.Parse(r) 54 | if e != nil { 55 | return nil, e 56 | } 57 | return newDocument(root, nil), nil 58 | } 59 | 60 | // NewDocumentFromResponse is another Document constructor that takes an http response as argument. 61 | // It loads the specified response's document, parses it, and stores the root Document 62 | // node, ready to be manipulated. The response's body is closed on return. 63 | // 64 | // Deprecated: Use goquery.NewDocumentFromReader with the response's body. 65 | func NewDocumentFromResponse(res *http.Response) (*Document, error) { 66 | if res == nil { 67 | return nil, errors.New("Response is nil") 68 | } 69 | defer res.Body.Close() 70 | if res.Request == nil { 71 | return nil, errors.New("Response.Request is nil") 72 | } 73 | 74 | // Parse the HTML into nodes 75 | root, e := html.Parse(res.Body) 76 | if e != nil { 77 | return nil, e 78 | } 79 | 80 | // Create and fill the document 81 | return newDocument(root, res.Request.URL), nil 82 | } 83 | 84 | // CloneDocument creates a deep-clone of a document. 85 | func CloneDocument(doc *Document) *Document { 86 | return newDocument(cloneNode(doc.rootNode), doc.Url) 87 | } 88 | 89 | // Private constructor, make sure all fields are correctly filled. 90 | func newDocument(root *html.Node, url *url.URL) *Document { 91 | // Create and fill the document 92 | d := &Document{nil, url, root} 93 | d.Selection = newSingleSelection(root, d) 94 | return d 95 | } 96 | 97 | // Selection represents a collection of nodes matching some criteria. The 98 | // initial Selection can be created by using Document.Find, and then 99 | // manipulated using the jQuery-like chainable syntax and methods. 100 | type Selection struct { 101 | Nodes []*html.Node 102 | document *Document 103 | prevSel *Selection 104 | } 105 | 106 | // Helper constructor to create an empty selection 107 | func newEmptySelection(doc *Document) *Selection { 108 | return &Selection{nil, doc, nil} 109 | } 110 | 111 | // Helper constructor to create a selection of only one node 112 | func newSingleSelection(node *html.Node, doc *Document) *Selection { 113 | return &Selection{[]*html.Node{node}, doc, nil} 114 | } 115 | 116 | // Matcher is an interface that defines the methods to match 117 | // HTML nodes against a compiled selector string. Cascadia's 118 | // Selector implements this interface. 119 | type Matcher interface { 120 | Match(*html.Node) bool 121 | MatchAll(*html.Node) []*html.Node 122 | Filter([]*html.Node) []*html.Node 123 | } 124 | 125 | // compileMatcher compiles the selector string s and returns 126 | // the corresponding Matcher. If s is an invalid selector string, 127 | // it returns a Matcher that fails all matches. 128 | func compileMatcher(s string) Matcher { 129 | cs, err := cascadia.Compile(s) 130 | if err != nil { 131 | return invalidMatcher{} 132 | } 133 | return cs 134 | } 135 | 136 | // invalidMatcher is a Matcher that always fails to match. 137 | type invalidMatcher struct{} 138 | 139 | func (invalidMatcher) Match(n *html.Node) bool { return false } 140 | func (invalidMatcher) MatchAll(n *html.Node) []*html.Node { return nil } 141 | func (invalidMatcher) Filter(ns []*html.Node) []*html.Node { return nil } 142 | -------------------------------------------------------------------------------- /vendor/github.com/PuerkitoBio/goquery/utilities.go: -------------------------------------------------------------------------------- 1 | package goquery 2 | 3 | import ( 4 | "bytes" 5 | 6 | "golang.org/x/net/html" 7 | ) 8 | 9 | // used to determine if a set (map[*html.Node]bool) should be used 10 | // instead of iterating over a slice. The set uses more memory and 11 | // is slower than slice iteration for small N. 12 | const minNodesForSet = 1000 13 | 14 | var nodeNames = []string{ 15 | html.ErrorNode: "#error", 16 | html.TextNode: "#text", 17 | html.DocumentNode: "#document", 18 | html.CommentNode: "#comment", 19 | } 20 | 21 | // NodeName returns the node name of the first element in the selection. 22 | // It tries to behave in a similar way as the DOM's nodeName property 23 | // (https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeName). 24 | // 25 | // Go's net/html package defines the following node types, listed with 26 | // the corresponding returned value from this function: 27 | // 28 | // ErrorNode : #error 29 | // TextNode : #text 30 | // DocumentNode : #document 31 | // ElementNode : the element's tag name 32 | // CommentNode : #comment 33 | // DoctypeNode : the name of the document type 34 | // 35 | func NodeName(s *Selection) string { 36 | if s.Length() == 0 { 37 | return "" 38 | } 39 | return nodeName(s.Get(0)) 40 | } 41 | 42 | // nodeName returns the node name of the given html node. 43 | // See NodeName for additional details on behaviour. 44 | func nodeName(node *html.Node) string { 45 | if node == nil { 46 | return "" 47 | } 48 | 49 | switch node.Type { 50 | case html.ElementNode, html.DoctypeNode: 51 | return node.Data 52 | default: 53 | if node.Type >= 0 && int(node.Type) < len(nodeNames) { 54 | return nodeNames[node.Type] 55 | } 56 | return "" 57 | } 58 | } 59 | 60 | // OuterHtml returns the outer HTML rendering of the first item in 61 | // the selection - that is, the HTML including the first element's 62 | // tag and attributes. 63 | // 64 | // Unlike InnerHtml, this is a function and not a method on the Selection, 65 | // because this is not a jQuery method (in javascript-land, this is 66 | // a property provided by the DOM). 67 | func OuterHtml(s *Selection) (string, error) { 68 | var buf bytes.Buffer 69 | 70 | if s.Length() == 0 { 71 | return "", nil 72 | } 73 | n := s.Get(0) 74 | if err := html.Render(&buf, n); err != nil { 75 | return "", err 76 | } 77 | return buf.String(), nil 78 | } 79 | 80 | // Loop through all container nodes to search for the target node. 81 | func sliceContains(container []*html.Node, contained *html.Node) bool { 82 | for _, n := range container { 83 | if nodeContains(n, contained) { 84 | return true 85 | } 86 | } 87 | 88 | return false 89 | } 90 | 91 | // Checks if the contained node is within the container node. 92 | func nodeContains(container *html.Node, contained *html.Node) bool { 93 | // Check if the parent of the contained node is the container node, traversing 94 | // upward until the top is reached, or the container is found. 95 | for contained = contained.Parent; contained != nil; contained = contained.Parent { 96 | if container == contained { 97 | return true 98 | } 99 | } 100 | return false 101 | } 102 | 103 | // Checks if the target node is in the slice of nodes. 104 | func isInSlice(slice []*html.Node, node *html.Node) bool { 105 | return indexInSlice(slice, node) > -1 106 | } 107 | 108 | // Returns the index of the target node in the slice, or -1. 109 | func indexInSlice(slice []*html.Node, node *html.Node) int { 110 | if node != nil { 111 | for i, n := range slice { 112 | if n == node { 113 | return i 114 | } 115 | } 116 | } 117 | return -1 118 | } 119 | 120 | // Appends the new nodes to the target slice, making sure no duplicate is added. 121 | // There is no check to the original state of the target slice, so it may still 122 | // contain duplicates. The target slice is returned because append() may create 123 | // a new underlying array. If targetSet is nil, a local set is created with the 124 | // target if len(target) + len(nodes) is greater than minNodesForSet. 125 | func appendWithoutDuplicates(target []*html.Node, nodes []*html.Node, targetSet map[*html.Node]bool) []*html.Node { 126 | // if there are not that many nodes, don't use the map, faster to just use nested loops 127 | // (unless a non-nil targetSet is passed, in which case the caller knows better). 128 | if targetSet == nil && len(target)+len(nodes) < minNodesForSet { 129 | for _, n := range nodes { 130 | if !isInSlice(target, n) { 131 | target = append(target, n) 132 | } 133 | } 134 | return target 135 | } 136 | 137 | // if a targetSet is passed, then assume it is reliable, otherwise create one 138 | // and initialize it with the current target contents. 139 | if targetSet == nil { 140 | targetSet = make(map[*html.Node]bool, len(target)) 141 | for _, n := range target { 142 | targetSet[n] = true 143 | } 144 | } 145 | for _, n := range nodes { 146 | if !targetSet[n] { 147 | target = append(target, n) 148 | targetSet[n] = true 149 | } 150 | } 151 | 152 | return target 153 | } 154 | 155 | // Loop through a selection, returning only those nodes that pass the predicate 156 | // function. 157 | func grep(sel *Selection, predicate func(i int, s *Selection) bool) (result []*html.Node) { 158 | for i, n := range sel.Nodes { 159 | if predicate(i, newSingleSelection(n, sel.document)) { 160 | result = append(result, n) 161 | } 162 | } 163 | return result 164 | } 165 | 166 | // Creates a new Selection object based on the specified nodes, and keeps the 167 | // source Selection object on the stack (linked list). 168 | func pushStack(fromSel *Selection, nodes []*html.Node) *Selection { 169 | result := &Selection{nodes, fromSel.document, fromSel} 170 | return result 171 | } 172 | -------------------------------------------------------------------------------- /vendor/github.com/andybalholm/cascadia/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | go: 4 | - 1.3 5 | - 1.4 6 | 7 | install: 8 | - go get github.com/andybalholm/cascadia 9 | 10 | script: 11 | - go test -v 12 | 13 | notifications: 14 | email: false 15 | -------------------------------------------------------------------------------- /vendor/github.com/andybalholm/cascadia/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011 Andy Balholm. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 15 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 16 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 17 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 18 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 19 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 20 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | -------------------------------------------------------------------------------- /vendor/github.com/andybalholm/cascadia/README.md: -------------------------------------------------------------------------------- 1 | # cascadia 2 | 3 | [![](https://travis-ci.org/andybalholm/cascadia.svg)](https://travis-ci.org/andybalholm/cascadia) 4 | 5 | The Cascadia package implements CSS selectors for use with the parse trees produced by the html package. 6 | 7 | To test CSS selectors without writing Go code, check out [cascadia](https://github.com/suntong/cascadia) the command line tool, a thin wrapper around this package. 8 | 9 | [Refer to godoc here](https://godoc.org/github.com/andybalholm/cascadia). 10 | -------------------------------------------------------------------------------- /vendor/github.com/andybalholm/cascadia/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/andybalholm/cascadia 2 | 3 | require golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01 4 | 5 | go 1.13 6 | -------------------------------------------------------------------------------- /vendor/github.com/andybalholm/cascadia/serialize.go: -------------------------------------------------------------------------------- 1 | package cascadia 2 | 3 | import ( 4 | "fmt" 5 | "strings" 6 | ) 7 | 8 | // implements the reverse operation Sel -> string 9 | 10 | func (c tagSelector) String() string { 11 | return c.tag 12 | } 13 | 14 | func (c idSelector) String() string { 15 | return "#" + c.id 16 | } 17 | 18 | func (c classSelector) String() string { 19 | return "." + c.class 20 | } 21 | 22 | func (c attrSelector) String() string { 23 | val := c.val 24 | if c.operation == "#=" { 25 | val = c.regexp.String() 26 | } else if c.operation != "" { 27 | val = fmt.Sprintf(`"%s"`, val) 28 | } 29 | return fmt.Sprintf(`[%s%s%s]`, c.key, c.operation, val) 30 | } 31 | 32 | func (c relativePseudoClassSelector) String() string { 33 | return fmt.Sprintf(":%s(%s)", c.name, c.match.String()) 34 | } 35 | func (c containsPseudoClassSelector) String() string { 36 | s := "contains" 37 | if c.own { 38 | s += "Own" 39 | } 40 | return fmt.Sprintf(`:%s("%s")`, s, c.value) 41 | } 42 | func (c regexpPseudoClassSelector) String() string { 43 | s := "matches" 44 | if c.own { 45 | s += "Own" 46 | } 47 | return fmt.Sprintf(":%s(%s)", s, c.regexp.String()) 48 | } 49 | func (c nthPseudoClassSelector) String() string { 50 | if c.a == 0 && c.b == 1 { // special cases 51 | s := ":first-" 52 | if c.last { 53 | s = ":last-" 54 | } 55 | if c.ofType { 56 | s += "of-type" 57 | } else { 58 | s += "child" 59 | } 60 | return s 61 | } 62 | var name string 63 | switch [2]bool{c.last, c.ofType} { 64 | case [2]bool{true, true}: 65 | name = "nth-last-of-type" 66 | case [2]bool{true, false}: 67 | name = "nth-last-child" 68 | case [2]bool{false, true}: 69 | name = "nth-of-type" 70 | case [2]bool{false, false}: 71 | name = "nth-child" 72 | } 73 | return fmt.Sprintf(":%s(%dn+%d)", name, c.a, c.b) 74 | } 75 | func (c onlyChildPseudoClassSelector) String() string { 76 | if c.ofType { 77 | return ":only-of-type" 78 | } 79 | return ":only-child" 80 | } 81 | func (c inputPseudoClassSelector) String() string { 82 | return ":input" 83 | } 84 | func (c emptyElementPseudoClassSelector) String() string { 85 | return ":empty" 86 | } 87 | func (c rootPseudoClassSelector) String() string { 88 | return ":root" 89 | } 90 | 91 | func (c compoundSelector) String() string { 92 | if len(c.selectors) == 0 && c.pseudoElement == "" { 93 | return "*" 94 | } 95 | chunks := make([]string, len(c.selectors)) 96 | for i, sel := range c.selectors { 97 | chunks[i] = sel.String() 98 | } 99 | s := strings.Join(chunks, "") 100 | if c.pseudoElement != "" { 101 | s += "::" + c.pseudoElement 102 | } 103 | return s 104 | } 105 | 106 | func (c combinedSelector) String() string { 107 | start := c.first.String() 108 | if c.second != nil { 109 | start += fmt.Sprintf(" %s %s", string(c.combinator), c.second.String()) 110 | } 111 | return start 112 | } 113 | 114 | func (c SelectorGroup) String() string { 115 | ck := make([]string, len(c)) 116 | for i, s := range c { 117 | ck[i] = s.String() 118 | } 119 | return strings.Join(ck, ", ") 120 | } 121 | -------------------------------------------------------------------------------- /vendor/github.com/andybalholm/cascadia/specificity.go: -------------------------------------------------------------------------------- 1 | package cascadia 2 | 3 | // Specificity is the CSS specificity as defined in 4 | // https://www.w3.org/TR/selectors/#specificity-rules 5 | // with the convention Specificity = [A,B,C]. 6 | type Specificity [3]int 7 | 8 | // returns `true` if s < other (strictly), false otherwise 9 | func (s Specificity) Less(other Specificity) bool { 10 | for i := range s { 11 | if s[i] < other[i] { 12 | return true 13 | } 14 | if s[i] > other[i] { 15 | return false 16 | } 17 | } 18 | return false 19 | } 20 | 21 | func (s Specificity) Add(other Specificity) Specificity { 22 | for i, sp := range other { 23 | s[i] += sp 24 | } 25 | return s 26 | } 27 | -------------------------------------------------------------------------------- /vendor/github.com/inconshreveable/mousetrap/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2014 Alan Shreve 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /vendor/github.com/inconshreveable/mousetrap/README.md: -------------------------------------------------------------------------------- 1 | # mousetrap 2 | 3 | mousetrap is a tiny library that answers a single question. 4 | 5 | On a Windows machine, was the process invoked by someone double clicking on 6 | the executable file while browsing in explorer? 7 | 8 | ### Motivation 9 | 10 | Windows developers unfamiliar with command line tools will often "double-click" 11 | the executable for a tool. Because most CLI tools print the help and then exit 12 | when invoked without arguments, this is often very frustrating for those users. 13 | 14 | mousetrap provides a way to detect these invocations so that you can provide 15 | more helpful behavior and instructions on how to run the CLI tool. To see what 16 | this looks like, both from an organizational and a technical perspective, see 17 | https://inconshreveable.com/09-09-2014/sweat-the-small-stuff/ 18 | 19 | ### The interface 20 | 21 | The library exposes a single interface: 22 | 23 | func StartedByExplorer() (bool) 24 | -------------------------------------------------------------------------------- /vendor/github.com/inconshreveable/mousetrap/trap_others.go: -------------------------------------------------------------------------------- 1 | // +build !windows 2 | 3 | package mousetrap 4 | 5 | // StartedByExplorer returns true if the program was invoked by the user 6 | // double-clicking on the executable from explorer.exe 7 | // 8 | // It is conservative and returns false if any of the internal calls fail. 9 | // It does not guarantee that the program was run from a terminal. It only can tell you 10 | // whether it was launched from explorer.exe 11 | // 12 | // On non-Windows platforms, it always returns false. 13 | func StartedByExplorer() bool { 14 | return false 15 | } 16 | -------------------------------------------------------------------------------- /vendor/github.com/inconshreveable/mousetrap/trap_windows.go: -------------------------------------------------------------------------------- 1 | // +build windows 2 | // +build !go1.4 3 | 4 | package mousetrap 5 | 6 | import ( 7 | "fmt" 8 | "os" 9 | "syscall" 10 | "unsafe" 11 | ) 12 | 13 | const ( 14 | // defined by the Win32 API 15 | th32cs_snapprocess uintptr = 0x2 16 | ) 17 | 18 | var ( 19 | kernel = syscall.MustLoadDLL("kernel32.dll") 20 | CreateToolhelp32Snapshot = kernel.MustFindProc("CreateToolhelp32Snapshot") 21 | Process32First = kernel.MustFindProc("Process32FirstW") 22 | Process32Next = kernel.MustFindProc("Process32NextW") 23 | ) 24 | 25 | // ProcessEntry32 structure defined by the Win32 API 26 | type processEntry32 struct { 27 | dwSize uint32 28 | cntUsage uint32 29 | th32ProcessID uint32 30 | th32DefaultHeapID int 31 | th32ModuleID uint32 32 | cntThreads uint32 33 | th32ParentProcessID uint32 34 | pcPriClassBase int32 35 | dwFlags uint32 36 | szExeFile [syscall.MAX_PATH]uint16 37 | } 38 | 39 | func getProcessEntry(pid int) (pe *processEntry32, err error) { 40 | snapshot, _, e1 := CreateToolhelp32Snapshot.Call(th32cs_snapprocess, uintptr(0)) 41 | if snapshot == uintptr(syscall.InvalidHandle) { 42 | err = fmt.Errorf("CreateToolhelp32Snapshot: %v", e1) 43 | return 44 | } 45 | defer syscall.CloseHandle(syscall.Handle(snapshot)) 46 | 47 | var processEntry processEntry32 48 | processEntry.dwSize = uint32(unsafe.Sizeof(processEntry)) 49 | ok, _, e1 := Process32First.Call(snapshot, uintptr(unsafe.Pointer(&processEntry))) 50 | if ok == 0 { 51 | err = fmt.Errorf("Process32First: %v", e1) 52 | return 53 | } 54 | 55 | for { 56 | if processEntry.th32ProcessID == uint32(pid) { 57 | pe = &processEntry 58 | return 59 | } 60 | 61 | ok, _, e1 = Process32Next.Call(snapshot, uintptr(unsafe.Pointer(&processEntry))) 62 | if ok == 0 { 63 | err = fmt.Errorf("Process32Next: %v", e1) 64 | return 65 | } 66 | } 67 | } 68 | 69 | func getppid() (pid int, err error) { 70 | pe, err := getProcessEntry(os.Getpid()) 71 | if err != nil { 72 | return 73 | } 74 | 75 | pid = int(pe.th32ParentProcessID) 76 | return 77 | } 78 | 79 | // StartedByExplorer returns true if the program was invoked by the user double-clicking 80 | // on the executable from explorer.exe 81 | // 82 | // It is conservative and returns false if any of the internal calls fail. 83 | // It does not guarantee that the program was run from a terminal. It only can tell you 84 | // whether it was launched from explorer.exe 85 | func StartedByExplorer() bool { 86 | ppid, err := getppid() 87 | if err != nil { 88 | return false 89 | } 90 | 91 | pe, err := getProcessEntry(ppid) 92 | if err != nil { 93 | return false 94 | } 95 | 96 | name := syscall.UTF16ToString(pe.szExeFile[:]) 97 | return name == "explorer.exe" 98 | } 99 | -------------------------------------------------------------------------------- /vendor/github.com/inconshreveable/mousetrap/trap_windows_1.4.go: -------------------------------------------------------------------------------- 1 | // +build windows 2 | // +build go1.4 3 | 4 | package mousetrap 5 | 6 | import ( 7 | "os" 8 | "syscall" 9 | "unsafe" 10 | ) 11 | 12 | func getProcessEntry(pid int) (*syscall.ProcessEntry32, error) { 13 | snapshot, err := syscall.CreateToolhelp32Snapshot(syscall.TH32CS_SNAPPROCESS, 0) 14 | if err != nil { 15 | return nil, err 16 | } 17 | defer syscall.CloseHandle(snapshot) 18 | var procEntry syscall.ProcessEntry32 19 | procEntry.Size = uint32(unsafe.Sizeof(procEntry)) 20 | if err = syscall.Process32First(snapshot, &procEntry); err != nil { 21 | return nil, err 22 | } 23 | for { 24 | if procEntry.ProcessID == uint32(pid) { 25 | return &procEntry, nil 26 | } 27 | err = syscall.Process32Next(snapshot, &procEntry) 28 | if err != nil { 29 | return nil, err 30 | } 31 | } 32 | } 33 | 34 | // StartedByExplorer returns true if the program was invoked by the user double-clicking 35 | // on the executable from explorer.exe 36 | // 37 | // It is conservative and returns false if any of the internal calls fail. 38 | // It does not guarantee that the program was run from a terminal. It only can tell you 39 | // whether it was launched from explorer.exe 40 | func StartedByExplorer() bool { 41 | pe, err := getProcessEntry(os.Getppid()) 42 | if err != nil { 43 | return false 44 | } 45 | return "explorer.exe" == syscall.UTF16ToString(pe.ExeFile[:]) 46 | } 47 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/cobra/.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # Folders 7 | _obj 8 | _test 9 | 10 | # Architecture specific extensions/prefixes 11 | *.[568vq] 12 | [568vq].out 13 | 14 | *.cgo1.go 15 | *.cgo2.c 16 | _cgo_defun.c 17 | _cgo_gotypes.go 18 | _cgo_export.* 19 | 20 | _testmain.go 21 | 22 | # Vim files https://github.com/github/gitignore/blob/master/Global/Vim.gitignore 23 | # swap 24 | [._]*.s[a-w][a-z] 25 | [._]s[a-w][a-z] 26 | # session 27 | Session.vim 28 | # temporary 29 | .netrwhist 30 | *~ 31 | # auto-generated tag files 32 | tags 33 | 34 | *.exe 35 | cobra.test 36 | bin 37 | 38 | .idea/ 39 | *.iml 40 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/cobra/.mailmap: -------------------------------------------------------------------------------- 1 | Steve Francia 2 | Bjørn Erik Pedersen 3 | Fabiano Franz 4 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/cobra/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | stages: 4 | - diff 5 | - test 6 | - build 7 | 8 | go: 9 | - 1.12.x 10 | - 1.13.x 11 | - tip 12 | 13 | before_install: 14 | - go get -u github.com/kyoh86/richgo 15 | - go get -u github.com/mitchellh/gox 16 | 17 | matrix: 18 | allow_failures: 19 | - go: tip 20 | include: 21 | - stage: diff 22 | go: 1.13.x 23 | script: make fmt 24 | - stage: build 25 | go: 1.13.x 26 | script: make cobra_generator 27 | 28 | script: 29 | - make test 30 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/cobra/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Cobra Changelog 2 | 3 | ## Pending 4 | * Fix man page doc generation - no auto generated tag when `cmd.DisableAutoGenTag = true` @jpmcb 5 | 6 | ## v1.0.0 7 | Announcing v1.0.0 of Cobra. 🎉 8 | **Notable Changes** 9 | * Fish completion (including support for Go custom completion) @marckhouzam 10 | * API (urgent): Rename BashCompDirectives to ShellCompDirectives @marckhouzam 11 | * Remove/replace SetOutput on Command - deprecated @jpmcb 12 | * add support for autolabel stale PR @xchapter7x 13 | * Add Labeler Actions @xchapter7x 14 | * Custom completions coded in Go (instead of Bash) @marckhouzam 15 | * Partial Revert of #922 @jharshman 16 | * Add Makefile to project @jharshman 17 | * Correct documentation for InOrStdin @desponda 18 | * Apply formatting to templates @jharshman 19 | * Revert change so help is printed on stdout again @marckhouzam 20 | * Update md2man to v2.0.0 @pdf 21 | * update viper to v1.4.0 @umarcor 22 | * Update cmd/root.go example in README.md @jharshman 23 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/cobra/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to Cobra 2 | 3 | Thank you so much for contributing to Cobra. We appreciate your time and help. 4 | Here are some guidelines to help you get started. 5 | 6 | ## Code of Conduct 7 | 8 | Be kind and respectful to the members of the community. Take time to educate 9 | others who are seeking help. Harassment of any kind will not be tolerated. 10 | 11 | ## Questions 12 | 13 | If you have questions regarding Cobra, feel free to ask it in the community 14 | [#cobra Slack channel][cobra-slack] 15 | 16 | ## Filing a bug or feature 17 | 18 | 1. Before filing an issue, please check the existing issues to see if a 19 | similar one was already opened. If there is one already opened, feel free 20 | to comment on it. 21 | 1. If you believe you've found a bug, please provide detailed steps of 22 | reproduction, the version of Cobra and anything else you believe will be 23 | useful to help troubleshoot it (e.g. OS environment, environment variables, 24 | etc...). Also state the current behavior vs. the expected behavior. 25 | 1. If you'd like to see a feature or an enhancement please open an issue with 26 | a clear title and description of what the feature is and why it would be 27 | beneficial to the project and its users. 28 | 29 | ## Submitting changes 30 | 31 | 1. CLA: Upon submitting a Pull Request (PR), contributors will be prompted to 32 | sign a CLA. Please sign the CLA :slightly_smiling_face: 33 | 1. Tests: If you are submitting code, please ensure you have adequate tests 34 | for the feature. Tests can be run via `go test ./...` or `make test`. 35 | 1. Since this is golang project, ensure the new code is properly formatted to 36 | ensure code consistency. Run `make all`. 37 | 38 | ### Quick steps to contribute 39 | 40 | 1. Fork the project. 41 | 1. Download your fork to your PC (`git clone https://github.com/your_username/cobra && cd cobra`) 42 | 1. Create your feature branch (`git checkout -b my-new-feature`) 43 | 1. Make changes and run tests (`make test`) 44 | 1. Add them to staging (`git add .`) 45 | 1. Commit your changes (`git commit -m 'Add some feature'`) 46 | 1. Push to the branch (`git push origin my-new-feature`) 47 | 1. Create new pull request 48 | 49 | 50 | [cobra-slack]: https://gophers.slack.com/archives/CD3LP1199 51 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/cobra/Makefile: -------------------------------------------------------------------------------- 1 | BIN="./bin" 2 | SRC=$(shell find . -name "*.go") 3 | 4 | ifeq (, $(shell which richgo)) 5 | $(warning "could not find richgo in $(PATH), run: go get github.com/kyoh86/richgo") 6 | endif 7 | 8 | .PHONY: fmt vet test cobra_generator install_deps clean 9 | 10 | default: all 11 | 12 | all: fmt vet test cobra_generator 13 | 14 | fmt: 15 | $(info ******************** checking formatting ********************) 16 | @test -z $(shell gofmt -l $(SRC)) || (gofmt -d $(SRC); exit 1) 17 | 18 | test: install_deps vet 19 | $(info ******************** running tests ********************) 20 | richgo test -v ./... 21 | 22 | cobra_generator: install_deps 23 | $(info ******************** building generator ********************) 24 | mkdir -p $(BIN) 25 | make -C cobra all 26 | 27 | install_deps: 28 | $(info ******************** downloading dependencies ********************) 29 | go get -v ./... 30 | 31 | vet: 32 | $(info ******************** vetting ********************) 33 | go vet ./... 34 | 35 | clean: 36 | rm -rf $(BIN) 37 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/cobra/args.go: -------------------------------------------------------------------------------- 1 | package cobra 2 | 3 | import ( 4 | "fmt" 5 | "strings" 6 | ) 7 | 8 | type PositionalArgs func(cmd *Command, args []string) error 9 | 10 | // Legacy arg validation has the following behaviour: 11 | // - root commands with no subcommands can take arbitrary arguments 12 | // - root commands with subcommands will do subcommand validity checking 13 | // - subcommands will always accept arbitrary arguments 14 | func legacyArgs(cmd *Command, args []string) error { 15 | // no subcommand, always take args 16 | if !cmd.HasSubCommands() { 17 | return nil 18 | } 19 | 20 | // root command with subcommands, do subcommand checking. 21 | if !cmd.HasParent() && len(args) > 0 { 22 | return fmt.Errorf("unknown command %q for %q%s", args[0], cmd.CommandPath(), cmd.findSuggestions(args[0])) 23 | } 24 | return nil 25 | } 26 | 27 | // NoArgs returns an error if any args are included. 28 | func NoArgs(cmd *Command, args []string) error { 29 | if len(args) > 0 { 30 | return fmt.Errorf("unknown command %q for %q", args[0], cmd.CommandPath()) 31 | } 32 | return nil 33 | } 34 | 35 | // OnlyValidArgs returns an error if any args are not in the list of ValidArgs. 36 | func OnlyValidArgs(cmd *Command, args []string) error { 37 | if len(cmd.ValidArgs) > 0 { 38 | // Remove any description that may be included in ValidArgs. 39 | // A description is following a tab character. 40 | var validArgs []string 41 | for _, v := range cmd.ValidArgs { 42 | validArgs = append(validArgs, strings.Split(v, "\t")[0]) 43 | } 44 | 45 | for _, v := range args { 46 | if !stringInSlice(v, validArgs) { 47 | return fmt.Errorf("invalid argument %q for %q%s", v, cmd.CommandPath(), cmd.findSuggestions(args[0])) 48 | } 49 | } 50 | } 51 | return nil 52 | } 53 | 54 | // ArbitraryArgs never returns an error. 55 | func ArbitraryArgs(cmd *Command, args []string) error { 56 | return nil 57 | } 58 | 59 | // MinimumNArgs returns an error if there is not at least N args. 60 | func MinimumNArgs(n int) PositionalArgs { 61 | return func(cmd *Command, args []string) error { 62 | if len(args) < n { 63 | return fmt.Errorf("requires at least %d arg(s), only received %d", n, len(args)) 64 | } 65 | return nil 66 | } 67 | } 68 | 69 | // MaximumNArgs returns an error if there are more than N args. 70 | func MaximumNArgs(n int) PositionalArgs { 71 | return func(cmd *Command, args []string) error { 72 | if len(args) > n { 73 | return fmt.Errorf("accepts at most %d arg(s), received %d", n, len(args)) 74 | } 75 | return nil 76 | } 77 | } 78 | 79 | // ExactArgs returns an error if there are not exactly n args. 80 | func ExactArgs(n int) PositionalArgs { 81 | return func(cmd *Command, args []string) error { 82 | if len(args) != n { 83 | return fmt.Errorf("accepts %d arg(s), received %d", n, len(args)) 84 | } 85 | return nil 86 | } 87 | } 88 | 89 | // ExactValidArgs returns an error if 90 | // there are not exactly N positional args OR 91 | // there are any positional args that are not in the `ValidArgs` field of `Command` 92 | func ExactValidArgs(n int) PositionalArgs { 93 | return func(cmd *Command, args []string) error { 94 | if err := ExactArgs(n)(cmd, args); err != nil { 95 | return err 96 | } 97 | return OnlyValidArgs(cmd, args) 98 | } 99 | } 100 | 101 | // RangeArgs returns an error if the number of args is not within the expected range. 102 | func RangeArgs(min int, max int) PositionalArgs { 103 | return func(cmd *Command, args []string) error { 104 | if len(args) < min || len(args) > max { 105 | return fmt.Errorf("accepts between %d and %d arg(s), received %d", min, max, len(args)) 106 | } 107 | return nil 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/cobra/bash_completions.md: -------------------------------------------------------------------------------- 1 | # Generating Bash Completions For Your cobra.Command 2 | 3 | Please refer to [Shell Completions](shell_completions.md) for details. 4 | 5 | ## Bash legacy dynamic completions 6 | 7 | For backwards-compatibility, Cobra still supports its legacy dynamic completion solution (described below). Unlike the `ValidArgsFunction` solution, the legacy solution will only work for Bash shell-completion and not for other shells. This legacy solution can be used along-side `ValidArgsFunction` and `RegisterFlagCompletionFunc()`, as long as both solutions are not used for the same command. This provides a path to gradually migrate from the legacy solution to the new solution. 8 | 9 | The legacy solution allows you to inject bash functions into the bash completion script. Those bash functions are responsible for providing the completion choices for your own completions. 10 | 11 | Some code that works in kubernetes: 12 | 13 | ```bash 14 | const ( 15 | bash_completion_func = `__kubectl_parse_get() 16 | { 17 | local kubectl_output out 18 | if kubectl_output=$(kubectl get --no-headers "$1" 2>/dev/null); then 19 | out=($(echo "${kubectl_output}" | awk '{print $1}')) 20 | COMPREPLY=( $( compgen -W "${out[*]}" -- "$cur" ) ) 21 | fi 22 | } 23 | 24 | __kubectl_get_resource() 25 | { 26 | if [[ ${#nouns[@]} -eq 0 ]]; then 27 | return 1 28 | fi 29 | __kubectl_parse_get ${nouns[${#nouns[@]} -1]} 30 | if [[ $? -eq 0 ]]; then 31 | return 0 32 | fi 33 | } 34 | 35 | __kubectl_custom_func() { 36 | case ${last_command} in 37 | kubectl_get | kubectl_describe | kubectl_delete | kubectl_stop) 38 | __kubectl_get_resource 39 | return 40 | ;; 41 | *) 42 | ;; 43 | esac 44 | } 45 | `) 46 | ``` 47 | 48 | And then I set that in my command definition: 49 | 50 | ```go 51 | cmds := &cobra.Command{ 52 | Use: "kubectl", 53 | Short: "kubectl controls the Kubernetes cluster manager", 54 | Long: `kubectl controls the Kubernetes cluster manager. 55 | 56 | Find more information at https://github.com/GoogleCloudPlatform/kubernetes.`, 57 | Run: runHelp, 58 | BashCompletionFunction: bash_completion_func, 59 | } 60 | ``` 61 | 62 | The `BashCompletionFunction` option is really only valid/useful on the root command. Doing the above will cause `__kubectl_custom_func()` (`___custom_func()`) to be called when the built in processor was unable to find a solution. In the case of kubernetes a valid command might look something like `kubectl get pod [mypod]`. If you type `kubectl get pod [tab][tab]` the `__kubectl_customc_func()` will run because the cobra.Command only understood "kubectl" and "get." `__kubectl_custom_func()` will see that the cobra.Command is "kubectl_get" and will thus call another helper `__kubectl_get_resource()`. `__kubectl_get_resource` will look at the 'nouns' collected. In our example the only noun will be `pod`. So it will call `__kubectl_parse_get pod`. `__kubectl_parse_get` will actually call out to kubernetes and get any pods. It will then set `COMPREPLY` to valid pods! 63 | 64 | Similarly, for flags: 65 | 66 | ```go 67 | annotation := make(map[string][]string) 68 | annotation[cobra.BashCompCustom] = []string{"__kubectl_get_namespaces"} 69 | 70 | flag := &pflag.Flag{ 71 | Name: "namespace", 72 | Usage: usage, 73 | Annotations: annotation, 74 | } 75 | cmd.Flags().AddFlag(flag) 76 | ``` 77 | 78 | In addition add the `__kubectl_get_namespaces` implementation in the `BashCompletionFunction` 79 | value, e.g.: 80 | 81 | ```bash 82 | __kubectl_get_namespaces() 83 | { 84 | local template 85 | template="{{ range .items }}{{ .metadata.name }} {{ end }}" 86 | local kubectl_out 87 | if kubectl_out=$(kubectl get -o template --template="${template}" namespace 2>/dev/null); then 88 | COMPREPLY=( $( compgen -W "${kubectl_out}[*]" -- "$cur" ) ) 89 | fi 90 | } 91 | ``` 92 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/cobra/command_notwin.go: -------------------------------------------------------------------------------- 1 | // +build !windows 2 | 3 | package cobra 4 | 5 | var preExecHookFn func(*Command) 6 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/cobra/command_win.go: -------------------------------------------------------------------------------- 1 | // +build windows 2 | 3 | package cobra 4 | 5 | import ( 6 | "fmt" 7 | "os" 8 | "time" 9 | 10 | "github.com/inconshreveable/mousetrap" 11 | ) 12 | 13 | var preExecHookFn = preExecHook 14 | 15 | func preExecHook(c *Command) { 16 | if MousetrapHelpText != "" && mousetrap.StartedByExplorer() { 17 | c.Print(MousetrapHelpText) 18 | if MousetrapDisplayDuration > 0 { 19 | time.Sleep(MousetrapDisplayDuration) 20 | } else { 21 | c.Println("Press return to continue...") 22 | fmt.Scanln() 23 | } 24 | os.Exit(1) 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/cobra/fish_completions.md: -------------------------------------------------------------------------------- 1 | ## Generating Fish Completions For Your cobra.Command 2 | 3 | Please refer to [Shell Completions](shell_completions.md) for details. 4 | 5 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/cobra/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/spf13/cobra 2 | 3 | go 1.12 4 | 5 | require ( 6 | github.com/cpuguy83/go-md2man/v2 v2.0.0 7 | github.com/inconshreveable/mousetrap v1.0.0 8 | github.com/mitchellh/go-homedir v1.1.0 9 | github.com/spf13/pflag v1.0.5 10 | github.com/spf13/viper v1.7.0 11 | gopkg.in/yaml.v2 v2.2.8 12 | ) 13 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/cobra/powershell_completions.go: -------------------------------------------------------------------------------- 1 | // PowerShell completions are based on the amazing work from clap: 2 | // https://github.com/clap-rs/clap/blob/3294d18efe5f264d12c9035f404c7d189d4824e1/src/completions/powershell.rs 3 | // 4 | // The generated scripts require PowerShell v5.0+ (which comes Windows 10, but 5 | // can be downloaded separately for windows 7 or 8.1). 6 | 7 | package cobra 8 | 9 | import ( 10 | "bytes" 11 | "fmt" 12 | "io" 13 | "os" 14 | "strings" 15 | 16 | "github.com/spf13/pflag" 17 | ) 18 | 19 | var powerShellCompletionTemplate = `using namespace System.Management.Automation 20 | using namespace System.Management.Automation.Language 21 | Register-ArgumentCompleter -Native -CommandName '%s' -ScriptBlock { 22 | param($wordToComplete, $commandAst, $cursorPosition) 23 | $commandElements = $commandAst.CommandElements 24 | $command = @( 25 | '%s' 26 | for ($i = 1; $i -lt $commandElements.Count; $i++) { 27 | $element = $commandElements[$i] 28 | if ($element -isnot [StringConstantExpressionAst] -or 29 | $element.StringConstantType -ne [StringConstantType]::BareWord -or 30 | $element.Value.StartsWith('-')) { 31 | break 32 | } 33 | $element.Value 34 | } 35 | ) -join ';' 36 | $completions = @(switch ($command) {%s 37 | }) 38 | $completions.Where{ $_.CompletionText -like "$wordToComplete*" } | 39 | Sort-Object -Property ListItemText 40 | }` 41 | 42 | func generatePowerShellSubcommandCases(out io.Writer, cmd *Command, previousCommandName string) { 43 | var cmdName string 44 | if previousCommandName == "" { 45 | cmdName = cmd.Name() 46 | } else { 47 | cmdName = fmt.Sprintf("%s;%s", previousCommandName, cmd.Name()) 48 | } 49 | 50 | fmt.Fprintf(out, "\n '%s' {", cmdName) 51 | 52 | cmd.Flags().VisitAll(func(flag *pflag.Flag) { 53 | if nonCompletableFlag(flag) { 54 | return 55 | } 56 | usage := escapeStringForPowerShell(flag.Usage) 57 | if len(flag.Shorthand) > 0 { 58 | fmt.Fprintf(out, "\n [CompletionResult]::new('-%s', '%s', [CompletionResultType]::ParameterName, '%s')", flag.Shorthand, flag.Shorthand, usage) 59 | } 60 | fmt.Fprintf(out, "\n [CompletionResult]::new('--%s', '%s', [CompletionResultType]::ParameterName, '%s')", flag.Name, flag.Name, usage) 61 | }) 62 | 63 | for _, subCmd := range cmd.Commands() { 64 | usage := escapeStringForPowerShell(subCmd.Short) 65 | fmt.Fprintf(out, "\n [CompletionResult]::new('%s', '%s', [CompletionResultType]::ParameterValue, '%s')", subCmd.Name(), subCmd.Name(), usage) 66 | } 67 | 68 | fmt.Fprint(out, "\n break\n }") 69 | 70 | for _, subCmd := range cmd.Commands() { 71 | generatePowerShellSubcommandCases(out, subCmd, cmdName) 72 | } 73 | } 74 | 75 | func escapeStringForPowerShell(s string) string { 76 | return strings.Replace(s, "'", "''", -1) 77 | } 78 | 79 | // GenPowerShellCompletion generates PowerShell completion file and writes to the passed writer. 80 | func (c *Command) GenPowerShellCompletion(w io.Writer) error { 81 | buf := new(bytes.Buffer) 82 | 83 | var subCommandCases bytes.Buffer 84 | generatePowerShellSubcommandCases(&subCommandCases, c, "") 85 | fmt.Fprintf(buf, powerShellCompletionTemplate, c.Name(), c.Name(), subCommandCases.String()) 86 | 87 | _, err := buf.WriteTo(w) 88 | return err 89 | } 90 | 91 | // GenPowerShellCompletionFile generates PowerShell completion file. 92 | func (c *Command) GenPowerShellCompletionFile(filename string) error { 93 | outFile, err := os.Create(filename) 94 | if err != nil { 95 | return err 96 | } 97 | defer outFile.Close() 98 | 99 | return c.GenPowerShellCompletion(outFile) 100 | } 101 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/cobra/powershell_completions.md: -------------------------------------------------------------------------------- 1 | # Generating PowerShell Completions For Your Own cobra.Command 2 | 3 | Cobra can generate PowerShell completion scripts. Users need PowerShell version 5.0 or above, which comes with Windows 10 and can be downloaded separately for Windows 7 or 8.1. They can then write the completions to a file and source this file from their PowerShell profile, which is referenced by the `$Profile` environment variable. See `Get-Help about_Profiles` for more info about PowerShell profiles. 4 | 5 | *Note*: PowerShell completions have not (yet?) been aligned to Cobra's generic shell completion support. This implies the PowerShell completions are not as rich as for other shells (see [What's not yet supported](#whats-not-yet-supported)), and may behave slightly differently. They are still very useful for PowerShell users. 6 | 7 | # What's supported 8 | 9 | - Completion for subcommands using their `.Short` description 10 | - Completion for non-hidden flags using their `.Name` and `.Shorthand` 11 | 12 | # What's not yet supported 13 | 14 | - Command aliases 15 | - Required, filename or custom flags (they will work like normal flags) 16 | - Custom completion scripts 17 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/cobra/projects_using_cobra.md: -------------------------------------------------------------------------------- 1 | ## Projects using Cobra 2 | 3 | - [Arduino CLI](https://github.com/arduino/arduino-cli) 4 | - [Bleve](http://www.blevesearch.com/) 5 | - [CockroachDB](http://www.cockroachlabs.com/) 6 | - [Cosmos SDK](https://github.com/cosmos/cosmos-sdk) 7 | - [Delve](https://github.com/derekparker/delve) 8 | - [Docker (distribution)](https://github.com/docker/distribution) 9 | - [Etcd](https://etcd.io/) 10 | - [Gardener](https://github.com/gardener/gardenctl) 11 | - [Giant Swarm's gsctl](https://github.com/giantswarm/gsctl) 12 | - [Git Bump](https://github.com/erdaltsksn/git-bump) 13 | - [Github CLI](https://github.com/cli/cli) 14 | - [GitHub Labeler](https://github.com/erdaltsksn/gh-label) 15 | - [Golangci-lint](https://golangci-lint.run) 16 | - [GopherJS](http://www.gopherjs.org/) 17 | - [Helm](https://helm.sh) 18 | - [Hugo](https://gohugo.io) 19 | - [Istio](https://istio.io) 20 | - [Kool](https://github.com/kool-dev/kool) 21 | - [Kubernetes](http://kubernetes.io/) 22 | - [Linkerd](https://linkerd.io/) 23 | - [Mattermost-server](https://github.com/mattermost/mattermost-server) 24 | - [Metal Stack CLI](https://github.com/metal-stack/metalctl) 25 | - [Moby (former Docker)](https://github.com/moby/moby) 26 | - [Nanobox](https://github.com/nanobox-io/nanobox)/[Nanopack](https://github.com/nanopack) 27 | - [OpenShift](https://www.openshift.com/) 28 | - [Pouch](https://github.com/alibaba/pouch) 29 | - [ProjectAtomic (enterprise)](http://www.projectatomic.io/) 30 | - [Prototool](https://github.com/uber/prototool) 31 | - [Random](https://github.com/erdaltsksn/random) 32 | - [Rclone](https://rclone.org/) 33 | - [Skaffold](https://skaffold.dev/) 34 | - [Tendermint](https://github.com/tendermint/tendermint) 35 | - [Werf](https://werf.io/) 36 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/cobra/shell_completions.go: -------------------------------------------------------------------------------- 1 | package cobra 2 | 3 | import ( 4 | "github.com/spf13/pflag" 5 | ) 6 | 7 | // MarkFlagRequired instructs the various shell completion implementations to 8 | // prioritize the named flag when performing completion, 9 | // and causes your command to report an error if invoked without the flag. 10 | func (c *Command) MarkFlagRequired(name string) error { 11 | return MarkFlagRequired(c.Flags(), name) 12 | } 13 | 14 | // MarkPersistentFlagRequired instructs the various shell completion implementations to 15 | // prioritize the named persistent flag when performing completion, 16 | // and causes your command to report an error if invoked without the flag. 17 | func (c *Command) MarkPersistentFlagRequired(name string) error { 18 | return MarkFlagRequired(c.PersistentFlags(), name) 19 | } 20 | 21 | // MarkFlagRequired instructs the various shell completion implementations to 22 | // prioritize the named flag when performing completion, 23 | // and causes your command to report an error if invoked without the flag. 24 | func MarkFlagRequired(flags *pflag.FlagSet, name string) error { 25 | return flags.SetAnnotation(name, BashCompOneRequiredFlag, []string{"true"}) 26 | } 27 | 28 | // MarkFlagFilename instructs the various shell completion implementations to 29 | // limit completions for the named flag to the specified file extensions. 30 | func (c *Command) MarkFlagFilename(name string, extensions ...string) error { 31 | return MarkFlagFilename(c.Flags(), name, extensions...) 32 | } 33 | 34 | // MarkFlagCustom adds the BashCompCustom annotation to the named flag, if it exists. 35 | // The bash completion script will call the bash function f for the flag. 36 | // 37 | // This will only work for bash completion. 38 | // It is recommended to instead use c.RegisterFlagCompletionFunc(...) which allows 39 | // to register a Go function which will work across all shells. 40 | func (c *Command) MarkFlagCustom(name string, f string) error { 41 | return MarkFlagCustom(c.Flags(), name, f) 42 | } 43 | 44 | // MarkPersistentFlagFilename instructs the various shell completion 45 | // implementations to limit completions for the named persistent flag to the 46 | // specified file extensions. 47 | func (c *Command) MarkPersistentFlagFilename(name string, extensions ...string) error { 48 | return MarkFlagFilename(c.PersistentFlags(), name, extensions...) 49 | } 50 | 51 | // MarkFlagFilename instructs the various shell completion implementations to 52 | // limit completions for the named flag to the specified file extensions. 53 | func MarkFlagFilename(flags *pflag.FlagSet, name string, extensions ...string) error { 54 | return flags.SetAnnotation(name, BashCompFilenameExt, extensions) 55 | } 56 | 57 | // MarkFlagCustom adds the BashCompCustom annotation to the named flag, if it exists. 58 | // The bash completion script will call the bash function f for the flag. 59 | // 60 | // This will only work for bash completion. 61 | // It is recommended to instead use c.RegisterFlagCompletionFunc(...) which allows 62 | // to register a Go function which will work across all shells. 63 | func MarkFlagCustom(flags *pflag.FlagSet, name string, f string) error { 64 | return flags.SetAnnotation(name, BashCompCustom, []string{f}) 65 | } 66 | 67 | // MarkFlagDirname instructs the various shell completion implementations to 68 | // limit completions for the named flag to directory names. 69 | func (c *Command) MarkFlagDirname(name string) error { 70 | return MarkFlagDirname(c.Flags(), name) 71 | } 72 | 73 | // MarkPersistentFlagDirname instructs the various shell completion 74 | // implementations to limit completions for the named persistent flag to 75 | // directory names. 76 | func (c *Command) MarkPersistentFlagDirname(name string) error { 77 | return MarkFlagDirname(c.PersistentFlags(), name) 78 | } 79 | 80 | // MarkFlagDirname instructs the various shell completion implementations to 81 | // limit completions for the named flag to directory names. 82 | func MarkFlagDirname(flags *pflag.FlagSet, name string) error { 83 | return flags.SetAnnotation(name, BashCompSubdirsInDir, []string{}) 84 | } 85 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/cobra/zsh_completions.md: -------------------------------------------------------------------------------- 1 | ## Generating Zsh Completion For Your cobra.Command 2 | 3 | Please refer to [Shell Completions](shell_completions.md) for details. 4 | 5 | ## Zsh completions standardization 6 | 7 | Cobra 1.1 standardized its zsh completion support to align it with its other shell completions. Although the API was kept backwards-compatible, some small changes in behavior were introduced. 8 | 9 | ### Deprecation summary 10 | 11 | See further below for more details on these deprecations. 12 | 13 | * `cmd.MarkZshCompPositionalArgumentFile(pos, []string{})` is no longer needed. It is therefore **deprecated** and silently ignored. 14 | * `cmd.MarkZshCompPositionalArgumentFile(pos, glob[])` is **deprecated** and silently ignored. 15 | * Instead use `ValidArgsFunction` with `ShellCompDirectiveFilterFileExt`. 16 | * `cmd.MarkZshCompPositionalArgumentWords()` is **deprecated** and silently ignored. 17 | * Instead use `ValidArgsFunction`. 18 | 19 | ### Behavioral changes 20 | 21 | **Noun completion** 22 | |Old behavior|New behavior| 23 | |---|---| 24 | |No file completion by default (opposite of bash)|File completion by default; use `ValidArgsFunction` with `ShellCompDirectiveNoFileComp` to turn off file completion on a per-argument basis| 25 | |Completion of flag names without the `-` prefix having been typed|Flag names are only completed if the user has typed the first `-`| 26 | `cmd.MarkZshCompPositionalArgumentFile(pos, []string{})` used to turn on file completion on a per-argument position basis|File completion for all arguments by default; `cmd.MarkZshCompPositionalArgumentFile()` is **deprecated** and silently ignored| 27 | |`cmd.MarkZshCompPositionalArgumentFile(pos, glob[])` used to turn on file completion **with glob filtering** on a per-argument position basis (zsh-specific)|`cmd.MarkZshCompPositionalArgumentFile()` is **deprecated** and silently ignored; use `ValidArgsFunction` with `ShellCompDirectiveFilterFileExt` for file **extension** filtering (not full glob filtering)| 28 | |`cmd.MarkZshCompPositionalArgumentWords(pos, words[])` used to provide completion choices on a per-argument position basis (zsh-specific)|`cmd.MarkZshCompPositionalArgumentWords()` is **deprecated** and silently ignored; use `ValidArgsFunction` to achieve the same behavior| 29 | 30 | **Flag-value completion** 31 | 32 | |Old behavior|New behavior| 33 | |---|---| 34 | |No file completion by default (opposite of bash)|File completion by default; use `RegisterFlagCompletionFunc()` with `ShellCompDirectiveNoFileComp` to turn off file completion| 35 | |`cmd.MarkFlagFilename(flag, []string{})` and similar used to turn on file completion|File completion by default; `cmd.MarkFlagFilename(flag, []string{})` no longer needed in this context and silently ignored| 36 | |`cmd.MarkFlagFilename(flag, glob[])` used to turn on file completion **with glob filtering** (syntax of `[]string{"*.yaml", "*.yml"}` incompatible with bash)|Will continue to work, however, support for bash syntax is added and should be used instead so as to work for all shells (`[]string{"yaml", "yml"}`)| 37 | |`cmd.MarkFlagDirname(flag)` only completes directories (zsh-specific)|Has been added for all shells| 38 | |Completion of a flag name does not repeat, unless flag is of type `*Array` or `*Slice` (not supported by bash)|Retained for `zsh` and added to `fish`| 39 | |Completion of a flag name does not provide the `=` form (unlike bash)|Retained for `zsh` and added to `fish`| 40 | 41 | **Improvements** 42 | 43 | * Custom completion support (`ValidArgsFunction` and `RegisterFlagCompletionFunc()`) 44 | * File completion by default if no other completions found 45 | * Handling of required flags 46 | * File extension filtering no longer mutually exclusive with bash usage 47 | * Completion of directory names *within* another directory 48 | * Support for `=` form of flags 49 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/.gitignore: -------------------------------------------------------------------------------- 1 | .idea/* 2 | 3 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | 3 | language: go 4 | 5 | go: 6 | - 1.9.x 7 | - 1.10.x 8 | - 1.11.x 9 | - tip 10 | 11 | matrix: 12 | allow_failures: 13 | - go: tip 14 | 15 | install: 16 | - go get golang.org/x/lint/golint 17 | - export PATH=$GOPATH/bin:$PATH 18 | - go install ./... 19 | 20 | script: 21 | - verify/all.sh -v 22 | - go test ./... 23 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 Alex Ogier. All rights reserved. 2 | Copyright (c) 2012 The Go Authors. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are 6 | met: 7 | 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above 11 | copyright notice, this list of conditions and the following disclaimer 12 | in the documentation and/or other materials provided with the 13 | distribution. 14 | * Neither the name of Google Inc. nor the names of its 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/bool.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // optional interface to indicate boolean flags that can be 6 | // supplied without "=value" text 7 | type boolFlag interface { 8 | Value 9 | IsBoolFlag() bool 10 | } 11 | 12 | // -- bool Value 13 | type boolValue bool 14 | 15 | func newBoolValue(val bool, p *bool) *boolValue { 16 | *p = val 17 | return (*boolValue)(p) 18 | } 19 | 20 | func (b *boolValue) Set(s string) error { 21 | v, err := strconv.ParseBool(s) 22 | *b = boolValue(v) 23 | return err 24 | } 25 | 26 | func (b *boolValue) Type() string { 27 | return "bool" 28 | } 29 | 30 | func (b *boolValue) String() string { return strconv.FormatBool(bool(*b)) } 31 | 32 | func (b *boolValue) IsBoolFlag() bool { return true } 33 | 34 | func boolConv(sval string) (interface{}, error) { 35 | return strconv.ParseBool(sval) 36 | } 37 | 38 | // GetBool return the bool value of a flag with the given name 39 | func (f *FlagSet) GetBool(name string) (bool, error) { 40 | val, err := f.getFlagType(name, "bool", boolConv) 41 | if err != nil { 42 | return false, err 43 | } 44 | return val.(bool), nil 45 | } 46 | 47 | // BoolVar defines a bool flag with specified name, default value, and usage string. 48 | // The argument p points to a bool variable in which to store the value of the flag. 49 | func (f *FlagSet) BoolVar(p *bool, name string, value bool, usage string) { 50 | f.BoolVarP(p, name, "", value, usage) 51 | } 52 | 53 | // BoolVarP is like BoolVar, but accepts a shorthand letter that can be used after a single dash. 54 | func (f *FlagSet) BoolVarP(p *bool, name, shorthand string, value bool, usage string) { 55 | flag := f.VarPF(newBoolValue(value, p), name, shorthand, usage) 56 | flag.NoOptDefVal = "true" 57 | } 58 | 59 | // BoolVar defines a bool flag with specified name, default value, and usage string. 60 | // The argument p points to a bool variable in which to store the value of the flag. 61 | func BoolVar(p *bool, name string, value bool, usage string) { 62 | BoolVarP(p, name, "", value, usage) 63 | } 64 | 65 | // BoolVarP is like BoolVar, but accepts a shorthand letter that can be used after a single dash. 66 | func BoolVarP(p *bool, name, shorthand string, value bool, usage string) { 67 | flag := CommandLine.VarPF(newBoolValue(value, p), name, shorthand, usage) 68 | flag.NoOptDefVal = "true" 69 | } 70 | 71 | // Bool defines a bool flag with specified name, default value, and usage string. 72 | // The return value is the address of a bool variable that stores the value of the flag. 73 | func (f *FlagSet) Bool(name string, value bool, usage string) *bool { 74 | return f.BoolP(name, "", value, usage) 75 | } 76 | 77 | // BoolP is like Bool, but accepts a shorthand letter that can be used after a single dash. 78 | func (f *FlagSet) BoolP(name, shorthand string, value bool, usage string) *bool { 79 | p := new(bool) 80 | f.BoolVarP(p, name, shorthand, value, usage) 81 | return p 82 | } 83 | 84 | // Bool defines a bool flag with specified name, default value, and usage string. 85 | // The return value is the address of a bool variable that stores the value of the flag. 86 | func Bool(name string, value bool, usage string) *bool { 87 | return BoolP(name, "", value, usage) 88 | } 89 | 90 | // BoolP is like Bool, but accepts a shorthand letter that can be used after a single dash. 91 | func BoolP(name, shorthand string, value bool, usage string) *bool { 92 | b := CommandLine.BoolP(name, shorthand, value, usage) 93 | return b 94 | } 95 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/count.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- count Value 6 | type countValue int 7 | 8 | func newCountValue(val int, p *int) *countValue { 9 | *p = val 10 | return (*countValue)(p) 11 | } 12 | 13 | func (i *countValue) Set(s string) error { 14 | // "+1" means that no specific value was passed, so increment 15 | if s == "+1" { 16 | *i = countValue(*i + 1) 17 | return nil 18 | } 19 | v, err := strconv.ParseInt(s, 0, 0) 20 | *i = countValue(v) 21 | return err 22 | } 23 | 24 | func (i *countValue) Type() string { 25 | return "count" 26 | } 27 | 28 | func (i *countValue) String() string { return strconv.Itoa(int(*i)) } 29 | 30 | func countConv(sval string) (interface{}, error) { 31 | i, err := strconv.Atoi(sval) 32 | if err != nil { 33 | return nil, err 34 | } 35 | return i, nil 36 | } 37 | 38 | // GetCount return the int value of a flag with the given name 39 | func (f *FlagSet) GetCount(name string) (int, error) { 40 | val, err := f.getFlagType(name, "count", countConv) 41 | if err != nil { 42 | return 0, err 43 | } 44 | return val.(int), nil 45 | } 46 | 47 | // CountVar defines a count flag with specified name, default value, and usage string. 48 | // The argument p points to an int variable in which to store the value of the flag. 49 | // A count flag will add 1 to its value every time it is found on the command line 50 | func (f *FlagSet) CountVar(p *int, name string, usage string) { 51 | f.CountVarP(p, name, "", usage) 52 | } 53 | 54 | // CountVarP is like CountVar only take a shorthand for the flag name. 55 | func (f *FlagSet) CountVarP(p *int, name, shorthand string, usage string) { 56 | flag := f.VarPF(newCountValue(0, p), name, shorthand, usage) 57 | flag.NoOptDefVal = "+1" 58 | } 59 | 60 | // CountVar like CountVar only the flag is placed on the CommandLine instead of a given flag set 61 | func CountVar(p *int, name string, usage string) { 62 | CommandLine.CountVar(p, name, usage) 63 | } 64 | 65 | // CountVarP is like CountVar only take a shorthand for the flag name. 66 | func CountVarP(p *int, name, shorthand string, usage string) { 67 | CommandLine.CountVarP(p, name, shorthand, usage) 68 | } 69 | 70 | // Count defines a count flag with specified name, default value, and usage string. 71 | // The return value is the address of an int variable that stores the value of the flag. 72 | // A count flag will add 1 to its value every time it is found on the command line 73 | func (f *FlagSet) Count(name string, usage string) *int { 74 | p := new(int) 75 | f.CountVarP(p, name, "", usage) 76 | return p 77 | } 78 | 79 | // CountP is like Count only takes a shorthand for the flag name. 80 | func (f *FlagSet) CountP(name, shorthand string, usage string) *int { 81 | p := new(int) 82 | f.CountVarP(p, name, shorthand, usage) 83 | return p 84 | } 85 | 86 | // Count defines a count flag with specified name, default value, and usage string. 87 | // The return value is the address of an int variable that stores the value of the flag. 88 | // A count flag will add 1 to its value evey time it is found on the command line 89 | func Count(name string, usage string) *int { 90 | return CommandLine.CountP(name, "", usage) 91 | } 92 | 93 | // CountP is like Count only takes a shorthand for the flag name. 94 | func CountP(name, shorthand string, usage string) *int { 95 | return CommandLine.CountP(name, shorthand, usage) 96 | } 97 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/duration.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import ( 4 | "time" 5 | ) 6 | 7 | // -- time.Duration Value 8 | type durationValue time.Duration 9 | 10 | func newDurationValue(val time.Duration, p *time.Duration) *durationValue { 11 | *p = val 12 | return (*durationValue)(p) 13 | } 14 | 15 | func (d *durationValue) Set(s string) error { 16 | v, err := time.ParseDuration(s) 17 | *d = durationValue(v) 18 | return err 19 | } 20 | 21 | func (d *durationValue) Type() string { 22 | return "duration" 23 | } 24 | 25 | func (d *durationValue) String() string { return (*time.Duration)(d).String() } 26 | 27 | func durationConv(sval string) (interface{}, error) { 28 | return time.ParseDuration(sval) 29 | } 30 | 31 | // GetDuration return the duration value of a flag with the given name 32 | func (f *FlagSet) GetDuration(name string) (time.Duration, error) { 33 | val, err := f.getFlagType(name, "duration", durationConv) 34 | if err != nil { 35 | return 0, err 36 | } 37 | return val.(time.Duration), nil 38 | } 39 | 40 | // DurationVar defines a time.Duration flag with specified name, default value, and usage string. 41 | // The argument p points to a time.Duration variable in which to store the value of the flag. 42 | func (f *FlagSet) DurationVar(p *time.Duration, name string, value time.Duration, usage string) { 43 | f.VarP(newDurationValue(value, p), name, "", usage) 44 | } 45 | 46 | // DurationVarP is like DurationVar, but accepts a shorthand letter that can be used after a single dash. 47 | func (f *FlagSet) DurationVarP(p *time.Duration, name, shorthand string, value time.Duration, usage string) { 48 | f.VarP(newDurationValue(value, p), name, shorthand, usage) 49 | } 50 | 51 | // DurationVar defines a time.Duration flag with specified name, default value, and usage string. 52 | // The argument p points to a time.Duration variable in which to store the value of the flag. 53 | func DurationVar(p *time.Duration, name string, value time.Duration, usage string) { 54 | CommandLine.VarP(newDurationValue(value, p), name, "", usage) 55 | } 56 | 57 | // DurationVarP is like DurationVar, but accepts a shorthand letter that can be used after a single dash. 58 | func DurationVarP(p *time.Duration, name, shorthand string, value time.Duration, usage string) { 59 | CommandLine.VarP(newDurationValue(value, p), name, shorthand, usage) 60 | } 61 | 62 | // Duration defines a time.Duration flag with specified name, default value, and usage string. 63 | // The return value is the address of a time.Duration variable that stores the value of the flag. 64 | func (f *FlagSet) Duration(name string, value time.Duration, usage string) *time.Duration { 65 | p := new(time.Duration) 66 | f.DurationVarP(p, name, "", value, usage) 67 | return p 68 | } 69 | 70 | // DurationP is like Duration, but accepts a shorthand letter that can be used after a single dash. 71 | func (f *FlagSet) DurationP(name, shorthand string, value time.Duration, usage string) *time.Duration { 72 | p := new(time.Duration) 73 | f.DurationVarP(p, name, shorthand, value, usage) 74 | return p 75 | } 76 | 77 | // Duration defines a time.Duration flag with specified name, default value, and usage string. 78 | // The return value is the address of a time.Duration variable that stores the value of the flag. 79 | func Duration(name string, value time.Duration, usage string) *time.Duration { 80 | return CommandLine.DurationP(name, "", value, usage) 81 | } 82 | 83 | // DurationP is like Duration, but accepts a shorthand letter that can be used after a single dash. 84 | func DurationP(name, shorthand string, value time.Duration, usage string) *time.Duration { 85 | return CommandLine.DurationP(name, shorthand, value, usage) 86 | } 87 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/duration_slice.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import ( 4 | "fmt" 5 | "strings" 6 | "time" 7 | ) 8 | 9 | // -- durationSlice Value 10 | type durationSliceValue struct { 11 | value *[]time.Duration 12 | changed bool 13 | } 14 | 15 | func newDurationSliceValue(val []time.Duration, p *[]time.Duration) *durationSliceValue { 16 | dsv := new(durationSliceValue) 17 | dsv.value = p 18 | *dsv.value = val 19 | return dsv 20 | } 21 | 22 | func (s *durationSliceValue) Set(val string) error { 23 | ss := strings.Split(val, ",") 24 | out := make([]time.Duration, len(ss)) 25 | for i, d := range ss { 26 | var err error 27 | out[i], err = time.ParseDuration(d) 28 | if err != nil { 29 | return err 30 | } 31 | 32 | } 33 | if !s.changed { 34 | *s.value = out 35 | } else { 36 | *s.value = append(*s.value, out...) 37 | } 38 | s.changed = true 39 | return nil 40 | } 41 | 42 | func (s *durationSliceValue) Type() string { 43 | return "durationSlice" 44 | } 45 | 46 | func (s *durationSliceValue) String() string { 47 | out := make([]string, len(*s.value)) 48 | for i, d := range *s.value { 49 | out[i] = fmt.Sprintf("%s", d) 50 | } 51 | return "[" + strings.Join(out, ",") + "]" 52 | } 53 | 54 | func (s *durationSliceValue) fromString(val string) (time.Duration, error) { 55 | return time.ParseDuration(val) 56 | } 57 | 58 | func (s *durationSliceValue) toString(val time.Duration) string { 59 | return fmt.Sprintf("%s", val) 60 | } 61 | 62 | func (s *durationSliceValue) Append(val string) error { 63 | i, err := s.fromString(val) 64 | if err != nil { 65 | return err 66 | } 67 | *s.value = append(*s.value, i) 68 | return nil 69 | } 70 | 71 | func (s *durationSliceValue) Replace(val []string) error { 72 | out := make([]time.Duration, len(val)) 73 | for i, d := range val { 74 | var err error 75 | out[i], err = s.fromString(d) 76 | if err != nil { 77 | return err 78 | } 79 | } 80 | *s.value = out 81 | return nil 82 | } 83 | 84 | func (s *durationSliceValue) GetSlice() []string { 85 | out := make([]string, len(*s.value)) 86 | for i, d := range *s.value { 87 | out[i] = s.toString(d) 88 | } 89 | return out 90 | } 91 | 92 | func durationSliceConv(val string) (interface{}, error) { 93 | val = strings.Trim(val, "[]") 94 | // Empty string would cause a slice with one (empty) entry 95 | if len(val) == 0 { 96 | return []time.Duration{}, nil 97 | } 98 | ss := strings.Split(val, ",") 99 | out := make([]time.Duration, len(ss)) 100 | for i, d := range ss { 101 | var err error 102 | out[i], err = time.ParseDuration(d) 103 | if err != nil { 104 | return nil, err 105 | } 106 | 107 | } 108 | return out, nil 109 | } 110 | 111 | // GetDurationSlice returns the []time.Duration value of a flag with the given name 112 | func (f *FlagSet) GetDurationSlice(name string) ([]time.Duration, error) { 113 | val, err := f.getFlagType(name, "durationSlice", durationSliceConv) 114 | if err != nil { 115 | return []time.Duration{}, err 116 | } 117 | return val.([]time.Duration), nil 118 | } 119 | 120 | // DurationSliceVar defines a durationSlice flag with specified name, default value, and usage string. 121 | // The argument p points to a []time.Duration variable in which to store the value of the flag. 122 | func (f *FlagSet) DurationSliceVar(p *[]time.Duration, name string, value []time.Duration, usage string) { 123 | f.VarP(newDurationSliceValue(value, p), name, "", usage) 124 | } 125 | 126 | // DurationSliceVarP is like DurationSliceVar, but accepts a shorthand letter that can be used after a single dash. 127 | func (f *FlagSet) DurationSliceVarP(p *[]time.Duration, name, shorthand string, value []time.Duration, usage string) { 128 | f.VarP(newDurationSliceValue(value, p), name, shorthand, usage) 129 | } 130 | 131 | // DurationSliceVar defines a duration[] flag with specified name, default value, and usage string. 132 | // The argument p points to a duration[] variable in which to store the value of the flag. 133 | func DurationSliceVar(p *[]time.Duration, name string, value []time.Duration, usage string) { 134 | CommandLine.VarP(newDurationSliceValue(value, p), name, "", usage) 135 | } 136 | 137 | // DurationSliceVarP is like DurationSliceVar, but accepts a shorthand letter that can be used after a single dash. 138 | func DurationSliceVarP(p *[]time.Duration, name, shorthand string, value []time.Duration, usage string) { 139 | CommandLine.VarP(newDurationSliceValue(value, p), name, shorthand, usage) 140 | } 141 | 142 | // DurationSlice defines a []time.Duration flag with specified name, default value, and usage string. 143 | // The return value is the address of a []time.Duration variable that stores the value of the flag. 144 | func (f *FlagSet) DurationSlice(name string, value []time.Duration, usage string) *[]time.Duration { 145 | p := []time.Duration{} 146 | f.DurationSliceVarP(&p, name, "", value, usage) 147 | return &p 148 | } 149 | 150 | // DurationSliceP is like DurationSlice, but accepts a shorthand letter that can be used after a single dash. 151 | func (f *FlagSet) DurationSliceP(name, shorthand string, value []time.Duration, usage string) *[]time.Duration { 152 | p := []time.Duration{} 153 | f.DurationSliceVarP(&p, name, shorthand, value, usage) 154 | return &p 155 | } 156 | 157 | // DurationSlice defines a []time.Duration flag with specified name, default value, and usage string. 158 | // The return value is the address of a []time.Duration variable that stores the value of the flag. 159 | func DurationSlice(name string, value []time.Duration, usage string) *[]time.Duration { 160 | return CommandLine.DurationSliceP(name, "", value, usage) 161 | } 162 | 163 | // DurationSliceP is like DurationSlice, but accepts a shorthand letter that can be used after a single dash. 164 | func DurationSliceP(name, shorthand string, value []time.Duration, usage string) *[]time.Duration { 165 | return CommandLine.DurationSliceP(name, shorthand, value, usage) 166 | } 167 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/float32.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- float32 Value 6 | type float32Value float32 7 | 8 | func newFloat32Value(val float32, p *float32) *float32Value { 9 | *p = val 10 | return (*float32Value)(p) 11 | } 12 | 13 | func (f *float32Value) Set(s string) error { 14 | v, err := strconv.ParseFloat(s, 32) 15 | *f = float32Value(v) 16 | return err 17 | } 18 | 19 | func (f *float32Value) Type() string { 20 | return "float32" 21 | } 22 | 23 | func (f *float32Value) String() string { return strconv.FormatFloat(float64(*f), 'g', -1, 32) } 24 | 25 | func float32Conv(sval string) (interface{}, error) { 26 | v, err := strconv.ParseFloat(sval, 32) 27 | if err != nil { 28 | return 0, err 29 | } 30 | return float32(v), nil 31 | } 32 | 33 | // GetFloat32 return the float32 value of a flag with the given name 34 | func (f *FlagSet) GetFloat32(name string) (float32, error) { 35 | val, err := f.getFlagType(name, "float32", float32Conv) 36 | if err != nil { 37 | return 0, err 38 | } 39 | return val.(float32), nil 40 | } 41 | 42 | // Float32Var defines a float32 flag with specified name, default value, and usage string. 43 | // The argument p points to a float32 variable in which to store the value of the flag. 44 | func (f *FlagSet) Float32Var(p *float32, name string, value float32, usage string) { 45 | f.VarP(newFloat32Value(value, p), name, "", usage) 46 | } 47 | 48 | // Float32VarP is like Float32Var, but accepts a shorthand letter that can be used after a single dash. 49 | func (f *FlagSet) Float32VarP(p *float32, name, shorthand string, value float32, usage string) { 50 | f.VarP(newFloat32Value(value, p), name, shorthand, usage) 51 | } 52 | 53 | // Float32Var defines a float32 flag with specified name, default value, and usage string. 54 | // The argument p points to a float32 variable in which to store the value of the flag. 55 | func Float32Var(p *float32, name string, value float32, usage string) { 56 | CommandLine.VarP(newFloat32Value(value, p), name, "", usage) 57 | } 58 | 59 | // Float32VarP is like Float32Var, but accepts a shorthand letter that can be used after a single dash. 60 | func Float32VarP(p *float32, name, shorthand string, value float32, usage string) { 61 | CommandLine.VarP(newFloat32Value(value, p), name, shorthand, usage) 62 | } 63 | 64 | // Float32 defines a float32 flag with specified name, default value, and usage string. 65 | // The return value is the address of a float32 variable that stores the value of the flag. 66 | func (f *FlagSet) Float32(name string, value float32, usage string) *float32 { 67 | p := new(float32) 68 | f.Float32VarP(p, name, "", value, usage) 69 | return p 70 | } 71 | 72 | // Float32P is like Float32, but accepts a shorthand letter that can be used after a single dash. 73 | func (f *FlagSet) Float32P(name, shorthand string, value float32, usage string) *float32 { 74 | p := new(float32) 75 | f.Float32VarP(p, name, shorthand, value, usage) 76 | return p 77 | } 78 | 79 | // Float32 defines a float32 flag with specified name, default value, and usage string. 80 | // The return value is the address of a float32 variable that stores the value of the flag. 81 | func Float32(name string, value float32, usage string) *float32 { 82 | return CommandLine.Float32P(name, "", value, usage) 83 | } 84 | 85 | // Float32P is like Float32, but accepts a shorthand letter that can be used after a single dash. 86 | func Float32P(name, shorthand string, value float32, usage string) *float32 { 87 | return CommandLine.Float32P(name, shorthand, value, usage) 88 | } 89 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/float32_slice.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import ( 4 | "fmt" 5 | "strconv" 6 | "strings" 7 | ) 8 | 9 | // -- float32Slice Value 10 | type float32SliceValue struct { 11 | value *[]float32 12 | changed bool 13 | } 14 | 15 | func newFloat32SliceValue(val []float32, p *[]float32) *float32SliceValue { 16 | isv := new(float32SliceValue) 17 | isv.value = p 18 | *isv.value = val 19 | return isv 20 | } 21 | 22 | func (s *float32SliceValue) Set(val string) error { 23 | ss := strings.Split(val, ",") 24 | out := make([]float32, len(ss)) 25 | for i, d := range ss { 26 | var err error 27 | var temp64 float64 28 | temp64, err = strconv.ParseFloat(d, 32) 29 | if err != nil { 30 | return err 31 | } 32 | out[i] = float32(temp64) 33 | 34 | } 35 | if !s.changed { 36 | *s.value = out 37 | } else { 38 | *s.value = append(*s.value, out...) 39 | } 40 | s.changed = true 41 | return nil 42 | } 43 | 44 | func (s *float32SliceValue) Type() string { 45 | return "float32Slice" 46 | } 47 | 48 | func (s *float32SliceValue) String() string { 49 | out := make([]string, len(*s.value)) 50 | for i, d := range *s.value { 51 | out[i] = fmt.Sprintf("%f", d) 52 | } 53 | return "[" + strings.Join(out, ",") + "]" 54 | } 55 | 56 | func (s *float32SliceValue) fromString(val string) (float32, error) { 57 | t64, err := strconv.ParseFloat(val, 32) 58 | if err != nil { 59 | return 0, err 60 | } 61 | return float32(t64), nil 62 | } 63 | 64 | func (s *float32SliceValue) toString(val float32) string { 65 | return fmt.Sprintf("%f", val) 66 | } 67 | 68 | func (s *float32SliceValue) Append(val string) error { 69 | i, err := s.fromString(val) 70 | if err != nil { 71 | return err 72 | } 73 | *s.value = append(*s.value, i) 74 | return nil 75 | } 76 | 77 | func (s *float32SliceValue) Replace(val []string) error { 78 | out := make([]float32, len(val)) 79 | for i, d := range val { 80 | var err error 81 | out[i], err = s.fromString(d) 82 | if err != nil { 83 | return err 84 | } 85 | } 86 | *s.value = out 87 | return nil 88 | } 89 | 90 | func (s *float32SliceValue) GetSlice() []string { 91 | out := make([]string, len(*s.value)) 92 | for i, d := range *s.value { 93 | out[i] = s.toString(d) 94 | } 95 | return out 96 | } 97 | 98 | func float32SliceConv(val string) (interface{}, error) { 99 | val = strings.Trim(val, "[]") 100 | // Empty string would cause a slice with one (empty) entry 101 | if len(val) == 0 { 102 | return []float32{}, nil 103 | } 104 | ss := strings.Split(val, ",") 105 | out := make([]float32, len(ss)) 106 | for i, d := range ss { 107 | var err error 108 | var temp64 float64 109 | temp64, err = strconv.ParseFloat(d, 32) 110 | if err != nil { 111 | return nil, err 112 | } 113 | out[i] = float32(temp64) 114 | 115 | } 116 | return out, nil 117 | } 118 | 119 | // GetFloat32Slice return the []float32 value of a flag with the given name 120 | func (f *FlagSet) GetFloat32Slice(name string) ([]float32, error) { 121 | val, err := f.getFlagType(name, "float32Slice", float32SliceConv) 122 | if err != nil { 123 | return []float32{}, err 124 | } 125 | return val.([]float32), nil 126 | } 127 | 128 | // Float32SliceVar defines a float32Slice flag with specified name, default value, and usage string. 129 | // The argument p points to a []float32 variable in which to store the value of the flag. 130 | func (f *FlagSet) Float32SliceVar(p *[]float32, name string, value []float32, usage string) { 131 | f.VarP(newFloat32SliceValue(value, p), name, "", usage) 132 | } 133 | 134 | // Float32SliceVarP is like Float32SliceVar, but accepts a shorthand letter that can be used after a single dash. 135 | func (f *FlagSet) Float32SliceVarP(p *[]float32, name, shorthand string, value []float32, usage string) { 136 | f.VarP(newFloat32SliceValue(value, p), name, shorthand, usage) 137 | } 138 | 139 | // Float32SliceVar defines a float32[] flag with specified name, default value, and usage string. 140 | // The argument p points to a float32[] variable in which to store the value of the flag. 141 | func Float32SliceVar(p *[]float32, name string, value []float32, usage string) { 142 | CommandLine.VarP(newFloat32SliceValue(value, p), name, "", usage) 143 | } 144 | 145 | // Float32SliceVarP is like Float32SliceVar, but accepts a shorthand letter that can be used after a single dash. 146 | func Float32SliceVarP(p *[]float32, name, shorthand string, value []float32, usage string) { 147 | CommandLine.VarP(newFloat32SliceValue(value, p), name, shorthand, usage) 148 | } 149 | 150 | // Float32Slice defines a []float32 flag with specified name, default value, and usage string. 151 | // The return value is the address of a []float32 variable that stores the value of the flag. 152 | func (f *FlagSet) Float32Slice(name string, value []float32, usage string) *[]float32 { 153 | p := []float32{} 154 | f.Float32SliceVarP(&p, name, "", value, usage) 155 | return &p 156 | } 157 | 158 | // Float32SliceP is like Float32Slice, but accepts a shorthand letter that can be used after a single dash. 159 | func (f *FlagSet) Float32SliceP(name, shorthand string, value []float32, usage string) *[]float32 { 160 | p := []float32{} 161 | f.Float32SliceVarP(&p, name, shorthand, value, usage) 162 | return &p 163 | } 164 | 165 | // Float32Slice defines a []float32 flag with specified name, default value, and usage string. 166 | // The return value is the address of a []float32 variable that stores the value of the flag. 167 | func Float32Slice(name string, value []float32, usage string) *[]float32 { 168 | return CommandLine.Float32SliceP(name, "", value, usage) 169 | } 170 | 171 | // Float32SliceP is like Float32Slice, but accepts a shorthand letter that can be used after a single dash. 172 | func Float32SliceP(name, shorthand string, value []float32, usage string) *[]float32 { 173 | return CommandLine.Float32SliceP(name, shorthand, value, usage) 174 | } 175 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/float64.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- float64 Value 6 | type float64Value float64 7 | 8 | func newFloat64Value(val float64, p *float64) *float64Value { 9 | *p = val 10 | return (*float64Value)(p) 11 | } 12 | 13 | func (f *float64Value) Set(s string) error { 14 | v, err := strconv.ParseFloat(s, 64) 15 | *f = float64Value(v) 16 | return err 17 | } 18 | 19 | func (f *float64Value) Type() string { 20 | return "float64" 21 | } 22 | 23 | func (f *float64Value) String() string { return strconv.FormatFloat(float64(*f), 'g', -1, 64) } 24 | 25 | func float64Conv(sval string) (interface{}, error) { 26 | return strconv.ParseFloat(sval, 64) 27 | } 28 | 29 | // GetFloat64 return the float64 value of a flag with the given name 30 | func (f *FlagSet) GetFloat64(name string) (float64, error) { 31 | val, err := f.getFlagType(name, "float64", float64Conv) 32 | if err != nil { 33 | return 0, err 34 | } 35 | return val.(float64), nil 36 | } 37 | 38 | // Float64Var defines a float64 flag with specified name, default value, and usage string. 39 | // The argument p points to a float64 variable in which to store the value of the flag. 40 | func (f *FlagSet) Float64Var(p *float64, name string, value float64, usage string) { 41 | f.VarP(newFloat64Value(value, p), name, "", usage) 42 | } 43 | 44 | // Float64VarP is like Float64Var, but accepts a shorthand letter that can be used after a single dash. 45 | func (f *FlagSet) Float64VarP(p *float64, name, shorthand string, value float64, usage string) { 46 | f.VarP(newFloat64Value(value, p), name, shorthand, usage) 47 | } 48 | 49 | // Float64Var defines a float64 flag with specified name, default value, and usage string. 50 | // The argument p points to a float64 variable in which to store the value of the flag. 51 | func Float64Var(p *float64, name string, value float64, usage string) { 52 | CommandLine.VarP(newFloat64Value(value, p), name, "", usage) 53 | } 54 | 55 | // Float64VarP is like Float64Var, but accepts a shorthand letter that can be used after a single dash. 56 | func Float64VarP(p *float64, name, shorthand string, value float64, usage string) { 57 | CommandLine.VarP(newFloat64Value(value, p), name, shorthand, usage) 58 | } 59 | 60 | // Float64 defines a float64 flag with specified name, default value, and usage string. 61 | // The return value is the address of a float64 variable that stores the value of the flag. 62 | func (f *FlagSet) Float64(name string, value float64, usage string) *float64 { 63 | p := new(float64) 64 | f.Float64VarP(p, name, "", value, usage) 65 | return p 66 | } 67 | 68 | // Float64P is like Float64, but accepts a shorthand letter that can be used after a single dash. 69 | func (f *FlagSet) Float64P(name, shorthand string, value float64, usage string) *float64 { 70 | p := new(float64) 71 | f.Float64VarP(p, name, shorthand, value, usage) 72 | return p 73 | } 74 | 75 | // Float64 defines a float64 flag with specified name, default value, and usage string. 76 | // The return value is the address of a float64 variable that stores the value of the flag. 77 | func Float64(name string, value float64, usage string) *float64 { 78 | return CommandLine.Float64P(name, "", value, usage) 79 | } 80 | 81 | // Float64P is like Float64, but accepts a shorthand letter that can be used after a single dash. 82 | func Float64P(name, shorthand string, value float64, usage string) *float64 { 83 | return CommandLine.Float64P(name, shorthand, value, usage) 84 | } 85 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/float64_slice.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import ( 4 | "fmt" 5 | "strconv" 6 | "strings" 7 | ) 8 | 9 | // -- float64Slice Value 10 | type float64SliceValue struct { 11 | value *[]float64 12 | changed bool 13 | } 14 | 15 | func newFloat64SliceValue(val []float64, p *[]float64) *float64SliceValue { 16 | isv := new(float64SliceValue) 17 | isv.value = p 18 | *isv.value = val 19 | return isv 20 | } 21 | 22 | func (s *float64SliceValue) Set(val string) error { 23 | ss := strings.Split(val, ",") 24 | out := make([]float64, len(ss)) 25 | for i, d := range ss { 26 | var err error 27 | out[i], err = strconv.ParseFloat(d, 64) 28 | if err != nil { 29 | return err 30 | } 31 | 32 | } 33 | if !s.changed { 34 | *s.value = out 35 | } else { 36 | *s.value = append(*s.value, out...) 37 | } 38 | s.changed = true 39 | return nil 40 | } 41 | 42 | func (s *float64SliceValue) Type() string { 43 | return "float64Slice" 44 | } 45 | 46 | func (s *float64SliceValue) String() string { 47 | out := make([]string, len(*s.value)) 48 | for i, d := range *s.value { 49 | out[i] = fmt.Sprintf("%f", d) 50 | } 51 | return "[" + strings.Join(out, ",") + "]" 52 | } 53 | 54 | func (s *float64SliceValue) fromString(val string) (float64, error) { 55 | return strconv.ParseFloat(val, 64) 56 | } 57 | 58 | func (s *float64SliceValue) toString(val float64) string { 59 | return fmt.Sprintf("%f", val) 60 | } 61 | 62 | func (s *float64SliceValue) Append(val string) error { 63 | i, err := s.fromString(val) 64 | if err != nil { 65 | return err 66 | } 67 | *s.value = append(*s.value, i) 68 | return nil 69 | } 70 | 71 | func (s *float64SliceValue) Replace(val []string) error { 72 | out := make([]float64, len(val)) 73 | for i, d := range val { 74 | var err error 75 | out[i], err = s.fromString(d) 76 | if err != nil { 77 | return err 78 | } 79 | } 80 | *s.value = out 81 | return nil 82 | } 83 | 84 | func (s *float64SliceValue) GetSlice() []string { 85 | out := make([]string, len(*s.value)) 86 | for i, d := range *s.value { 87 | out[i] = s.toString(d) 88 | } 89 | return out 90 | } 91 | 92 | func float64SliceConv(val string) (interface{}, error) { 93 | val = strings.Trim(val, "[]") 94 | // Empty string would cause a slice with one (empty) entry 95 | if len(val) == 0 { 96 | return []float64{}, nil 97 | } 98 | ss := strings.Split(val, ",") 99 | out := make([]float64, len(ss)) 100 | for i, d := range ss { 101 | var err error 102 | out[i], err = strconv.ParseFloat(d, 64) 103 | if err != nil { 104 | return nil, err 105 | } 106 | 107 | } 108 | return out, nil 109 | } 110 | 111 | // GetFloat64Slice return the []float64 value of a flag with the given name 112 | func (f *FlagSet) GetFloat64Slice(name string) ([]float64, error) { 113 | val, err := f.getFlagType(name, "float64Slice", float64SliceConv) 114 | if err != nil { 115 | return []float64{}, err 116 | } 117 | return val.([]float64), nil 118 | } 119 | 120 | // Float64SliceVar defines a float64Slice flag with specified name, default value, and usage string. 121 | // The argument p points to a []float64 variable in which to store the value of the flag. 122 | func (f *FlagSet) Float64SliceVar(p *[]float64, name string, value []float64, usage string) { 123 | f.VarP(newFloat64SliceValue(value, p), name, "", usage) 124 | } 125 | 126 | // Float64SliceVarP is like Float64SliceVar, but accepts a shorthand letter that can be used after a single dash. 127 | func (f *FlagSet) Float64SliceVarP(p *[]float64, name, shorthand string, value []float64, usage string) { 128 | f.VarP(newFloat64SliceValue(value, p), name, shorthand, usage) 129 | } 130 | 131 | // Float64SliceVar defines a float64[] flag with specified name, default value, and usage string. 132 | // The argument p points to a float64[] variable in which to store the value of the flag. 133 | func Float64SliceVar(p *[]float64, name string, value []float64, usage string) { 134 | CommandLine.VarP(newFloat64SliceValue(value, p), name, "", usage) 135 | } 136 | 137 | // Float64SliceVarP is like Float64SliceVar, but accepts a shorthand letter that can be used after a single dash. 138 | func Float64SliceVarP(p *[]float64, name, shorthand string, value []float64, usage string) { 139 | CommandLine.VarP(newFloat64SliceValue(value, p), name, shorthand, usage) 140 | } 141 | 142 | // Float64Slice defines a []float64 flag with specified name, default value, and usage string. 143 | // The return value is the address of a []float64 variable that stores the value of the flag. 144 | func (f *FlagSet) Float64Slice(name string, value []float64, usage string) *[]float64 { 145 | p := []float64{} 146 | f.Float64SliceVarP(&p, name, "", value, usage) 147 | return &p 148 | } 149 | 150 | // Float64SliceP is like Float64Slice, but accepts a shorthand letter that can be used after a single dash. 151 | func (f *FlagSet) Float64SliceP(name, shorthand string, value []float64, usage string) *[]float64 { 152 | p := []float64{} 153 | f.Float64SliceVarP(&p, name, shorthand, value, usage) 154 | return &p 155 | } 156 | 157 | // Float64Slice defines a []float64 flag with specified name, default value, and usage string. 158 | // The return value is the address of a []float64 variable that stores the value of the flag. 159 | func Float64Slice(name string, value []float64, usage string) *[]float64 { 160 | return CommandLine.Float64SliceP(name, "", value, usage) 161 | } 162 | 163 | // Float64SliceP is like Float64Slice, but accepts a shorthand letter that can be used after a single dash. 164 | func Float64SliceP(name, shorthand string, value []float64, usage string) *[]float64 { 165 | return CommandLine.Float64SliceP(name, shorthand, value, usage) 166 | } 167 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/spf13/pflag 2 | 3 | go 1.12 4 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/go.sum: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mauidude/go-readability/a9b3620098b71b186e94ff028b0551ba4eff0244/vendor/github.com/spf13/pflag/go.sum -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/golangflag.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 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. 4 | 5 | package pflag 6 | 7 | import ( 8 | goflag "flag" 9 | "reflect" 10 | "strings" 11 | ) 12 | 13 | // flagValueWrapper implements pflag.Value around a flag.Value. The main 14 | // difference here is the addition of the Type method that returns a string 15 | // name of the type. As this is generally unknown, we approximate that with 16 | // reflection. 17 | type flagValueWrapper struct { 18 | inner goflag.Value 19 | flagType string 20 | } 21 | 22 | // We are just copying the boolFlag interface out of goflag as that is what 23 | // they use to decide if a flag should get "true" when no arg is given. 24 | type goBoolFlag interface { 25 | goflag.Value 26 | IsBoolFlag() bool 27 | } 28 | 29 | func wrapFlagValue(v goflag.Value) Value { 30 | // If the flag.Value happens to also be a pflag.Value, just use it directly. 31 | if pv, ok := v.(Value); ok { 32 | return pv 33 | } 34 | 35 | pv := &flagValueWrapper{ 36 | inner: v, 37 | } 38 | 39 | t := reflect.TypeOf(v) 40 | if t.Kind() == reflect.Interface || t.Kind() == reflect.Ptr { 41 | t = t.Elem() 42 | } 43 | 44 | pv.flagType = strings.TrimSuffix(t.Name(), "Value") 45 | return pv 46 | } 47 | 48 | func (v *flagValueWrapper) String() string { 49 | return v.inner.String() 50 | } 51 | 52 | func (v *flagValueWrapper) Set(s string) error { 53 | return v.inner.Set(s) 54 | } 55 | 56 | func (v *flagValueWrapper) Type() string { 57 | return v.flagType 58 | } 59 | 60 | // PFlagFromGoFlag will return a *pflag.Flag given a *flag.Flag 61 | // If the *flag.Flag.Name was a single character (ex: `v`) it will be accessiblei 62 | // with both `-v` and `--v` in flags. If the golang flag was more than a single 63 | // character (ex: `verbose`) it will only be accessible via `--verbose` 64 | func PFlagFromGoFlag(goflag *goflag.Flag) *Flag { 65 | // Remember the default value as a string; it won't change. 66 | flag := &Flag{ 67 | Name: goflag.Name, 68 | Usage: goflag.Usage, 69 | Value: wrapFlagValue(goflag.Value), 70 | // Looks like golang flags don't set DefValue correctly :-( 71 | //DefValue: goflag.DefValue, 72 | DefValue: goflag.Value.String(), 73 | } 74 | // Ex: if the golang flag was -v, allow both -v and --v to work 75 | if len(flag.Name) == 1 { 76 | flag.Shorthand = flag.Name 77 | } 78 | if fv, ok := goflag.Value.(goBoolFlag); ok && fv.IsBoolFlag() { 79 | flag.NoOptDefVal = "true" 80 | } 81 | return flag 82 | } 83 | 84 | // AddGoFlag will add the given *flag.Flag to the pflag.FlagSet 85 | func (f *FlagSet) AddGoFlag(goflag *goflag.Flag) { 86 | if f.Lookup(goflag.Name) != nil { 87 | return 88 | } 89 | newflag := PFlagFromGoFlag(goflag) 90 | f.AddFlag(newflag) 91 | } 92 | 93 | // AddGoFlagSet will add the given *flag.FlagSet to the pflag.FlagSet 94 | func (f *FlagSet) AddGoFlagSet(newSet *goflag.FlagSet) { 95 | if newSet == nil { 96 | return 97 | } 98 | newSet.VisitAll(func(goflag *goflag.Flag) { 99 | f.AddGoFlag(goflag) 100 | }) 101 | if f.addedGoFlagSets == nil { 102 | f.addedGoFlagSets = make([]*goflag.FlagSet, 0) 103 | } 104 | f.addedGoFlagSets = append(f.addedGoFlagSets, newSet) 105 | } 106 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/int.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- int Value 6 | type intValue int 7 | 8 | func newIntValue(val int, p *int) *intValue { 9 | *p = val 10 | return (*intValue)(p) 11 | } 12 | 13 | func (i *intValue) Set(s string) error { 14 | v, err := strconv.ParseInt(s, 0, 64) 15 | *i = intValue(v) 16 | return err 17 | } 18 | 19 | func (i *intValue) Type() string { 20 | return "int" 21 | } 22 | 23 | func (i *intValue) String() string { return strconv.Itoa(int(*i)) } 24 | 25 | func intConv(sval string) (interface{}, error) { 26 | return strconv.Atoi(sval) 27 | } 28 | 29 | // GetInt return the int value of a flag with the given name 30 | func (f *FlagSet) GetInt(name string) (int, error) { 31 | val, err := f.getFlagType(name, "int", intConv) 32 | if err != nil { 33 | return 0, err 34 | } 35 | return val.(int), nil 36 | } 37 | 38 | // IntVar defines an int flag with specified name, default value, and usage string. 39 | // The argument p points to an int variable in which to store the value of the flag. 40 | func (f *FlagSet) IntVar(p *int, name string, value int, usage string) { 41 | f.VarP(newIntValue(value, p), name, "", usage) 42 | } 43 | 44 | // IntVarP is like IntVar, but accepts a shorthand letter that can be used after a single dash. 45 | func (f *FlagSet) IntVarP(p *int, name, shorthand string, value int, usage string) { 46 | f.VarP(newIntValue(value, p), name, shorthand, usage) 47 | } 48 | 49 | // IntVar defines an int flag with specified name, default value, and usage string. 50 | // The argument p points to an int variable in which to store the value of the flag. 51 | func IntVar(p *int, name string, value int, usage string) { 52 | CommandLine.VarP(newIntValue(value, p), name, "", usage) 53 | } 54 | 55 | // IntVarP is like IntVar, but accepts a shorthand letter that can be used after a single dash. 56 | func IntVarP(p *int, name, shorthand string, value int, usage string) { 57 | CommandLine.VarP(newIntValue(value, p), name, shorthand, usage) 58 | } 59 | 60 | // Int defines an int flag with specified name, default value, and usage string. 61 | // The return value is the address of an int variable that stores the value of the flag. 62 | func (f *FlagSet) Int(name string, value int, usage string) *int { 63 | p := new(int) 64 | f.IntVarP(p, name, "", value, usage) 65 | return p 66 | } 67 | 68 | // IntP is like Int, but accepts a shorthand letter that can be used after a single dash. 69 | func (f *FlagSet) IntP(name, shorthand string, value int, usage string) *int { 70 | p := new(int) 71 | f.IntVarP(p, name, shorthand, value, usage) 72 | return p 73 | } 74 | 75 | // Int defines an int flag with specified name, default value, and usage string. 76 | // The return value is the address of an int variable that stores the value of the flag. 77 | func Int(name string, value int, usage string) *int { 78 | return CommandLine.IntP(name, "", value, usage) 79 | } 80 | 81 | // IntP is like Int, but accepts a shorthand letter that can be used after a single dash. 82 | func IntP(name, shorthand string, value int, usage string) *int { 83 | return CommandLine.IntP(name, shorthand, value, usage) 84 | } 85 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/int16.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- int16 Value 6 | type int16Value int16 7 | 8 | func newInt16Value(val int16, p *int16) *int16Value { 9 | *p = val 10 | return (*int16Value)(p) 11 | } 12 | 13 | func (i *int16Value) Set(s string) error { 14 | v, err := strconv.ParseInt(s, 0, 16) 15 | *i = int16Value(v) 16 | return err 17 | } 18 | 19 | func (i *int16Value) Type() string { 20 | return "int16" 21 | } 22 | 23 | func (i *int16Value) String() string { return strconv.FormatInt(int64(*i), 10) } 24 | 25 | func int16Conv(sval string) (interface{}, error) { 26 | v, err := strconv.ParseInt(sval, 0, 16) 27 | if err != nil { 28 | return 0, err 29 | } 30 | return int16(v), nil 31 | } 32 | 33 | // GetInt16 returns the int16 value of a flag with the given name 34 | func (f *FlagSet) GetInt16(name string) (int16, error) { 35 | val, err := f.getFlagType(name, "int16", int16Conv) 36 | if err != nil { 37 | return 0, err 38 | } 39 | return val.(int16), nil 40 | } 41 | 42 | // Int16Var defines an int16 flag with specified name, default value, and usage string. 43 | // The argument p points to an int16 variable in which to store the value of the flag. 44 | func (f *FlagSet) Int16Var(p *int16, name string, value int16, usage string) { 45 | f.VarP(newInt16Value(value, p), name, "", usage) 46 | } 47 | 48 | // Int16VarP is like Int16Var, but accepts a shorthand letter that can be used after a single dash. 49 | func (f *FlagSet) Int16VarP(p *int16, name, shorthand string, value int16, usage string) { 50 | f.VarP(newInt16Value(value, p), name, shorthand, usage) 51 | } 52 | 53 | // Int16Var defines an int16 flag with specified name, default value, and usage string. 54 | // The argument p points to an int16 variable in which to store the value of the flag. 55 | func Int16Var(p *int16, name string, value int16, usage string) { 56 | CommandLine.VarP(newInt16Value(value, p), name, "", usage) 57 | } 58 | 59 | // Int16VarP is like Int16Var, but accepts a shorthand letter that can be used after a single dash. 60 | func Int16VarP(p *int16, name, shorthand string, value int16, usage string) { 61 | CommandLine.VarP(newInt16Value(value, p), name, shorthand, usage) 62 | } 63 | 64 | // Int16 defines an int16 flag with specified name, default value, and usage string. 65 | // The return value is the address of an int16 variable that stores the value of the flag. 66 | func (f *FlagSet) Int16(name string, value int16, usage string) *int16 { 67 | p := new(int16) 68 | f.Int16VarP(p, name, "", value, usage) 69 | return p 70 | } 71 | 72 | // Int16P is like Int16, but accepts a shorthand letter that can be used after a single dash. 73 | func (f *FlagSet) Int16P(name, shorthand string, value int16, usage string) *int16 { 74 | p := new(int16) 75 | f.Int16VarP(p, name, shorthand, value, usage) 76 | return p 77 | } 78 | 79 | // Int16 defines an int16 flag with specified name, default value, and usage string. 80 | // The return value is the address of an int16 variable that stores the value of the flag. 81 | func Int16(name string, value int16, usage string) *int16 { 82 | return CommandLine.Int16P(name, "", value, usage) 83 | } 84 | 85 | // Int16P is like Int16, but accepts a shorthand letter that can be used after a single dash. 86 | func Int16P(name, shorthand string, value int16, usage string) *int16 { 87 | return CommandLine.Int16P(name, shorthand, value, usage) 88 | } 89 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/int32.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- int32 Value 6 | type int32Value int32 7 | 8 | func newInt32Value(val int32, p *int32) *int32Value { 9 | *p = val 10 | return (*int32Value)(p) 11 | } 12 | 13 | func (i *int32Value) Set(s string) error { 14 | v, err := strconv.ParseInt(s, 0, 32) 15 | *i = int32Value(v) 16 | return err 17 | } 18 | 19 | func (i *int32Value) Type() string { 20 | return "int32" 21 | } 22 | 23 | func (i *int32Value) String() string { return strconv.FormatInt(int64(*i), 10) } 24 | 25 | func int32Conv(sval string) (interface{}, error) { 26 | v, err := strconv.ParseInt(sval, 0, 32) 27 | if err != nil { 28 | return 0, err 29 | } 30 | return int32(v), nil 31 | } 32 | 33 | // GetInt32 return the int32 value of a flag with the given name 34 | func (f *FlagSet) GetInt32(name string) (int32, error) { 35 | val, err := f.getFlagType(name, "int32", int32Conv) 36 | if err != nil { 37 | return 0, err 38 | } 39 | return val.(int32), nil 40 | } 41 | 42 | // Int32Var defines an int32 flag with specified name, default value, and usage string. 43 | // The argument p points to an int32 variable in which to store the value of the flag. 44 | func (f *FlagSet) Int32Var(p *int32, name string, value int32, usage string) { 45 | f.VarP(newInt32Value(value, p), name, "", usage) 46 | } 47 | 48 | // Int32VarP is like Int32Var, but accepts a shorthand letter that can be used after a single dash. 49 | func (f *FlagSet) Int32VarP(p *int32, name, shorthand string, value int32, usage string) { 50 | f.VarP(newInt32Value(value, p), name, shorthand, usage) 51 | } 52 | 53 | // Int32Var defines an int32 flag with specified name, default value, and usage string. 54 | // The argument p points to an int32 variable in which to store the value of the flag. 55 | func Int32Var(p *int32, name string, value int32, usage string) { 56 | CommandLine.VarP(newInt32Value(value, p), name, "", usage) 57 | } 58 | 59 | // Int32VarP is like Int32Var, but accepts a shorthand letter that can be used after a single dash. 60 | func Int32VarP(p *int32, name, shorthand string, value int32, usage string) { 61 | CommandLine.VarP(newInt32Value(value, p), name, shorthand, usage) 62 | } 63 | 64 | // Int32 defines an int32 flag with specified name, default value, and usage string. 65 | // The return value is the address of an int32 variable that stores the value of the flag. 66 | func (f *FlagSet) Int32(name string, value int32, usage string) *int32 { 67 | p := new(int32) 68 | f.Int32VarP(p, name, "", value, usage) 69 | return p 70 | } 71 | 72 | // Int32P is like Int32, but accepts a shorthand letter that can be used after a single dash. 73 | func (f *FlagSet) Int32P(name, shorthand string, value int32, usage string) *int32 { 74 | p := new(int32) 75 | f.Int32VarP(p, name, shorthand, value, usage) 76 | return p 77 | } 78 | 79 | // Int32 defines an int32 flag with specified name, default value, and usage string. 80 | // The return value is the address of an int32 variable that stores the value of the flag. 81 | func Int32(name string, value int32, usage string) *int32 { 82 | return CommandLine.Int32P(name, "", value, usage) 83 | } 84 | 85 | // Int32P is like Int32, but accepts a shorthand letter that can be used after a single dash. 86 | func Int32P(name, shorthand string, value int32, usage string) *int32 { 87 | return CommandLine.Int32P(name, shorthand, value, usage) 88 | } 89 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/int32_slice.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import ( 4 | "fmt" 5 | "strconv" 6 | "strings" 7 | ) 8 | 9 | // -- int32Slice Value 10 | type int32SliceValue struct { 11 | value *[]int32 12 | changed bool 13 | } 14 | 15 | func newInt32SliceValue(val []int32, p *[]int32) *int32SliceValue { 16 | isv := new(int32SliceValue) 17 | isv.value = p 18 | *isv.value = val 19 | return isv 20 | } 21 | 22 | func (s *int32SliceValue) Set(val string) error { 23 | ss := strings.Split(val, ",") 24 | out := make([]int32, len(ss)) 25 | for i, d := range ss { 26 | var err error 27 | var temp64 int64 28 | temp64, err = strconv.ParseInt(d, 0, 32) 29 | if err != nil { 30 | return err 31 | } 32 | out[i] = int32(temp64) 33 | 34 | } 35 | if !s.changed { 36 | *s.value = out 37 | } else { 38 | *s.value = append(*s.value, out...) 39 | } 40 | s.changed = true 41 | return nil 42 | } 43 | 44 | func (s *int32SliceValue) Type() string { 45 | return "int32Slice" 46 | } 47 | 48 | func (s *int32SliceValue) String() string { 49 | out := make([]string, len(*s.value)) 50 | for i, d := range *s.value { 51 | out[i] = fmt.Sprintf("%d", d) 52 | } 53 | return "[" + strings.Join(out, ",") + "]" 54 | } 55 | 56 | func (s *int32SliceValue) fromString(val string) (int32, error) { 57 | t64, err := strconv.ParseInt(val, 0, 32) 58 | if err != nil { 59 | return 0, err 60 | } 61 | return int32(t64), nil 62 | } 63 | 64 | func (s *int32SliceValue) toString(val int32) string { 65 | return fmt.Sprintf("%d", val) 66 | } 67 | 68 | func (s *int32SliceValue) Append(val string) error { 69 | i, err := s.fromString(val) 70 | if err != nil { 71 | return err 72 | } 73 | *s.value = append(*s.value, i) 74 | return nil 75 | } 76 | 77 | func (s *int32SliceValue) Replace(val []string) error { 78 | out := make([]int32, len(val)) 79 | for i, d := range val { 80 | var err error 81 | out[i], err = s.fromString(d) 82 | if err != nil { 83 | return err 84 | } 85 | } 86 | *s.value = out 87 | return nil 88 | } 89 | 90 | func (s *int32SliceValue) GetSlice() []string { 91 | out := make([]string, len(*s.value)) 92 | for i, d := range *s.value { 93 | out[i] = s.toString(d) 94 | } 95 | return out 96 | } 97 | 98 | func int32SliceConv(val string) (interface{}, error) { 99 | val = strings.Trim(val, "[]") 100 | // Empty string would cause a slice with one (empty) entry 101 | if len(val) == 0 { 102 | return []int32{}, nil 103 | } 104 | ss := strings.Split(val, ",") 105 | out := make([]int32, len(ss)) 106 | for i, d := range ss { 107 | var err error 108 | var temp64 int64 109 | temp64, err = strconv.ParseInt(d, 0, 32) 110 | if err != nil { 111 | return nil, err 112 | } 113 | out[i] = int32(temp64) 114 | 115 | } 116 | return out, nil 117 | } 118 | 119 | // GetInt32Slice return the []int32 value of a flag with the given name 120 | func (f *FlagSet) GetInt32Slice(name string) ([]int32, error) { 121 | val, err := f.getFlagType(name, "int32Slice", int32SliceConv) 122 | if err != nil { 123 | return []int32{}, err 124 | } 125 | return val.([]int32), nil 126 | } 127 | 128 | // Int32SliceVar defines a int32Slice flag with specified name, default value, and usage string. 129 | // The argument p points to a []int32 variable in which to store the value of the flag. 130 | func (f *FlagSet) Int32SliceVar(p *[]int32, name string, value []int32, usage string) { 131 | f.VarP(newInt32SliceValue(value, p), name, "", usage) 132 | } 133 | 134 | // Int32SliceVarP is like Int32SliceVar, but accepts a shorthand letter that can be used after a single dash. 135 | func (f *FlagSet) Int32SliceVarP(p *[]int32, name, shorthand string, value []int32, usage string) { 136 | f.VarP(newInt32SliceValue(value, p), name, shorthand, usage) 137 | } 138 | 139 | // Int32SliceVar defines a int32[] flag with specified name, default value, and usage string. 140 | // The argument p points to a int32[] variable in which to store the value of the flag. 141 | func Int32SliceVar(p *[]int32, name string, value []int32, usage string) { 142 | CommandLine.VarP(newInt32SliceValue(value, p), name, "", usage) 143 | } 144 | 145 | // Int32SliceVarP is like Int32SliceVar, but accepts a shorthand letter that can be used after a single dash. 146 | func Int32SliceVarP(p *[]int32, name, shorthand string, value []int32, usage string) { 147 | CommandLine.VarP(newInt32SliceValue(value, p), name, shorthand, usage) 148 | } 149 | 150 | // Int32Slice defines a []int32 flag with specified name, default value, and usage string. 151 | // The return value is the address of a []int32 variable that stores the value of the flag. 152 | func (f *FlagSet) Int32Slice(name string, value []int32, usage string) *[]int32 { 153 | p := []int32{} 154 | f.Int32SliceVarP(&p, name, "", value, usage) 155 | return &p 156 | } 157 | 158 | // Int32SliceP is like Int32Slice, but accepts a shorthand letter that can be used after a single dash. 159 | func (f *FlagSet) Int32SliceP(name, shorthand string, value []int32, usage string) *[]int32 { 160 | p := []int32{} 161 | f.Int32SliceVarP(&p, name, shorthand, value, usage) 162 | return &p 163 | } 164 | 165 | // Int32Slice defines a []int32 flag with specified name, default value, and usage string. 166 | // The return value is the address of a []int32 variable that stores the value of the flag. 167 | func Int32Slice(name string, value []int32, usage string) *[]int32 { 168 | return CommandLine.Int32SliceP(name, "", value, usage) 169 | } 170 | 171 | // Int32SliceP is like Int32Slice, but accepts a shorthand letter that can be used after a single dash. 172 | func Int32SliceP(name, shorthand string, value []int32, usage string) *[]int32 { 173 | return CommandLine.Int32SliceP(name, shorthand, value, usage) 174 | } 175 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/int64.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- int64 Value 6 | type int64Value int64 7 | 8 | func newInt64Value(val int64, p *int64) *int64Value { 9 | *p = val 10 | return (*int64Value)(p) 11 | } 12 | 13 | func (i *int64Value) Set(s string) error { 14 | v, err := strconv.ParseInt(s, 0, 64) 15 | *i = int64Value(v) 16 | return err 17 | } 18 | 19 | func (i *int64Value) Type() string { 20 | return "int64" 21 | } 22 | 23 | func (i *int64Value) String() string { return strconv.FormatInt(int64(*i), 10) } 24 | 25 | func int64Conv(sval string) (interface{}, error) { 26 | return strconv.ParseInt(sval, 0, 64) 27 | } 28 | 29 | // GetInt64 return the int64 value of a flag with the given name 30 | func (f *FlagSet) GetInt64(name string) (int64, error) { 31 | val, err := f.getFlagType(name, "int64", int64Conv) 32 | if err != nil { 33 | return 0, err 34 | } 35 | return val.(int64), nil 36 | } 37 | 38 | // Int64Var defines an int64 flag with specified name, default value, and usage string. 39 | // The argument p points to an int64 variable in which to store the value of the flag. 40 | func (f *FlagSet) Int64Var(p *int64, name string, value int64, usage string) { 41 | f.VarP(newInt64Value(value, p), name, "", usage) 42 | } 43 | 44 | // Int64VarP is like Int64Var, but accepts a shorthand letter that can be used after a single dash. 45 | func (f *FlagSet) Int64VarP(p *int64, name, shorthand string, value int64, usage string) { 46 | f.VarP(newInt64Value(value, p), name, shorthand, usage) 47 | } 48 | 49 | // Int64Var defines an int64 flag with specified name, default value, and usage string. 50 | // The argument p points to an int64 variable in which to store the value of the flag. 51 | func Int64Var(p *int64, name string, value int64, usage string) { 52 | CommandLine.VarP(newInt64Value(value, p), name, "", usage) 53 | } 54 | 55 | // Int64VarP is like Int64Var, but accepts a shorthand letter that can be used after a single dash. 56 | func Int64VarP(p *int64, name, shorthand string, value int64, usage string) { 57 | CommandLine.VarP(newInt64Value(value, p), name, shorthand, usage) 58 | } 59 | 60 | // Int64 defines an int64 flag with specified name, default value, and usage string. 61 | // The return value is the address of an int64 variable that stores the value of the flag. 62 | func (f *FlagSet) Int64(name string, value int64, usage string) *int64 { 63 | p := new(int64) 64 | f.Int64VarP(p, name, "", value, usage) 65 | return p 66 | } 67 | 68 | // Int64P is like Int64, but accepts a shorthand letter that can be used after a single dash. 69 | func (f *FlagSet) Int64P(name, shorthand string, value int64, usage string) *int64 { 70 | p := new(int64) 71 | f.Int64VarP(p, name, shorthand, value, usage) 72 | return p 73 | } 74 | 75 | // Int64 defines an int64 flag with specified name, default value, and usage string. 76 | // The return value is the address of an int64 variable that stores the value of the flag. 77 | func Int64(name string, value int64, usage string) *int64 { 78 | return CommandLine.Int64P(name, "", value, usage) 79 | } 80 | 81 | // Int64P is like Int64, but accepts a shorthand letter that can be used after a single dash. 82 | func Int64P(name, shorthand string, value int64, usage string) *int64 { 83 | return CommandLine.Int64P(name, shorthand, value, usage) 84 | } 85 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/int64_slice.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import ( 4 | "fmt" 5 | "strconv" 6 | "strings" 7 | ) 8 | 9 | // -- int64Slice Value 10 | type int64SliceValue struct { 11 | value *[]int64 12 | changed bool 13 | } 14 | 15 | func newInt64SliceValue(val []int64, p *[]int64) *int64SliceValue { 16 | isv := new(int64SliceValue) 17 | isv.value = p 18 | *isv.value = val 19 | return isv 20 | } 21 | 22 | func (s *int64SliceValue) Set(val string) error { 23 | ss := strings.Split(val, ",") 24 | out := make([]int64, len(ss)) 25 | for i, d := range ss { 26 | var err error 27 | out[i], err = strconv.ParseInt(d, 0, 64) 28 | if err != nil { 29 | return err 30 | } 31 | 32 | } 33 | if !s.changed { 34 | *s.value = out 35 | } else { 36 | *s.value = append(*s.value, out...) 37 | } 38 | s.changed = true 39 | return nil 40 | } 41 | 42 | func (s *int64SliceValue) Type() string { 43 | return "int64Slice" 44 | } 45 | 46 | func (s *int64SliceValue) String() string { 47 | out := make([]string, len(*s.value)) 48 | for i, d := range *s.value { 49 | out[i] = fmt.Sprintf("%d", d) 50 | } 51 | return "[" + strings.Join(out, ",") + "]" 52 | } 53 | 54 | func (s *int64SliceValue) fromString(val string) (int64, error) { 55 | return strconv.ParseInt(val, 0, 64) 56 | } 57 | 58 | func (s *int64SliceValue) toString(val int64) string { 59 | return fmt.Sprintf("%d", val) 60 | } 61 | 62 | func (s *int64SliceValue) Append(val string) error { 63 | i, err := s.fromString(val) 64 | if err != nil { 65 | return err 66 | } 67 | *s.value = append(*s.value, i) 68 | return nil 69 | } 70 | 71 | func (s *int64SliceValue) Replace(val []string) error { 72 | out := make([]int64, len(val)) 73 | for i, d := range val { 74 | var err error 75 | out[i], err = s.fromString(d) 76 | if err != nil { 77 | return err 78 | } 79 | } 80 | *s.value = out 81 | return nil 82 | } 83 | 84 | func (s *int64SliceValue) GetSlice() []string { 85 | out := make([]string, len(*s.value)) 86 | for i, d := range *s.value { 87 | out[i] = s.toString(d) 88 | } 89 | return out 90 | } 91 | 92 | func int64SliceConv(val string) (interface{}, error) { 93 | val = strings.Trim(val, "[]") 94 | // Empty string would cause a slice with one (empty) entry 95 | if len(val) == 0 { 96 | return []int64{}, nil 97 | } 98 | ss := strings.Split(val, ",") 99 | out := make([]int64, len(ss)) 100 | for i, d := range ss { 101 | var err error 102 | out[i], err = strconv.ParseInt(d, 0, 64) 103 | if err != nil { 104 | return nil, err 105 | } 106 | 107 | } 108 | return out, nil 109 | } 110 | 111 | // GetInt64Slice return the []int64 value of a flag with the given name 112 | func (f *FlagSet) GetInt64Slice(name string) ([]int64, error) { 113 | val, err := f.getFlagType(name, "int64Slice", int64SliceConv) 114 | if err != nil { 115 | return []int64{}, err 116 | } 117 | return val.([]int64), nil 118 | } 119 | 120 | // Int64SliceVar defines a int64Slice flag with specified name, default value, and usage string. 121 | // The argument p points to a []int64 variable in which to store the value of the flag. 122 | func (f *FlagSet) Int64SliceVar(p *[]int64, name string, value []int64, usage string) { 123 | f.VarP(newInt64SliceValue(value, p), name, "", usage) 124 | } 125 | 126 | // Int64SliceVarP is like Int64SliceVar, but accepts a shorthand letter that can be used after a single dash. 127 | func (f *FlagSet) Int64SliceVarP(p *[]int64, name, shorthand string, value []int64, usage string) { 128 | f.VarP(newInt64SliceValue(value, p), name, shorthand, usage) 129 | } 130 | 131 | // Int64SliceVar defines a int64[] flag with specified name, default value, and usage string. 132 | // The argument p points to a int64[] variable in which to store the value of the flag. 133 | func Int64SliceVar(p *[]int64, name string, value []int64, usage string) { 134 | CommandLine.VarP(newInt64SliceValue(value, p), name, "", usage) 135 | } 136 | 137 | // Int64SliceVarP is like Int64SliceVar, but accepts a shorthand letter that can be used after a single dash. 138 | func Int64SliceVarP(p *[]int64, name, shorthand string, value []int64, usage string) { 139 | CommandLine.VarP(newInt64SliceValue(value, p), name, shorthand, usage) 140 | } 141 | 142 | // Int64Slice defines a []int64 flag with specified name, default value, and usage string. 143 | // The return value is the address of a []int64 variable that stores the value of the flag. 144 | func (f *FlagSet) Int64Slice(name string, value []int64, usage string) *[]int64 { 145 | p := []int64{} 146 | f.Int64SliceVarP(&p, name, "", value, usage) 147 | return &p 148 | } 149 | 150 | // Int64SliceP is like Int64Slice, but accepts a shorthand letter that can be used after a single dash. 151 | func (f *FlagSet) Int64SliceP(name, shorthand string, value []int64, usage string) *[]int64 { 152 | p := []int64{} 153 | f.Int64SliceVarP(&p, name, shorthand, value, usage) 154 | return &p 155 | } 156 | 157 | // Int64Slice defines a []int64 flag with specified name, default value, and usage string. 158 | // The return value is the address of a []int64 variable that stores the value of the flag. 159 | func Int64Slice(name string, value []int64, usage string) *[]int64 { 160 | return CommandLine.Int64SliceP(name, "", value, usage) 161 | } 162 | 163 | // Int64SliceP is like Int64Slice, but accepts a shorthand letter that can be used after a single dash. 164 | func Int64SliceP(name, shorthand string, value []int64, usage string) *[]int64 { 165 | return CommandLine.Int64SliceP(name, shorthand, value, usage) 166 | } 167 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/int8.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- int8 Value 6 | type int8Value int8 7 | 8 | func newInt8Value(val int8, p *int8) *int8Value { 9 | *p = val 10 | return (*int8Value)(p) 11 | } 12 | 13 | func (i *int8Value) Set(s string) error { 14 | v, err := strconv.ParseInt(s, 0, 8) 15 | *i = int8Value(v) 16 | return err 17 | } 18 | 19 | func (i *int8Value) Type() string { 20 | return "int8" 21 | } 22 | 23 | func (i *int8Value) String() string { return strconv.FormatInt(int64(*i), 10) } 24 | 25 | func int8Conv(sval string) (interface{}, error) { 26 | v, err := strconv.ParseInt(sval, 0, 8) 27 | if err != nil { 28 | return 0, err 29 | } 30 | return int8(v), nil 31 | } 32 | 33 | // GetInt8 return the int8 value of a flag with the given name 34 | func (f *FlagSet) GetInt8(name string) (int8, error) { 35 | val, err := f.getFlagType(name, "int8", int8Conv) 36 | if err != nil { 37 | return 0, err 38 | } 39 | return val.(int8), nil 40 | } 41 | 42 | // Int8Var defines an int8 flag with specified name, default value, and usage string. 43 | // The argument p points to an int8 variable in which to store the value of the flag. 44 | func (f *FlagSet) Int8Var(p *int8, name string, value int8, usage string) { 45 | f.VarP(newInt8Value(value, p), name, "", usage) 46 | } 47 | 48 | // Int8VarP is like Int8Var, but accepts a shorthand letter that can be used after a single dash. 49 | func (f *FlagSet) Int8VarP(p *int8, name, shorthand string, value int8, usage string) { 50 | f.VarP(newInt8Value(value, p), name, shorthand, usage) 51 | } 52 | 53 | // Int8Var defines an int8 flag with specified name, default value, and usage string. 54 | // The argument p points to an int8 variable in which to store the value of the flag. 55 | func Int8Var(p *int8, name string, value int8, usage string) { 56 | CommandLine.VarP(newInt8Value(value, p), name, "", usage) 57 | } 58 | 59 | // Int8VarP is like Int8Var, but accepts a shorthand letter that can be used after a single dash. 60 | func Int8VarP(p *int8, name, shorthand string, value int8, usage string) { 61 | CommandLine.VarP(newInt8Value(value, p), name, shorthand, usage) 62 | } 63 | 64 | // Int8 defines an int8 flag with specified name, default value, and usage string. 65 | // The return value is the address of an int8 variable that stores the value of the flag. 66 | func (f *FlagSet) Int8(name string, value int8, usage string) *int8 { 67 | p := new(int8) 68 | f.Int8VarP(p, name, "", value, usage) 69 | return p 70 | } 71 | 72 | // Int8P is like Int8, but accepts a shorthand letter that can be used after a single dash. 73 | func (f *FlagSet) Int8P(name, shorthand string, value int8, usage string) *int8 { 74 | p := new(int8) 75 | f.Int8VarP(p, name, shorthand, value, usage) 76 | return p 77 | } 78 | 79 | // Int8 defines an int8 flag with specified name, default value, and usage string. 80 | // The return value is the address of an int8 variable that stores the value of the flag. 81 | func Int8(name string, value int8, usage string) *int8 { 82 | return CommandLine.Int8P(name, "", value, usage) 83 | } 84 | 85 | // Int8P is like Int8, but accepts a shorthand letter that can be used after a single dash. 86 | func Int8P(name, shorthand string, value int8, usage string) *int8 { 87 | return CommandLine.Int8P(name, shorthand, value, usage) 88 | } 89 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/int_slice.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import ( 4 | "fmt" 5 | "strconv" 6 | "strings" 7 | ) 8 | 9 | // -- intSlice Value 10 | type intSliceValue struct { 11 | value *[]int 12 | changed bool 13 | } 14 | 15 | func newIntSliceValue(val []int, p *[]int) *intSliceValue { 16 | isv := new(intSliceValue) 17 | isv.value = p 18 | *isv.value = val 19 | return isv 20 | } 21 | 22 | func (s *intSliceValue) Set(val string) error { 23 | ss := strings.Split(val, ",") 24 | out := make([]int, len(ss)) 25 | for i, d := range ss { 26 | var err error 27 | out[i], err = strconv.Atoi(d) 28 | if err != nil { 29 | return err 30 | } 31 | 32 | } 33 | if !s.changed { 34 | *s.value = out 35 | } else { 36 | *s.value = append(*s.value, out...) 37 | } 38 | s.changed = true 39 | return nil 40 | } 41 | 42 | func (s *intSliceValue) Type() string { 43 | return "intSlice" 44 | } 45 | 46 | func (s *intSliceValue) String() string { 47 | out := make([]string, len(*s.value)) 48 | for i, d := range *s.value { 49 | out[i] = fmt.Sprintf("%d", d) 50 | } 51 | return "[" + strings.Join(out, ",") + "]" 52 | } 53 | 54 | func (s *intSliceValue) Append(val string) error { 55 | i, err := strconv.Atoi(val) 56 | if err != nil { 57 | return err 58 | } 59 | *s.value = append(*s.value, i) 60 | return nil 61 | } 62 | 63 | func (s *intSliceValue) Replace(val []string) error { 64 | out := make([]int, len(val)) 65 | for i, d := range val { 66 | var err error 67 | out[i], err = strconv.Atoi(d) 68 | if err != nil { 69 | return err 70 | } 71 | } 72 | *s.value = out 73 | return nil 74 | } 75 | 76 | func (s *intSliceValue) GetSlice() []string { 77 | out := make([]string, len(*s.value)) 78 | for i, d := range *s.value { 79 | out[i] = strconv.Itoa(d) 80 | } 81 | return out 82 | } 83 | 84 | func intSliceConv(val string) (interface{}, error) { 85 | val = strings.Trim(val, "[]") 86 | // Empty string would cause a slice with one (empty) entry 87 | if len(val) == 0 { 88 | return []int{}, nil 89 | } 90 | ss := strings.Split(val, ",") 91 | out := make([]int, len(ss)) 92 | for i, d := range ss { 93 | var err error 94 | out[i], err = strconv.Atoi(d) 95 | if err != nil { 96 | return nil, err 97 | } 98 | 99 | } 100 | return out, nil 101 | } 102 | 103 | // GetIntSlice return the []int value of a flag with the given name 104 | func (f *FlagSet) GetIntSlice(name string) ([]int, error) { 105 | val, err := f.getFlagType(name, "intSlice", intSliceConv) 106 | if err != nil { 107 | return []int{}, err 108 | } 109 | return val.([]int), nil 110 | } 111 | 112 | // IntSliceVar defines a intSlice flag with specified name, default value, and usage string. 113 | // The argument p points to a []int variable in which to store the value of the flag. 114 | func (f *FlagSet) IntSliceVar(p *[]int, name string, value []int, usage string) { 115 | f.VarP(newIntSliceValue(value, p), name, "", usage) 116 | } 117 | 118 | // IntSliceVarP is like IntSliceVar, but accepts a shorthand letter that can be used after a single dash. 119 | func (f *FlagSet) IntSliceVarP(p *[]int, name, shorthand string, value []int, usage string) { 120 | f.VarP(newIntSliceValue(value, p), name, shorthand, usage) 121 | } 122 | 123 | // IntSliceVar defines a int[] flag with specified name, default value, and usage string. 124 | // The argument p points to a int[] variable in which to store the value of the flag. 125 | func IntSliceVar(p *[]int, name string, value []int, usage string) { 126 | CommandLine.VarP(newIntSliceValue(value, p), name, "", usage) 127 | } 128 | 129 | // IntSliceVarP is like IntSliceVar, but accepts a shorthand letter that can be used after a single dash. 130 | func IntSliceVarP(p *[]int, name, shorthand string, value []int, usage string) { 131 | CommandLine.VarP(newIntSliceValue(value, p), name, shorthand, usage) 132 | } 133 | 134 | // IntSlice defines a []int flag with specified name, default value, and usage string. 135 | // The return value is the address of a []int variable that stores the value of the flag. 136 | func (f *FlagSet) IntSlice(name string, value []int, usage string) *[]int { 137 | p := []int{} 138 | f.IntSliceVarP(&p, name, "", value, usage) 139 | return &p 140 | } 141 | 142 | // IntSliceP is like IntSlice, but accepts a shorthand letter that can be used after a single dash. 143 | func (f *FlagSet) IntSliceP(name, shorthand string, value []int, usage string) *[]int { 144 | p := []int{} 145 | f.IntSliceVarP(&p, name, shorthand, value, usage) 146 | return &p 147 | } 148 | 149 | // IntSlice defines a []int flag with specified name, default value, and usage string. 150 | // The return value is the address of a []int variable that stores the value of the flag. 151 | func IntSlice(name string, value []int, usage string) *[]int { 152 | return CommandLine.IntSliceP(name, "", value, usage) 153 | } 154 | 155 | // IntSliceP is like IntSlice, but accepts a shorthand letter that can be used after a single dash. 156 | func IntSliceP(name, shorthand string, value []int, usage string) *[]int { 157 | return CommandLine.IntSliceP(name, shorthand, value, usage) 158 | } 159 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/ip.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import ( 4 | "fmt" 5 | "net" 6 | "strings" 7 | ) 8 | 9 | // -- net.IP value 10 | type ipValue net.IP 11 | 12 | func newIPValue(val net.IP, p *net.IP) *ipValue { 13 | *p = val 14 | return (*ipValue)(p) 15 | } 16 | 17 | func (i *ipValue) String() string { return net.IP(*i).String() } 18 | func (i *ipValue) Set(s string) error { 19 | ip := net.ParseIP(strings.TrimSpace(s)) 20 | if ip == nil { 21 | return fmt.Errorf("failed to parse IP: %q", s) 22 | } 23 | *i = ipValue(ip) 24 | return nil 25 | } 26 | 27 | func (i *ipValue) Type() string { 28 | return "ip" 29 | } 30 | 31 | func ipConv(sval string) (interface{}, error) { 32 | ip := net.ParseIP(sval) 33 | if ip != nil { 34 | return ip, nil 35 | } 36 | return nil, fmt.Errorf("invalid string being converted to IP address: %s", sval) 37 | } 38 | 39 | // GetIP return the net.IP value of a flag with the given name 40 | func (f *FlagSet) GetIP(name string) (net.IP, error) { 41 | val, err := f.getFlagType(name, "ip", ipConv) 42 | if err != nil { 43 | return nil, err 44 | } 45 | return val.(net.IP), nil 46 | } 47 | 48 | // IPVar defines an net.IP flag with specified name, default value, and usage string. 49 | // The argument p points to an net.IP variable in which to store the value of the flag. 50 | func (f *FlagSet) IPVar(p *net.IP, name string, value net.IP, usage string) { 51 | f.VarP(newIPValue(value, p), name, "", usage) 52 | } 53 | 54 | // IPVarP is like IPVar, but accepts a shorthand letter that can be used after a single dash. 55 | func (f *FlagSet) IPVarP(p *net.IP, name, shorthand string, value net.IP, usage string) { 56 | f.VarP(newIPValue(value, p), name, shorthand, usage) 57 | } 58 | 59 | // IPVar defines an net.IP flag with specified name, default value, and usage string. 60 | // The argument p points to an net.IP variable in which to store the value of the flag. 61 | func IPVar(p *net.IP, name string, value net.IP, usage string) { 62 | CommandLine.VarP(newIPValue(value, p), name, "", usage) 63 | } 64 | 65 | // IPVarP is like IPVar, but accepts a shorthand letter that can be used after a single dash. 66 | func IPVarP(p *net.IP, name, shorthand string, value net.IP, usage string) { 67 | CommandLine.VarP(newIPValue(value, p), name, shorthand, usage) 68 | } 69 | 70 | // IP defines an net.IP flag with specified name, default value, and usage string. 71 | // The return value is the address of an net.IP variable that stores the value of the flag. 72 | func (f *FlagSet) IP(name string, value net.IP, usage string) *net.IP { 73 | p := new(net.IP) 74 | f.IPVarP(p, name, "", value, usage) 75 | return p 76 | } 77 | 78 | // IPP is like IP, but accepts a shorthand letter that can be used after a single dash. 79 | func (f *FlagSet) IPP(name, shorthand string, value net.IP, usage string) *net.IP { 80 | p := new(net.IP) 81 | f.IPVarP(p, name, shorthand, value, usage) 82 | return p 83 | } 84 | 85 | // IP defines an net.IP flag with specified name, default value, and usage string. 86 | // The return value is the address of an net.IP variable that stores the value of the flag. 87 | func IP(name string, value net.IP, usage string) *net.IP { 88 | return CommandLine.IPP(name, "", value, usage) 89 | } 90 | 91 | // IPP is like IP, but accepts a shorthand letter that can be used after a single dash. 92 | func IPP(name, shorthand string, value net.IP, usage string) *net.IP { 93 | return CommandLine.IPP(name, shorthand, value, usage) 94 | } 95 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/ipmask.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import ( 4 | "fmt" 5 | "net" 6 | "strconv" 7 | ) 8 | 9 | // -- net.IPMask value 10 | type ipMaskValue net.IPMask 11 | 12 | func newIPMaskValue(val net.IPMask, p *net.IPMask) *ipMaskValue { 13 | *p = val 14 | return (*ipMaskValue)(p) 15 | } 16 | 17 | func (i *ipMaskValue) String() string { return net.IPMask(*i).String() } 18 | func (i *ipMaskValue) Set(s string) error { 19 | ip := ParseIPv4Mask(s) 20 | if ip == nil { 21 | return fmt.Errorf("failed to parse IP mask: %q", s) 22 | } 23 | *i = ipMaskValue(ip) 24 | return nil 25 | } 26 | 27 | func (i *ipMaskValue) Type() string { 28 | return "ipMask" 29 | } 30 | 31 | // ParseIPv4Mask written in IP form (e.g. 255.255.255.0). 32 | // This function should really belong to the net package. 33 | func ParseIPv4Mask(s string) net.IPMask { 34 | mask := net.ParseIP(s) 35 | if mask == nil { 36 | if len(s) != 8 { 37 | return nil 38 | } 39 | // net.IPMask.String() actually outputs things like ffffff00 40 | // so write a horrible parser for that as well :-( 41 | m := []int{} 42 | for i := 0; i < 4; i++ { 43 | b := "0x" + s[2*i:2*i+2] 44 | d, err := strconv.ParseInt(b, 0, 0) 45 | if err != nil { 46 | return nil 47 | } 48 | m = append(m, int(d)) 49 | } 50 | s := fmt.Sprintf("%d.%d.%d.%d", m[0], m[1], m[2], m[3]) 51 | mask = net.ParseIP(s) 52 | if mask == nil { 53 | return nil 54 | } 55 | } 56 | return net.IPv4Mask(mask[12], mask[13], mask[14], mask[15]) 57 | } 58 | 59 | func parseIPv4Mask(sval string) (interface{}, error) { 60 | mask := ParseIPv4Mask(sval) 61 | if mask == nil { 62 | return nil, fmt.Errorf("unable to parse %s as net.IPMask", sval) 63 | } 64 | return mask, nil 65 | } 66 | 67 | // GetIPv4Mask return the net.IPv4Mask value of a flag with the given name 68 | func (f *FlagSet) GetIPv4Mask(name string) (net.IPMask, error) { 69 | val, err := f.getFlagType(name, "ipMask", parseIPv4Mask) 70 | if err != nil { 71 | return nil, err 72 | } 73 | return val.(net.IPMask), nil 74 | } 75 | 76 | // IPMaskVar defines an net.IPMask flag with specified name, default value, and usage string. 77 | // The argument p points to an net.IPMask variable in which to store the value of the flag. 78 | func (f *FlagSet) IPMaskVar(p *net.IPMask, name string, value net.IPMask, usage string) { 79 | f.VarP(newIPMaskValue(value, p), name, "", usage) 80 | } 81 | 82 | // IPMaskVarP is like IPMaskVar, but accepts a shorthand letter that can be used after a single dash. 83 | func (f *FlagSet) IPMaskVarP(p *net.IPMask, name, shorthand string, value net.IPMask, usage string) { 84 | f.VarP(newIPMaskValue(value, p), name, shorthand, usage) 85 | } 86 | 87 | // IPMaskVar defines an net.IPMask flag with specified name, default value, and usage string. 88 | // The argument p points to an net.IPMask variable in which to store the value of the flag. 89 | func IPMaskVar(p *net.IPMask, name string, value net.IPMask, usage string) { 90 | CommandLine.VarP(newIPMaskValue(value, p), name, "", usage) 91 | } 92 | 93 | // IPMaskVarP is like IPMaskVar, but accepts a shorthand letter that can be used after a single dash. 94 | func IPMaskVarP(p *net.IPMask, name, shorthand string, value net.IPMask, usage string) { 95 | CommandLine.VarP(newIPMaskValue(value, p), name, shorthand, usage) 96 | } 97 | 98 | // IPMask defines an net.IPMask flag with specified name, default value, and usage string. 99 | // The return value is the address of an net.IPMask variable that stores the value of the flag. 100 | func (f *FlagSet) IPMask(name string, value net.IPMask, usage string) *net.IPMask { 101 | p := new(net.IPMask) 102 | f.IPMaskVarP(p, name, "", value, usage) 103 | return p 104 | } 105 | 106 | // IPMaskP is like IPMask, but accepts a shorthand letter that can be used after a single dash. 107 | func (f *FlagSet) IPMaskP(name, shorthand string, value net.IPMask, usage string) *net.IPMask { 108 | p := new(net.IPMask) 109 | f.IPMaskVarP(p, name, shorthand, value, usage) 110 | return p 111 | } 112 | 113 | // IPMask defines an net.IPMask flag with specified name, default value, and usage string. 114 | // The return value is the address of an net.IPMask variable that stores the value of the flag. 115 | func IPMask(name string, value net.IPMask, usage string) *net.IPMask { 116 | return CommandLine.IPMaskP(name, "", value, usage) 117 | } 118 | 119 | // IPMaskP is like IP, but accepts a shorthand letter that can be used after a single dash. 120 | func IPMaskP(name, shorthand string, value net.IPMask, usage string) *net.IPMask { 121 | return CommandLine.IPMaskP(name, shorthand, value, usage) 122 | } 123 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/ipnet.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import ( 4 | "fmt" 5 | "net" 6 | "strings" 7 | ) 8 | 9 | // IPNet adapts net.IPNet for use as a flag. 10 | type ipNetValue net.IPNet 11 | 12 | func (ipnet ipNetValue) String() string { 13 | n := net.IPNet(ipnet) 14 | return n.String() 15 | } 16 | 17 | func (ipnet *ipNetValue) Set(value string) error { 18 | _, n, err := net.ParseCIDR(strings.TrimSpace(value)) 19 | if err != nil { 20 | return err 21 | } 22 | *ipnet = ipNetValue(*n) 23 | return nil 24 | } 25 | 26 | func (*ipNetValue) Type() string { 27 | return "ipNet" 28 | } 29 | 30 | func newIPNetValue(val net.IPNet, p *net.IPNet) *ipNetValue { 31 | *p = val 32 | return (*ipNetValue)(p) 33 | } 34 | 35 | func ipNetConv(sval string) (interface{}, error) { 36 | _, n, err := net.ParseCIDR(strings.TrimSpace(sval)) 37 | if err == nil { 38 | return *n, nil 39 | } 40 | return nil, fmt.Errorf("invalid string being converted to IPNet: %s", sval) 41 | } 42 | 43 | // GetIPNet return the net.IPNet value of a flag with the given name 44 | func (f *FlagSet) GetIPNet(name string) (net.IPNet, error) { 45 | val, err := f.getFlagType(name, "ipNet", ipNetConv) 46 | if err != nil { 47 | return net.IPNet{}, err 48 | } 49 | return val.(net.IPNet), nil 50 | } 51 | 52 | // IPNetVar defines an net.IPNet flag with specified name, default value, and usage string. 53 | // The argument p points to an net.IPNet variable in which to store the value of the flag. 54 | func (f *FlagSet) IPNetVar(p *net.IPNet, name string, value net.IPNet, usage string) { 55 | f.VarP(newIPNetValue(value, p), name, "", usage) 56 | } 57 | 58 | // IPNetVarP is like IPNetVar, but accepts a shorthand letter that can be used after a single dash. 59 | func (f *FlagSet) IPNetVarP(p *net.IPNet, name, shorthand string, value net.IPNet, usage string) { 60 | f.VarP(newIPNetValue(value, p), name, shorthand, usage) 61 | } 62 | 63 | // IPNetVar defines an net.IPNet flag with specified name, default value, and usage string. 64 | // The argument p points to an net.IPNet variable in which to store the value of the flag. 65 | func IPNetVar(p *net.IPNet, name string, value net.IPNet, usage string) { 66 | CommandLine.VarP(newIPNetValue(value, p), name, "", usage) 67 | } 68 | 69 | // IPNetVarP is like IPNetVar, but accepts a shorthand letter that can be used after a single dash. 70 | func IPNetVarP(p *net.IPNet, name, shorthand string, value net.IPNet, usage string) { 71 | CommandLine.VarP(newIPNetValue(value, p), name, shorthand, usage) 72 | } 73 | 74 | // IPNet defines an net.IPNet flag with specified name, default value, and usage string. 75 | // The return value is the address of an net.IPNet variable that stores the value of the flag. 76 | func (f *FlagSet) IPNet(name string, value net.IPNet, usage string) *net.IPNet { 77 | p := new(net.IPNet) 78 | f.IPNetVarP(p, name, "", value, usage) 79 | return p 80 | } 81 | 82 | // IPNetP is like IPNet, but accepts a shorthand letter that can be used after a single dash. 83 | func (f *FlagSet) IPNetP(name, shorthand string, value net.IPNet, usage string) *net.IPNet { 84 | p := new(net.IPNet) 85 | f.IPNetVarP(p, name, shorthand, value, usage) 86 | return p 87 | } 88 | 89 | // IPNet defines an net.IPNet flag with specified name, default value, and usage string. 90 | // The return value is the address of an net.IPNet variable that stores the value of the flag. 91 | func IPNet(name string, value net.IPNet, usage string) *net.IPNet { 92 | return CommandLine.IPNetP(name, "", value, usage) 93 | } 94 | 95 | // IPNetP is like IPNet, but accepts a shorthand letter that can be used after a single dash. 96 | func IPNetP(name, shorthand string, value net.IPNet, usage string) *net.IPNet { 97 | return CommandLine.IPNetP(name, shorthand, value, usage) 98 | } 99 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/string.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | // -- string Value 4 | type stringValue string 5 | 6 | func newStringValue(val string, p *string) *stringValue { 7 | *p = val 8 | return (*stringValue)(p) 9 | } 10 | 11 | func (s *stringValue) Set(val string) error { 12 | *s = stringValue(val) 13 | return nil 14 | } 15 | func (s *stringValue) Type() string { 16 | return "string" 17 | } 18 | 19 | func (s *stringValue) String() string { return string(*s) } 20 | 21 | func stringConv(sval string) (interface{}, error) { 22 | return sval, nil 23 | } 24 | 25 | // GetString return the string value of a flag with the given name 26 | func (f *FlagSet) GetString(name string) (string, error) { 27 | val, err := f.getFlagType(name, "string", stringConv) 28 | if err != nil { 29 | return "", err 30 | } 31 | return val.(string), nil 32 | } 33 | 34 | // StringVar defines a string flag with specified name, default value, and usage string. 35 | // The argument p points to a string variable in which to store the value of the flag. 36 | func (f *FlagSet) StringVar(p *string, name string, value string, usage string) { 37 | f.VarP(newStringValue(value, p), name, "", usage) 38 | } 39 | 40 | // StringVarP is like StringVar, but accepts a shorthand letter that can be used after a single dash. 41 | func (f *FlagSet) StringVarP(p *string, name, shorthand string, value string, usage string) { 42 | f.VarP(newStringValue(value, p), name, shorthand, usage) 43 | } 44 | 45 | // StringVar defines a string flag with specified name, default value, and usage string. 46 | // The argument p points to a string variable in which to store the value of the flag. 47 | func StringVar(p *string, name string, value string, usage string) { 48 | CommandLine.VarP(newStringValue(value, p), name, "", usage) 49 | } 50 | 51 | // StringVarP is like StringVar, but accepts a shorthand letter that can be used after a single dash. 52 | func StringVarP(p *string, name, shorthand string, value string, usage string) { 53 | CommandLine.VarP(newStringValue(value, p), name, shorthand, usage) 54 | } 55 | 56 | // String defines a string flag with specified name, default value, and usage string. 57 | // The return value is the address of a string variable that stores the value of the flag. 58 | func (f *FlagSet) String(name string, value string, usage string) *string { 59 | p := new(string) 60 | f.StringVarP(p, name, "", value, usage) 61 | return p 62 | } 63 | 64 | // StringP is like String, but accepts a shorthand letter that can be used after a single dash. 65 | func (f *FlagSet) StringP(name, shorthand string, value string, usage string) *string { 66 | p := new(string) 67 | f.StringVarP(p, name, shorthand, value, usage) 68 | return p 69 | } 70 | 71 | // String defines a string flag with specified name, default value, and usage string. 72 | // The return value is the address of a string variable that stores the value of the flag. 73 | func String(name string, value string, usage string) *string { 74 | return CommandLine.StringP(name, "", value, usage) 75 | } 76 | 77 | // StringP is like String, but accepts a shorthand letter that can be used after a single dash. 78 | func StringP(name, shorthand string, value string, usage string) *string { 79 | return CommandLine.StringP(name, shorthand, value, usage) 80 | } 81 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/string_array.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | // -- stringArray Value 4 | type stringArrayValue struct { 5 | value *[]string 6 | changed bool 7 | } 8 | 9 | func newStringArrayValue(val []string, p *[]string) *stringArrayValue { 10 | ssv := new(stringArrayValue) 11 | ssv.value = p 12 | *ssv.value = val 13 | return ssv 14 | } 15 | 16 | func (s *stringArrayValue) Set(val string) error { 17 | if !s.changed { 18 | *s.value = []string{val} 19 | s.changed = true 20 | } else { 21 | *s.value = append(*s.value, val) 22 | } 23 | return nil 24 | } 25 | 26 | func (s *stringArrayValue) Append(val string) error { 27 | *s.value = append(*s.value, val) 28 | return nil 29 | } 30 | 31 | func (s *stringArrayValue) Replace(val []string) error { 32 | out := make([]string, len(val)) 33 | for i, d := range val { 34 | var err error 35 | out[i] = d 36 | if err != nil { 37 | return err 38 | } 39 | } 40 | *s.value = out 41 | return nil 42 | } 43 | 44 | func (s *stringArrayValue) GetSlice() []string { 45 | out := make([]string, len(*s.value)) 46 | for i, d := range *s.value { 47 | out[i] = d 48 | } 49 | return out 50 | } 51 | 52 | func (s *stringArrayValue) Type() string { 53 | return "stringArray" 54 | } 55 | 56 | func (s *stringArrayValue) String() string { 57 | str, _ := writeAsCSV(*s.value) 58 | return "[" + str + "]" 59 | } 60 | 61 | func stringArrayConv(sval string) (interface{}, error) { 62 | sval = sval[1 : len(sval)-1] 63 | // An empty string would cause a array with one (empty) string 64 | if len(sval) == 0 { 65 | return []string{}, nil 66 | } 67 | return readAsCSV(sval) 68 | } 69 | 70 | // GetStringArray return the []string value of a flag with the given name 71 | func (f *FlagSet) GetStringArray(name string) ([]string, error) { 72 | val, err := f.getFlagType(name, "stringArray", stringArrayConv) 73 | if err != nil { 74 | return []string{}, err 75 | } 76 | return val.([]string), nil 77 | } 78 | 79 | // StringArrayVar defines a string flag with specified name, default value, and usage string. 80 | // The argument p points to a []string variable in which to store the values of the multiple flags. 81 | // The value of each argument will not try to be separated by comma. Use a StringSlice for that. 82 | func (f *FlagSet) StringArrayVar(p *[]string, name string, value []string, usage string) { 83 | f.VarP(newStringArrayValue(value, p), name, "", usage) 84 | } 85 | 86 | // StringArrayVarP is like StringArrayVar, but accepts a shorthand letter that can be used after a single dash. 87 | func (f *FlagSet) StringArrayVarP(p *[]string, name, shorthand string, value []string, usage string) { 88 | f.VarP(newStringArrayValue(value, p), name, shorthand, usage) 89 | } 90 | 91 | // StringArrayVar defines a string flag with specified name, default value, and usage string. 92 | // The argument p points to a []string variable in which to store the value of the flag. 93 | // The value of each argument will not try to be separated by comma. Use a StringSlice for that. 94 | func StringArrayVar(p *[]string, name string, value []string, usage string) { 95 | CommandLine.VarP(newStringArrayValue(value, p), name, "", usage) 96 | } 97 | 98 | // StringArrayVarP is like StringArrayVar, but accepts a shorthand letter that can be used after a single dash. 99 | func StringArrayVarP(p *[]string, name, shorthand string, value []string, usage string) { 100 | CommandLine.VarP(newStringArrayValue(value, p), name, shorthand, usage) 101 | } 102 | 103 | // StringArray defines a string flag with specified name, default value, and usage string. 104 | // The return value is the address of a []string variable that stores the value of the flag. 105 | // The value of each argument will not try to be separated by comma. Use a StringSlice for that. 106 | func (f *FlagSet) StringArray(name string, value []string, usage string) *[]string { 107 | p := []string{} 108 | f.StringArrayVarP(&p, name, "", value, usage) 109 | return &p 110 | } 111 | 112 | // StringArrayP is like StringArray, but accepts a shorthand letter that can be used after a single dash. 113 | func (f *FlagSet) StringArrayP(name, shorthand string, value []string, usage string) *[]string { 114 | p := []string{} 115 | f.StringArrayVarP(&p, name, shorthand, value, usage) 116 | return &p 117 | } 118 | 119 | // StringArray defines a string flag with specified name, default value, and usage string. 120 | // The return value is the address of a []string variable that stores the value of the flag. 121 | // The value of each argument will not try to be separated by comma. Use a StringSlice for that. 122 | func StringArray(name string, value []string, usage string) *[]string { 123 | return CommandLine.StringArrayP(name, "", value, usage) 124 | } 125 | 126 | // StringArrayP is like StringArray, but accepts a shorthand letter that can be used after a single dash. 127 | func StringArrayP(name, shorthand string, value []string, usage string) *[]string { 128 | return CommandLine.StringArrayP(name, shorthand, value, usage) 129 | } 130 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/string_to_int.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import ( 4 | "bytes" 5 | "fmt" 6 | "strconv" 7 | "strings" 8 | ) 9 | 10 | // -- stringToInt Value 11 | type stringToIntValue struct { 12 | value *map[string]int 13 | changed bool 14 | } 15 | 16 | func newStringToIntValue(val map[string]int, p *map[string]int) *stringToIntValue { 17 | ssv := new(stringToIntValue) 18 | ssv.value = p 19 | *ssv.value = val 20 | return ssv 21 | } 22 | 23 | // Format: a=1,b=2 24 | func (s *stringToIntValue) Set(val string) error { 25 | ss := strings.Split(val, ",") 26 | out := make(map[string]int, len(ss)) 27 | for _, pair := range ss { 28 | kv := strings.SplitN(pair, "=", 2) 29 | if len(kv) != 2 { 30 | return fmt.Errorf("%s must be formatted as key=value", pair) 31 | } 32 | var err error 33 | out[kv[0]], err = strconv.Atoi(kv[1]) 34 | if err != nil { 35 | return err 36 | } 37 | } 38 | if !s.changed { 39 | *s.value = out 40 | } else { 41 | for k, v := range out { 42 | (*s.value)[k] = v 43 | } 44 | } 45 | s.changed = true 46 | return nil 47 | } 48 | 49 | func (s *stringToIntValue) Type() string { 50 | return "stringToInt" 51 | } 52 | 53 | func (s *stringToIntValue) String() string { 54 | var buf bytes.Buffer 55 | i := 0 56 | for k, v := range *s.value { 57 | if i > 0 { 58 | buf.WriteRune(',') 59 | } 60 | buf.WriteString(k) 61 | buf.WriteRune('=') 62 | buf.WriteString(strconv.Itoa(v)) 63 | i++ 64 | } 65 | return "[" + buf.String() + "]" 66 | } 67 | 68 | func stringToIntConv(val string) (interface{}, error) { 69 | val = strings.Trim(val, "[]") 70 | // An empty string would cause an empty map 71 | if len(val) == 0 { 72 | return map[string]int{}, nil 73 | } 74 | ss := strings.Split(val, ",") 75 | out := make(map[string]int, len(ss)) 76 | for _, pair := range ss { 77 | kv := strings.SplitN(pair, "=", 2) 78 | if len(kv) != 2 { 79 | return nil, fmt.Errorf("%s must be formatted as key=value", pair) 80 | } 81 | var err error 82 | out[kv[0]], err = strconv.Atoi(kv[1]) 83 | if err != nil { 84 | return nil, err 85 | } 86 | } 87 | return out, nil 88 | } 89 | 90 | // GetStringToInt return the map[string]int value of a flag with the given name 91 | func (f *FlagSet) GetStringToInt(name string) (map[string]int, error) { 92 | val, err := f.getFlagType(name, "stringToInt", stringToIntConv) 93 | if err != nil { 94 | return map[string]int{}, err 95 | } 96 | return val.(map[string]int), nil 97 | } 98 | 99 | // StringToIntVar defines a string flag with specified name, default value, and usage string. 100 | // The argument p points to a map[string]int variable in which to store the values of the multiple flags. 101 | // The value of each argument will not try to be separated by comma 102 | func (f *FlagSet) StringToIntVar(p *map[string]int, name string, value map[string]int, usage string) { 103 | f.VarP(newStringToIntValue(value, p), name, "", usage) 104 | } 105 | 106 | // StringToIntVarP is like StringToIntVar, but accepts a shorthand letter that can be used after a single dash. 107 | func (f *FlagSet) StringToIntVarP(p *map[string]int, name, shorthand string, value map[string]int, usage string) { 108 | f.VarP(newStringToIntValue(value, p), name, shorthand, usage) 109 | } 110 | 111 | // StringToIntVar defines a string flag with specified name, default value, and usage string. 112 | // The argument p points to a map[string]int variable in which to store the value of the flag. 113 | // The value of each argument will not try to be separated by comma 114 | func StringToIntVar(p *map[string]int, name string, value map[string]int, usage string) { 115 | CommandLine.VarP(newStringToIntValue(value, p), name, "", usage) 116 | } 117 | 118 | // StringToIntVarP is like StringToIntVar, but accepts a shorthand letter that can be used after a single dash. 119 | func StringToIntVarP(p *map[string]int, name, shorthand string, value map[string]int, usage string) { 120 | CommandLine.VarP(newStringToIntValue(value, p), name, shorthand, usage) 121 | } 122 | 123 | // StringToInt defines a string flag with specified name, default value, and usage string. 124 | // The return value is the address of a map[string]int variable that stores the value of the flag. 125 | // The value of each argument will not try to be separated by comma 126 | func (f *FlagSet) StringToInt(name string, value map[string]int, usage string) *map[string]int { 127 | p := map[string]int{} 128 | f.StringToIntVarP(&p, name, "", value, usage) 129 | return &p 130 | } 131 | 132 | // StringToIntP is like StringToInt, but accepts a shorthand letter that can be used after a single dash. 133 | func (f *FlagSet) StringToIntP(name, shorthand string, value map[string]int, usage string) *map[string]int { 134 | p := map[string]int{} 135 | f.StringToIntVarP(&p, name, shorthand, value, usage) 136 | return &p 137 | } 138 | 139 | // StringToInt defines a string flag with specified name, default value, and usage string. 140 | // The return value is the address of a map[string]int variable that stores the value of the flag. 141 | // The value of each argument will not try to be separated by comma 142 | func StringToInt(name string, value map[string]int, usage string) *map[string]int { 143 | return CommandLine.StringToIntP(name, "", value, usage) 144 | } 145 | 146 | // StringToIntP is like StringToInt, but accepts a shorthand letter that can be used after a single dash. 147 | func StringToIntP(name, shorthand string, value map[string]int, usage string) *map[string]int { 148 | return CommandLine.StringToIntP(name, shorthand, value, usage) 149 | } 150 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/string_to_int64.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import ( 4 | "bytes" 5 | "fmt" 6 | "strconv" 7 | "strings" 8 | ) 9 | 10 | // -- stringToInt64 Value 11 | type stringToInt64Value struct { 12 | value *map[string]int64 13 | changed bool 14 | } 15 | 16 | func newStringToInt64Value(val map[string]int64, p *map[string]int64) *stringToInt64Value { 17 | ssv := new(stringToInt64Value) 18 | ssv.value = p 19 | *ssv.value = val 20 | return ssv 21 | } 22 | 23 | // Format: a=1,b=2 24 | func (s *stringToInt64Value) Set(val string) error { 25 | ss := strings.Split(val, ",") 26 | out := make(map[string]int64, len(ss)) 27 | for _, pair := range ss { 28 | kv := strings.SplitN(pair, "=", 2) 29 | if len(kv) != 2 { 30 | return fmt.Errorf("%s must be formatted as key=value", pair) 31 | } 32 | var err error 33 | out[kv[0]], err = strconv.ParseInt(kv[1], 10, 64) 34 | if err != nil { 35 | return err 36 | } 37 | } 38 | if !s.changed { 39 | *s.value = out 40 | } else { 41 | for k, v := range out { 42 | (*s.value)[k] = v 43 | } 44 | } 45 | s.changed = true 46 | return nil 47 | } 48 | 49 | func (s *stringToInt64Value) Type() string { 50 | return "stringToInt64" 51 | } 52 | 53 | func (s *stringToInt64Value) String() string { 54 | var buf bytes.Buffer 55 | i := 0 56 | for k, v := range *s.value { 57 | if i > 0 { 58 | buf.WriteRune(',') 59 | } 60 | buf.WriteString(k) 61 | buf.WriteRune('=') 62 | buf.WriteString(strconv.FormatInt(v, 10)) 63 | i++ 64 | } 65 | return "[" + buf.String() + "]" 66 | } 67 | 68 | func stringToInt64Conv(val string) (interface{}, error) { 69 | val = strings.Trim(val, "[]") 70 | // An empty string would cause an empty map 71 | if len(val) == 0 { 72 | return map[string]int64{}, nil 73 | } 74 | ss := strings.Split(val, ",") 75 | out := make(map[string]int64, len(ss)) 76 | for _, pair := range ss { 77 | kv := strings.SplitN(pair, "=", 2) 78 | if len(kv) != 2 { 79 | return nil, fmt.Errorf("%s must be formatted as key=value", pair) 80 | } 81 | var err error 82 | out[kv[0]], err = strconv.ParseInt(kv[1], 10, 64) 83 | if err != nil { 84 | return nil, err 85 | } 86 | } 87 | return out, nil 88 | } 89 | 90 | // GetStringToInt64 return the map[string]int64 value of a flag with the given name 91 | func (f *FlagSet) GetStringToInt64(name string) (map[string]int64, error) { 92 | val, err := f.getFlagType(name, "stringToInt64", stringToInt64Conv) 93 | if err != nil { 94 | return map[string]int64{}, err 95 | } 96 | return val.(map[string]int64), nil 97 | } 98 | 99 | // StringToInt64Var defines a string flag with specified name, default value, and usage string. 100 | // The argument p point64s to a map[string]int64 variable in which to store the values of the multiple flags. 101 | // The value of each argument will not try to be separated by comma 102 | func (f *FlagSet) StringToInt64Var(p *map[string]int64, name string, value map[string]int64, usage string) { 103 | f.VarP(newStringToInt64Value(value, p), name, "", usage) 104 | } 105 | 106 | // StringToInt64VarP is like StringToInt64Var, but accepts a shorthand letter that can be used after a single dash. 107 | func (f *FlagSet) StringToInt64VarP(p *map[string]int64, name, shorthand string, value map[string]int64, usage string) { 108 | f.VarP(newStringToInt64Value(value, p), name, shorthand, usage) 109 | } 110 | 111 | // StringToInt64Var defines a string flag with specified name, default value, and usage string. 112 | // The argument p point64s to a map[string]int64 variable in which to store the value of the flag. 113 | // The value of each argument will not try to be separated by comma 114 | func StringToInt64Var(p *map[string]int64, name string, value map[string]int64, usage string) { 115 | CommandLine.VarP(newStringToInt64Value(value, p), name, "", usage) 116 | } 117 | 118 | // StringToInt64VarP is like StringToInt64Var, but accepts a shorthand letter that can be used after a single dash. 119 | func StringToInt64VarP(p *map[string]int64, name, shorthand string, value map[string]int64, usage string) { 120 | CommandLine.VarP(newStringToInt64Value(value, p), name, shorthand, usage) 121 | } 122 | 123 | // StringToInt64 defines a string flag with specified name, default value, and usage string. 124 | // The return value is the address of a map[string]int64 variable that stores the value of the flag. 125 | // The value of each argument will not try to be separated by comma 126 | func (f *FlagSet) StringToInt64(name string, value map[string]int64, usage string) *map[string]int64 { 127 | p := map[string]int64{} 128 | f.StringToInt64VarP(&p, name, "", value, usage) 129 | return &p 130 | } 131 | 132 | // StringToInt64P is like StringToInt64, but accepts a shorthand letter that can be used after a single dash. 133 | func (f *FlagSet) StringToInt64P(name, shorthand string, value map[string]int64, usage string) *map[string]int64 { 134 | p := map[string]int64{} 135 | f.StringToInt64VarP(&p, name, shorthand, value, usage) 136 | return &p 137 | } 138 | 139 | // StringToInt64 defines a string flag with specified name, default value, and usage string. 140 | // The return value is the address of a map[string]int64 variable that stores the value of the flag. 141 | // The value of each argument will not try to be separated by comma 142 | func StringToInt64(name string, value map[string]int64, usage string) *map[string]int64 { 143 | return CommandLine.StringToInt64P(name, "", value, usage) 144 | } 145 | 146 | // StringToInt64P is like StringToInt64, but accepts a shorthand letter that can be used after a single dash. 147 | func StringToInt64P(name, shorthand string, value map[string]int64, usage string) *map[string]int64 { 148 | return CommandLine.StringToInt64P(name, shorthand, value, usage) 149 | } 150 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/uint.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- uint Value 6 | type uintValue uint 7 | 8 | func newUintValue(val uint, p *uint) *uintValue { 9 | *p = val 10 | return (*uintValue)(p) 11 | } 12 | 13 | func (i *uintValue) Set(s string) error { 14 | v, err := strconv.ParseUint(s, 0, 64) 15 | *i = uintValue(v) 16 | return err 17 | } 18 | 19 | func (i *uintValue) Type() string { 20 | return "uint" 21 | } 22 | 23 | func (i *uintValue) String() string { return strconv.FormatUint(uint64(*i), 10) } 24 | 25 | func uintConv(sval string) (interface{}, error) { 26 | v, err := strconv.ParseUint(sval, 0, 0) 27 | if err != nil { 28 | return 0, err 29 | } 30 | return uint(v), nil 31 | } 32 | 33 | // GetUint return the uint value of a flag with the given name 34 | func (f *FlagSet) GetUint(name string) (uint, error) { 35 | val, err := f.getFlagType(name, "uint", uintConv) 36 | if err != nil { 37 | return 0, err 38 | } 39 | return val.(uint), nil 40 | } 41 | 42 | // UintVar defines a uint flag with specified name, default value, and usage string. 43 | // The argument p points to a uint variable in which to store the value of the flag. 44 | func (f *FlagSet) UintVar(p *uint, name string, value uint, usage string) { 45 | f.VarP(newUintValue(value, p), name, "", usage) 46 | } 47 | 48 | // UintVarP is like UintVar, but accepts a shorthand letter that can be used after a single dash. 49 | func (f *FlagSet) UintVarP(p *uint, name, shorthand string, value uint, usage string) { 50 | f.VarP(newUintValue(value, p), name, shorthand, usage) 51 | } 52 | 53 | // UintVar defines a uint flag with specified name, default value, and usage string. 54 | // The argument p points to a uint variable in which to store the value of the flag. 55 | func UintVar(p *uint, name string, value uint, usage string) { 56 | CommandLine.VarP(newUintValue(value, p), name, "", usage) 57 | } 58 | 59 | // UintVarP is like UintVar, but accepts a shorthand letter that can be used after a single dash. 60 | func UintVarP(p *uint, name, shorthand string, value uint, usage string) { 61 | CommandLine.VarP(newUintValue(value, p), name, shorthand, usage) 62 | } 63 | 64 | // Uint defines a uint flag with specified name, default value, and usage string. 65 | // The return value is the address of a uint variable that stores the value of the flag. 66 | func (f *FlagSet) Uint(name string, value uint, usage string) *uint { 67 | p := new(uint) 68 | f.UintVarP(p, name, "", value, usage) 69 | return p 70 | } 71 | 72 | // UintP is like Uint, but accepts a shorthand letter that can be used after a single dash. 73 | func (f *FlagSet) UintP(name, shorthand string, value uint, usage string) *uint { 74 | p := new(uint) 75 | f.UintVarP(p, name, shorthand, value, usage) 76 | return p 77 | } 78 | 79 | // Uint defines a uint flag with specified name, default value, and usage string. 80 | // The return value is the address of a uint variable that stores the value of the flag. 81 | func Uint(name string, value uint, usage string) *uint { 82 | return CommandLine.UintP(name, "", value, usage) 83 | } 84 | 85 | // UintP is like Uint, but accepts a shorthand letter that can be used after a single dash. 86 | func UintP(name, shorthand string, value uint, usage string) *uint { 87 | return CommandLine.UintP(name, shorthand, value, usage) 88 | } 89 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/uint16.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- uint16 value 6 | type uint16Value uint16 7 | 8 | func newUint16Value(val uint16, p *uint16) *uint16Value { 9 | *p = val 10 | return (*uint16Value)(p) 11 | } 12 | 13 | func (i *uint16Value) Set(s string) error { 14 | v, err := strconv.ParseUint(s, 0, 16) 15 | *i = uint16Value(v) 16 | return err 17 | } 18 | 19 | func (i *uint16Value) Type() string { 20 | return "uint16" 21 | } 22 | 23 | func (i *uint16Value) String() string { return strconv.FormatUint(uint64(*i), 10) } 24 | 25 | func uint16Conv(sval string) (interface{}, error) { 26 | v, err := strconv.ParseUint(sval, 0, 16) 27 | if err != nil { 28 | return 0, err 29 | } 30 | return uint16(v), nil 31 | } 32 | 33 | // GetUint16 return the uint16 value of a flag with the given name 34 | func (f *FlagSet) GetUint16(name string) (uint16, error) { 35 | val, err := f.getFlagType(name, "uint16", uint16Conv) 36 | if err != nil { 37 | return 0, err 38 | } 39 | return val.(uint16), nil 40 | } 41 | 42 | // Uint16Var defines a uint flag with specified name, default value, and usage string. 43 | // The argument p points to a uint variable in which to store the value of the flag. 44 | func (f *FlagSet) Uint16Var(p *uint16, name string, value uint16, usage string) { 45 | f.VarP(newUint16Value(value, p), name, "", usage) 46 | } 47 | 48 | // Uint16VarP is like Uint16Var, but accepts a shorthand letter that can be used after a single dash. 49 | func (f *FlagSet) Uint16VarP(p *uint16, name, shorthand string, value uint16, usage string) { 50 | f.VarP(newUint16Value(value, p), name, shorthand, usage) 51 | } 52 | 53 | // Uint16Var defines a uint flag with specified name, default value, and usage string. 54 | // The argument p points to a uint variable in which to store the value of the flag. 55 | func Uint16Var(p *uint16, name string, value uint16, usage string) { 56 | CommandLine.VarP(newUint16Value(value, p), name, "", usage) 57 | } 58 | 59 | // Uint16VarP is like Uint16Var, but accepts a shorthand letter that can be used after a single dash. 60 | func Uint16VarP(p *uint16, name, shorthand string, value uint16, usage string) { 61 | CommandLine.VarP(newUint16Value(value, p), name, shorthand, usage) 62 | } 63 | 64 | // Uint16 defines a uint flag with specified name, default value, and usage string. 65 | // The return value is the address of a uint variable that stores the value of the flag. 66 | func (f *FlagSet) Uint16(name string, value uint16, usage string) *uint16 { 67 | p := new(uint16) 68 | f.Uint16VarP(p, name, "", value, usage) 69 | return p 70 | } 71 | 72 | // Uint16P is like Uint16, but accepts a shorthand letter that can be used after a single dash. 73 | func (f *FlagSet) Uint16P(name, shorthand string, value uint16, usage string) *uint16 { 74 | p := new(uint16) 75 | f.Uint16VarP(p, name, shorthand, value, usage) 76 | return p 77 | } 78 | 79 | // Uint16 defines a uint flag with specified name, default value, and usage string. 80 | // The return value is the address of a uint variable that stores the value of the flag. 81 | func Uint16(name string, value uint16, usage string) *uint16 { 82 | return CommandLine.Uint16P(name, "", value, usage) 83 | } 84 | 85 | // Uint16P is like Uint16, but accepts a shorthand letter that can be used after a single dash. 86 | func Uint16P(name, shorthand string, value uint16, usage string) *uint16 { 87 | return CommandLine.Uint16P(name, shorthand, value, usage) 88 | } 89 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/uint32.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- uint32 value 6 | type uint32Value uint32 7 | 8 | func newUint32Value(val uint32, p *uint32) *uint32Value { 9 | *p = val 10 | return (*uint32Value)(p) 11 | } 12 | 13 | func (i *uint32Value) Set(s string) error { 14 | v, err := strconv.ParseUint(s, 0, 32) 15 | *i = uint32Value(v) 16 | return err 17 | } 18 | 19 | func (i *uint32Value) Type() string { 20 | return "uint32" 21 | } 22 | 23 | func (i *uint32Value) String() string { return strconv.FormatUint(uint64(*i), 10) } 24 | 25 | func uint32Conv(sval string) (interface{}, error) { 26 | v, err := strconv.ParseUint(sval, 0, 32) 27 | if err != nil { 28 | return 0, err 29 | } 30 | return uint32(v), nil 31 | } 32 | 33 | // GetUint32 return the uint32 value of a flag with the given name 34 | func (f *FlagSet) GetUint32(name string) (uint32, error) { 35 | val, err := f.getFlagType(name, "uint32", uint32Conv) 36 | if err != nil { 37 | return 0, err 38 | } 39 | return val.(uint32), nil 40 | } 41 | 42 | // Uint32Var defines a uint32 flag with specified name, default value, and usage string. 43 | // The argument p points to a uint32 variable in which to store the value of the flag. 44 | func (f *FlagSet) Uint32Var(p *uint32, name string, value uint32, usage string) { 45 | f.VarP(newUint32Value(value, p), name, "", usage) 46 | } 47 | 48 | // Uint32VarP is like Uint32Var, but accepts a shorthand letter that can be used after a single dash. 49 | func (f *FlagSet) Uint32VarP(p *uint32, name, shorthand string, value uint32, usage string) { 50 | f.VarP(newUint32Value(value, p), name, shorthand, usage) 51 | } 52 | 53 | // Uint32Var defines a uint32 flag with specified name, default value, and usage string. 54 | // The argument p points to a uint32 variable in which to store the value of the flag. 55 | func Uint32Var(p *uint32, name string, value uint32, usage string) { 56 | CommandLine.VarP(newUint32Value(value, p), name, "", usage) 57 | } 58 | 59 | // Uint32VarP is like Uint32Var, but accepts a shorthand letter that can be used after a single dash. 60 | func Uint32VarP(p *uint32, name, shorthand string, value uint32, usage string) { 61 | CommandLine.VarP(newUint32Value(value, p), name, shorthand, usage) 62 | } 63 | 64 | // Uint32 defines a uint32 flag with specified name, default value, and usage string. 65 | // The return value is the address of a uint32 variable that stores the value of the flag. 66 | func (f *FlagSet) Uint32(name string, value uint32, usage string) *uint32 { 67 | p := new(uint32) 68 | f.Uint32VarP(p, name, "", value, usage) 69 | return p 70 | } 71 | 72 | // Uint32P is like Uint32, but accepts a shorthand letter that can be used after a single dash. 73 | func (f *FlagSet) Uint32P(name, shorthand string, value uint32, usage string) *uint32 { 74 | p := new(uint32) 75 | f.Uint32VarP(p, name, shorthand, value, usage) 76 | return p 77 | } 78 | 79 | // Uint32 defines a uint32 flag with specified name, default value, and usage string. 80 | // The return value is the address of a uint32 variable that stores the value of the flag. 81 | func Uint32(name string, value uint32, usage string) *uint32 { 82 | return CommandLine.Uint32P(name, "", value, usage) 83 | } 84 | 85 | // Uint32P is like Uint32, but accepts a shorthand letter that can be used after a single dash. 86 | func Uint32P(name, shorthand string, value uint32, usage string) *uint32 { 87 | return CommandLine.Uint32P(name, shorthand, value, usage) 88 | } 89 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/uint64.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- uint64 Value 6 | type uint64Value uint64 7 | 8 | func newUint64Value(val uint64, p *uint64) *uint64Value { 9 | *p = val 10 | return (*uint64Value)(p) 11 | } 12 | 13 | func (i *uint64Value) Set(s string) error { 14 | v, err := strconv.ParseUint(s, 0, 64) 15 | *i = uint64Value(v) 16 | return err 17 | } 18 | 19 | func (i *uint64Value) Type() string { 20 | return "uint64" 21 | } 22 | 23 | func (i *uint64Value) String() string { return strconv.FormatUint(uint64(*i), 10) } 24 | 25 | func uint64Conv(sval string) (interface{}, error) { 26 | v, err := strconv.ParseUint(sval, 0, 64) 27 | if err != nil { 28 | return 0, err 29 | } 30 | return uint64(v), nil 31 | } 32 | 33 | // GetUint64 return the uint64 value of a flag with the given name 34 | func (f *FlagSet) GetUint64(name string) (uint64, error) { 35 | val, err := f.getFlagType(name, "uint64", uint64Conv) 36 | if err != nil { 37 | return 0, err 38 | } 39 | return val.(uint64), nil 40 | } 41 | 42 | // Uint64Var defines a uint64 flag with specified name, default value, and usage string. 43 | // The argument p points to a uint64 variable in which to store the value of the flag. 44 | func (f *FlagSet) Uint64Var(p *uint64, name string, value uint64, usage string) { 45 | f.VarP(newUint64Value(value, p), name, "", usage) 46 | } 47 | 48 | // Uint64VarP is like Uint64Var, but accepts a shorthand letter that can be used after a single dash. 49 | func (f *FlagSet) Uint64VarP(p *uint64, name, shorthand string, value uint64, usage string) { 50 | f.VarP(newUint64Value(value, p), name, shorthand, usage) 51 | } 52 | 53 | // Uint64Var defines a uint64 flag with specified name, default value, and usage string. 54 | // The argument p points to a uint64 variable in which to store the value of the flag. 55 | func Uint64Var(p *uint64, name string, value uint64, usage string) { 56 | CommandLine.VarP(newUint64Value(value, p), name, "", usage) 57 | } 58 | 59 | // Uint64VarP is like Uint64Var, but accepts a shorthand letter that can be used after a single dash. 60 | func Uint64VarP(p *uint64, name, shorthand string, value uint64, usage string) { 61 | CommandLine.VarP(newUint64Value(value, p), name, shorthand, usage) 62 | } 63 | 64 | // Uint64 defines a uint64 flag with specified name, default value, and usage string. 65 | // The return value is the address of a uint64 variable that stores the value of the flag. 66 | func (f *FlagSet) Uint64(name string, value uint64, usage string) *uint64 { 67 | p := new(uint64) 68 | f.Uint64VarP(p, name, "", value, usage) 69 | return p 70 | } 71 | 72 | // Uint64P is like Uint64, but accepts a shorthand letter that can be used after a single dash. 73 | func (f *FlagSet) Uint64P(name, shorthand string, value uint64, usage string) *uint64 { 74 | p := new(uint64) 75 | f.Uint64VarP(p, name, shorthand, value, usage) 76 | return p 77 | } 78 | 79 | // Uint64 defines a uint64 flag with specified name, default value, and usage string. 80 | // The return value is the address of a uint64 variable that stores the value of the flag. 81 | func Uint64(name string, value uint64, usage string) *uint64 { 82 | return CommandLine.Uint64P(name, "", value, usage) 83 | } 84 | 85 | // Uint64P is like Uint64, but accepts a shorthand letter that can be used after a single dash. 86 | func Uint64P(name, shorthand string, value uint64, usage string) *uint64 { 87 | return CommandLine.Uint64P(name, shorthand, value, usage) 88 | } 89 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/uint8.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- uint8 Value 6 | type uint8Value uint8 7 | 8 | func newUint8Value(val uint8, p *uint8) *uint8Value { 9 | *p = val 10 | return (*uint8Value)(p) 11 | } 12 | 13 | func (i *uint8Value) Set(s string) error { 14 | v, err := strconv.ParseUint(s, 0, 8) 15 | *i = uint8Value(v) 16 | return err 17 | } 18 | 19 | func (i *uint8Value) Type() string { 20 | return "uint8" 21 | } 22 | 23 | func (i *uint8Value) String() string { return strconv.FormatUint(uint64(*i), 10) } 24 | 25 | func uint8Conv(sval string) (interface{}, error) { 26 | v, err := strconv.ParseUint(sval, 0, 8) 27 | if err != nil { 28 | return 0, err 29 | } 30 | return uint8(v), nil 31 | } 32 | 33 | // GetUint8 return the uint8 value of a flag with the given name 34 | func (f *FlagSet) GetUint8(name string) (uint8, error) { 35 | val, err := f.getFlagType(name, "uint8", uint8Conv) 36 | if err != nil { 37 | return 0, err 38 | } 39 | return val.(uint8), nil 40 | } 41 | 42 | // Uint8Var defines a uint8 flag with specified name, default value, and usage string. 43 | // The argument p points to a uint8 variable in which to store the value of the flag. 44 | func (f *FlagSet) Uint8Var(p *uint8, name string, value uint8, usage string) { 45 | f.VarP(newUint8Value(value, p), name, "", usage) 46 | } 47 | 48 | // Uint8VarP is like Uint8Var, but accepts a shorthand letter that can be used after a single dash. 49 | func (f *FlagSet) Uint8VarP(p *uint8, name, shorthand string, value uint8, usage string) { 50 | f.VarP(newUint8Value(value, p), name, shorthand, usage) 51 | } 52 | 53 | // Uint8Var defines a uint8 flag with specified name, default value, and usage string. 54 | // The argument p points to a uint8 variable in which to store the value of the flag. 55 | func Uint8Var(p *uint8, name string, value uint8, usage string) { 56 | CommandLine.VarP(newUint8Value(value, p), name, "", usage) 57 | } 58 | 59 | // Uint8VarP is like Uint8Var, but accepts a shorthand letter that can be used after a single dash. 60 | func Uint8VarP(p *uint8, name, shorthand string, value uint8, usage string) { 61 | CommandLine.VarP(newUint8Value(value, p), name, shorthand, usage) 62 | } 63 | 64 | // Uint8 defines a uint8 flag with specified name, default value, and usage string. 65 | // The return value is the address of a uint8 variable that stores the value of the flag. 66 | func (f *FlagSet) Uint8(name string, value uint8, usage string) *uint8 { 67 | p := new(uint8) 68 | f.Uint8VarP(p, name, "", value, usage) 69 | return p 70 | } 71 | 72 | // Uint8P is like Uint8, but accepts a shorthand letter that can be used after a single dash. 73 | func (f *FlagSet) Uint8P(name, shorthand string, value uint8, usage string) *uint8 { 74 | p := new(uint8) 75 | f.Uint8VarP(p, name, shorthand, value, usage) 76 | return p 77 | } 78 | 79 | // Uint8 defines a uint8 flag with specified name, default value, and usage string. 80 | // The return value is the address of a uint8 variable that stores the value of the flag. 81 | func Uint8(name string, value uint8, usage string) *uint8 { 82 | return CommandLine.Uint8P(name, "", value, usage) 83 | } 84 | 85 | // Uint8P is like Uint8, but accepts a shorthand letter that can be used after a single dash. 86 | func Uint8P(name, shorthand string, value uint8, usage string) *uint8 { 87 | return CommandLine.Uint8P(name, shorthand, value, usage) 88 | } 89 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/uint_slice.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import ( 4 | "fmt" 5 | "strconv" 6 | "strings" 7 | ) 8 | 9 | // -- uintSlice Value 10 | type uintSliceValue struct { 11 | value *[]uint 12 | changed bool 13 | } 14 | 15 | func newUintSliceValue(val []uint, p *[]uint) *uintSliceValue { 16 | uisv := new(uintSliceValue) 17 | uisv.value = p 18 | *uisv.value = val 19 | return uisv 20 | } 21 | 22 | func (s *uintSliceValue) Set(val string) error { 23 | ss := strings.Split(val, ",") 24 | out := make([]uint, len(ss)) 25 | for i, d := range ss { 26 | u, err := strconv.ParseUint(d, 10, 0) 27 | if err != nil { 28 | return err 29 | } 30 | out[i] = uint(u) 31 | } 32 | if !s.changed { 33 | *s.value = out 34 | } else { 35 | *s.value = append(*s.value, out...) 36 | } 37 | s.changed = true 38 | return nil 39 | } 40 | 41 | func (s *uintSliceValue) Type() string { 42 | return "uintSlice" 43 | } 44 | 45 | func (s *uintSliceValue) String() string { 46 | out := make([]string, len(*s.value)) 47 | for i, d := range *s.value { 48 | out[i] = fmt.Sprintf("%d", d) 49 | } 50 | return "[" + strings.Join(out, ",") + "]" 51 | } 52 | 53 | func (s *uintSliceValue) fromString(val string) (uint, error) { 54 | t, err := strconv.ParseUint(val, 10, 0) 55 | if err != nil { 56 | return 0, err 57 | } 58 | return uint(t), nil 59 | } 60 | 61 | func (s *uintSliceValue) toString(val uint) string { 62 | return fmt.Sprintf("%d", val) 63 | } 64 | 65 | func (s *uintSliceValue) Append(val string) error { 66 | i, err := s.fromString(val) 67 | if err != nil { 68 | return err 69 | } 70 | *s.value = append(*s.value, i) 71 | return nil 72 | } 73 | 74 | func (s *uintSliceValue) Replace(val []string) error { 75 | out := make([]uint, len(val)) 76 | for i, d := range val { 77 | var err error 78 | out[i], err = s.fromString(d) 79 | if err != nil { 80 | return err 81 | } 82 | } 83 | *s.value = out 84 | return nil 85 | } 86 | 87 | func (s *uintSliceValue) GetSlice() []string { 88 | out := make([]string, len(*s.value)) 89 | for i, d := range *s.value { 90 | out[i] = s.toString(d) 91 | } 92 | return out 93 | } 94 | 95 | func uintSliceConv(val string) (interface{}, error) { 96 | val = strings.Trim(val, "[]") 97 | // Empty string would cause a slice with one (empty) entry 98 | if len(val) == 0 { 99 | return []uint{}, nil 100 | } 101 | ss := strings.Split(val, ",") 102 | out := make([]uint, len(ss)) 103 | for i, d := range ss { 104 | u, err := strconv.ParseUint(d, 10, 0) 105 | if err != nil { 106 | return nil, err 107 | } 108 | out[i] = uint(u) 109 | } 110 | return out, nil 111 | } 112 | 113 | // GetUintSlice returns the []uint value of a flag with the given name. 114 | func (f *FlagSet) GetUintSlice(name string) ([]uint, error) { 115 | val, err := f.getFlagType(name, "uintSlice", uintSliceConv) 116 | if err != nil { 117 | return []uint{}, err 118 | } 119 | return val.([]uint), nil 120 | } 121 | 122 | // UintSliceVar defines a uintSlice flag with specified name, default value, and usage string. 123 | // The argument p points to a []uint variable in which to store the value of the flag. 124 | func (f *FlagSet) UintSliceVar(p *[]uint, name string, value []uint, usage string) { 125 | f.VarP(newUintSliceValue(value, p), name, "", usage) 126 | } 127 | 128 | // UintSliceVarP is like UintSliceVar, but accepts a shorthand letter that can be used after a single dash. 129 | func (f *FlagSet) UintSliceVarP(p *[]uint, name, shorthand string, value []uint, usage string) { 130 | f.VarP(newUintSliceValue(value, p), name, shorthand, usage) 131 | } 132 | 133 | // UintSliceVar defines a uint[] flag with specified name, default value, and usage string. 134 | // The argument p points to a uint[] variable in which to store the value of the flag. 135 | func UintSliceVar(p *[]uint, name string, value []uint, usage string) { 136 | CommandLine.VarP(newUintSliceValue(value, p), name, "", usage) 137 | } 138 | 139 | // UintSliceVarP is like the UintSliceVar, but accepts a shorthand letter that can be used after a single dash. 140 | func UintSliceVarP(p *[]uint, name, shorthand string, value []uint, usage string) { 141 | CommandLine.VarP(newUintSliceValue(value, p), name, shorthand, usage) 142 | } 143 | 144 | // UintSlice defines a []uint flag with specified name, default value, and usage string. 145 | // The return value is the address of a []uint variable that stores the value of the flag. 146 | func (f *FlagSet) UintSlice(name string, value []uint, usage string) *[]uint { 147 | p := []uint{} 148 | f.UintSliceVarP(&p, name, "", value, usage) 149 | return &p 150 | } 151 | 152 | // UintSliceP is like UintSlice, but accepts a shorthand letter that can be used after a single dash. 153 | func (f *FlagSet) UintSliceP(name, shorthand string, value []uint, usage string) *[]uint { 154 | p := []uint{} 155 | f.UintSliceVarP(&p, name, shorthand, value, usage) 156 | return &p 157 | } 158 | 159 | // UintSlice defines a []uint flag with specified name, default value, and usage string. 160 | // The return value is the address of a []uint variable that stores the value of the flag. 161 | func UintSlice(name string, value []uint, usage string) *[]uint { 162 | return CommandLine.UintSliceP(name, "", value, usage) 163 | } 164 | 165 | // UintSliceP is like UintSlice, but accepts a shorthand letter that can be used after a single dash. 166 | func UintSliceP(name, shorthand string, value []uint, usage string) *[]uint { 167 | return CommandLine.UintSliceP(name, shorthand, value, usage) 168 | } 169 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/AUTHORS: -------------------------------------------------------------------------------- 1 | # This source code refers to The Go Authors for copyright purposes. 2 | # The master list of authors is in the main Go distribution, 3 | # visible at http://tip.golang.org/AUTHORS. 4 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | # This source code was written by the Go contributors. 2 | # The master list of contributors is in the main Go distribution, 3 | # visible at http://tip.golang.org/CONTRIBUTORS. 4 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009 The Go Authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of Google Inc. nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/PATENTS: -------------------------------------------------------------------------------- 1 | Additional IP Rights Grant (Patents) 2 | 3 | "This implementation" means the copyrightable works distributed by 4 | Google as part of the Go project. 5 | 6 | Google hereby grants to You a perpetual, worldwide, non-exclusive, 7 | no-charge, royalty-free, irrevocable (except as stated in this section) 8 | patent license to make, have made, use, offer to sell, sell, import, 9 | transfer and otherwise run, modify and propagate the contents of this 10 | implementation of Go, where such license applies only to those patent 11 | claims, both currently owned or controlled by Google and acquired in 12 | the future, licensable by Google that are necessarily infringed by this 13 | implementation of Go. This grant does not include claims that would be 14 | infringed only as a consequence of further modification of this 15 | implementation. If you or your agent or exclusive licensee institute or 16 | order or agree to the institution of patent litigation against any 17 | entity (including a cross-claim or counterclaim in a lawsuit) alleging 18 | that this implementation of Go or any code incorporated within this 19 | implementation of Go constitutes direct or contributory patent 20 | infringement, or inducement of patent infringement, then any patent 21 | rights granted to you under this License for this implementation of Go 22 | shall terminate as of the date such litigation is filed. 23 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/html/atom/atom.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 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. 4 | 5 | // Package atom provides integer codes (also known as atoms) for a fixed set of 6 | // frequently occurring HTML strings: tag names and attribute keys such as "p" 7 | // and "id". 8 | // 9 | // Sharing an atom's name between all elements with the same tag can result in 10 | // fewer string allocations when tokenizing and parsing HTML. Integer 11 | // comparisons are also generally faster than string comparisons. 12 | // 13 | // The value of an atom's particular code is not guaranteed to stay the same 14 | // between versions of this package. Neither is any ordering guaranteed: 15 | // whether atom.H1 < atom.H2 may also change. The codes are not guaranteed to 16 | // be dense. The only guarantees are that e.g. looking up "div" will yield 17 | // atom.Div, calling atom.Div.String will return "div", and atom.Div != 0. 18 | package atom // import "golang.org/x/net/html/atom" 19 | 20 | // Atom is an integer code for a string. The zero value maps to "". 21 | type Atom uint32 22 | 23 | // String returns the atom's name. 24 | func (a Atom) String() string { 25 | start := uint32(a >> 8) 26 | n := uint32(a & 0xff) 27 | if start+n > uint32(len(atomText)) { 28 | return "" 29 | } 30 | return atomText[start : start+n] 31 | } 32 | 33 | func (a Atom) string() string { 34 | return atomText[a>>8 : a>>8+a&0xff] 35 | } 36 | 37 | // fnv computes the FNV hash with an arbitrary starting value h. 38 | func fnv(h uint32, s []byte) uint32 { 39 | for i := range s { 40 | h ^= uint32(s[i]) 41 | h *= 16777619 42 | } 43 | return h 44 | } 45 | 46 | func match(s string, t []byte) bool { 47 | for i, c := range t { 48 | if s[i] != c { 49 | return false 50 | } 51 | } 52 | return true 53 | } 54 | 55 | // Lookup returns the atom whose name is s. It returns zero if there is no 56 | // such atom. The lookup is case sensitive. 57 | func Lookup(s []byte) Atom { 58 | if len(s) == 0 || len(s) > maxAtomLen { 59 | return 0 60 | } 61 | h := fnv(hash0, s) 62 | if a := table[h&uint32(len(table)-1)]; int(a&0xff) == len(s) && match(a.string(), s) { 63 | return a 64 | } 65 | if a := table[(h>>16)&uint32(len(table)-1)]; int(a&0xff) == len(s) && match(a.string(), s) { 66 | return a 67 | } 68 | return 0 69 | } 70 | 71 | // String returns a string whose contents are equal to s. In that sense, it is 72 | // equivalent to string(s) but may be more efficient. 73 | func String(s []byte) string { 74 | if a := Lookup(s); a != 0 { 75 | return a.String() 76 | } 77 | return string(s) 78 | } 79 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/html/const.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 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. 4 | 5 | package html 6 | 7 | // Section 12.2.4.2 of the HTML5 specification says "The following elements 8 | // have varying levels of special parsing rules". 9 | // https://html.spec.whatwg.org/multipage/syntax.html#the-stack-of-open-elements 10 | var isSpecialElementMap = map[string]bool{ 11 | "address": true, 12 | "applet": true, 13 | "area": true, 14 | "article": true, 15 | "aside": true, 16 | "base": true, 17 | "basefont": true, 18 | "bgsound": true, 19 | "blockquote": true, 20 | "body": true, 21 | "br": true, 22 | "button": true, 23 | "caption": true, 24 | "center": true, 25 | "col": true, 26 | "colgroup": true, 27 | "dd": true, 28 | "details": true, 29 | "dir": true, 30 | "div": true, 31 | "dl": true, 32 | "dt": true, 33 | "embed": true, 34 | "fieldset": true, 35 | "figcaption": true, 36 | "figure": true, 37 | "footer": true, 38 | "form": true, 39 | "frame": true, 40 | "frameset": true, 41 | "h1": true, 42 | "h2": true, 43 | "h3": true, 44 | "h4": true, 45 | "h5": true, 46 | "h6": true, 47 | "head": true, 48 | "header": true, 49 | "hgroup": true, 50 | "hr": true, 51 | "html": true, 52 | "iframe": true, 53 | "img": true, 54 | "input": true, 55 | "keygen": true, // "keygen" has been removed from the spec, but are kept here for backwards compatibility. 56 | "li": true, 57 | "link": true, 58 | "listing": true, 59 | "main": true, 60 | "marquee": true, 61 | "menu": true, 62 | "meta": true, 63 | "nav": true, 64 | "noembed": true, 65 | "noframes": true, 66 | "noscript": true, 67 | "object": true, 68 | "ol": true, 69 | "p": true, 70 | "param": true, 71 | "plaintext": true, 72 | "pre": true, 73 | "script": true, 74 | "section": true, 75 | "select": true, 76 | "source": true, 77 | "style": true, 78 | "summary": true, 79 | "table": true, 80 | "tbody": true, 81 | "td": true, 82 | "template": true, 83 | "textarea": true, 84 | "tfoot": true, 85 | "th": true, 86 | "thead": true, 87 | "title": true, 88 | "tr": true, 89 | "track": true, 90 | "ul": true, 91 | "wbr": true, 92 | "xmp": true, 93 | } 94 | 95 | func isSpecialElement(element *Node) bool { 96 | switch element.Namespace { 97 | case "", "html": 98 | return isSpecialElementMap[element.Data] 99 | case "math": 100 | switch element.Data { 101 | case "mi", "mo", "mn", "ms", "mtext", "annotation-xml": 102 | return true 103 | } 104 | case "svg": 105 | switch element.Data { 106 | case "foreignObject", "desc", "title": 107 | return true 108 | } 109 | } 110 | return false 111 | } 112 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/html/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2010 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. 4 | 5 | /* 6 | Package html implements an HTML5-compliant tokenizer and parser. 7 | 8 | Tokenization is done by creating a Tokenizer for an io.Reader r. It is the 9 | caller's responsibility to ensure that r provides UTF-8 encoded HTML. 10 | 11 | z := html.NewTokenizer(r) 12 | 13 | Given a Tokenizer z, the HTML is tokenized by repeatedly calling z.Next(), 14 | which parses the next token and returns its type, or an error: 15 | 16 | for { 17 | tt := z.Next() 18 | if tt == html.ErrorToken { 19 | // ... 20 | return ... 21 | } 22 | // Process the current token. 23 | } 24 | 25 | There are two APIs for retrieving the current token. The high-level API is to 26 | call Token; the low-level API is to call Text or TagName / TagAttr. Both APIs 27 | allow optionally calling Raw after Next but before Token, Text, TagName, or 28 | TagAttr. In EBNF notation, the valid call sequence per token is: 29 | 30 | Next {Raw} [ Token | Text | TagName {TagAttr} ] 31 | 32 | Token returns an independent data structure that completely describes a token. 33 | Entities (such as "<") are unescaped, tag names and attribute keys are 34 | lower-cased, and attributes are collected into a []Attribute. For example: 35 | 36 | for { 37 | if z.Next() == html.ErrorToken { 38 | // Returning io.EOF indicates success. 39 | return z.Err() 40 | } 41 | emitToken(z.Token()) 42 | } 43 | 44 | The low-level API performs fewer allocations and copies, but the contents of 45 | the []byte values returned by Text, TagName and TagAttr may change on the next 46 | call to Next. For example, to extract an HTML page's anchor text: 47 | 48 | depth := 0 49 | for { 50 | tt := z.Next() 51 | switch tt { 52 | case html.ErrorToken: 53 | return z.Err() 54 | case html.TextToken: 55 | if depth > 0 { 56 | // emitBytes should copy the []byte it receives, 57 | // if it doesn't process it immediately. 58 | emitBytes(z.Text()) 59 | } 60 | case html.StartTagToken, html.EndTagToken: 61 | tn, _ := z.TagName() 62 | if len(tn) == 1 && tn[0] == 'a' { 63 | if tt == html.StartTagToken { 64 | depth++ 65 | } else { 66 | depth-- 67 | } 68 | } 69 | } 70 | } 71 | 72 | Parsing is done by calling Parse with an io.Reader, which returns the root of 73 | the parse tree (the document element) as a *Node. It is the caller's 74 | responsibility to ensure that the Reader provides UTF-8 encoded HTML. For 75 | example, to process each anchor node in depth-first order: 76 | 77 | doc, err := html.Parse(r) 78 | if err != nil { 79 | // ... 80 | } 81 | var f func(*html.Node) 82 | f = func(n *html.Node) { 83 | if n.Type == html.ElementNode && n.Data == "a" { 84 | // Do something with n... 85 | } 86 | for c := n.FirstChild; c != nil; c = c.NextSibling { 87 | f(c) 88 | } 89 | } 90 | f(doc) 91 | 92 | The relevant specifications include: 93 | https://html.spec.whatwg.org/multipage/syntax.html and 94 | https://html.spec.whatwg.org/multipage/syntax.html#tokenization 95 | */ 96 | package html // import "golang.org/x/net/html" 97 | 98 | // The tokenization algorithm implemented by this package is not a line-by-line 99 | // transliteration of the relatively verbose state-machine in the WHATWG 100 | // specification. A more direct approach is used instead, where the program 101 | // counter implies the state, such as whether it is tokenizing a tag or a text 102 | // node. Specification compliance is verified by checking expected and actual 103 | // outputs over a test suite rather than aiming for algorithmic fidelity. 104 | 105 | // TODO(nigeltao): Does a DOM API belong in this package or a separate one? 106 | // TODO(nigeltao): How does parsing interact with a JavaScript engine? 107 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/html/doctype.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 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. 4 | 5 | package html 6 | 7 | import ( 8 | "strings" 9 | ) 10 | 11 | // parseDoctype parses the data from a DoctypeToken into a name, 12 | // public identifier, and system identifier. It returns a Node whose Type 13 | // is DoctypeNode, whose Data is the name, and which has attributes 14 | // named "system" and "public" for the two identifiers if they were present. 15 | // quirks is whether the document should be parsed in "quirks mode". 16 | func parseDoctype(s string) (n *Node, quirks bool) { 17 | n = &Node{Type: DoctypeNode} 18 | 19 | // Find the name. 20 | space := strings.IndexAny(s, whitespace) 21 | if space == -1 { 22 | space = len(s) 23 | } 24 | n.Data = s[:space] 25 | // The comparison to "html" is case-sensitive. 26 | if n.Data != "html" { 27 | quirks = true 28 | } 29 | n.Data = strings.ToLower(n.Data) 30 | s = strings.TrimLeft(s[space:], whitespace) 31 | 32 | if len(s) < 6 { 33 | // It can't start with "PUBLIC" or "SYSTEM". 34 | // Ignore the rest of the string. 35 | return n, quirks || s != "" 36 | } 37 | 38 | key := strings.ToLower(s[:6]) 39 | s = s[6:] 40 | for key == "public" || key == "system" { 41 | s = strings.TrimLeft(s, whitespace) 42 | if s == "" { 43 | break 44 | } 45 | quote := s[0] 46 | if quote != '"' && quote != '\'' { 47 | break 48 | } 49 | s = s[1:] 50 | q := strings.IndexRune(s, rune(quote)) 51 | var id string 52 | if q == -1 { 53 | id = s 54 | s = "" 55 | } else { 56 | id = s[:q] 57 | s = s[q+1:] 58 | } 59 | n.Attr = append(n.Attr, Attribute{Key: key, Val: id}) 60 | if key == "public" { 61 | key = "system" 62 | } else { 63 | key = "" 64 | } 65 | } 66 | 67 | if key != "" || s != "" { 68 | quirks = true 69 | } else if len(n.Attr) > 0 { 70 | if n.Attr[0].Key == "public" { 71 | public := strings.ToLower(n.Attr[0].Val) 72 | switch public { 73 | case "-//w3o//dtd w3 html strict 3.0//en//", "-/w3d/dtd html 4.0 transitional/en", "html": 74 | quirks = true 75 | default: 76 | for _, q := range quirkyIDs { 77 | if strings.HasPrefix(public, q) { 78 | quirks = true 79 | break 80 | } 81 | } 82 | } 83 | // The following two public IDs only cause quirks mode if there is no system ID. 84 | if len(n.Attr) == 1 && (strings.HasPrefix(public, "-//w3c//dtd html 4.01 frameset//") || 85 | strings.HasPrefix(public, "-//w3c//dtd html 4.01 transitional//")) { 86 | quirks = true 87 | } 88 | } 89 | if lastAttr := n.Attr[len(n.Attr)-1]; lastAttr.Key == "system" && 90 | strings.ToLower(lastAttr.Val) == "http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd" { 91 | quirks = true 92 | } 93 | } 94 | 95 | return n, quirks 96 | } 97 | 98 | // quirkyIDs is a list of public doctype identifiers that cause a document 99 | // to be interpreted in quirks mode. The identifiers should be in lower case. 100 | var quirkyIDs = []string{ 101 | "+//silmaril//dtd html pro v0r11 19970101//", 102 | "-//advasoft ltd//dtd html 3.0 aswedit + extensions//", 103 | "-//as//dtd html 3.0 aswedit + extensions//", 104 | "-//ietf//dtd html 2.0 level 1//", 105 | "-//ietf//dtd html 2.0 level 2//", 106 | "-//ietf//dtd html 2.0 strict level 1//", 107 | "-//ietf//dtd html 2.0 strict level 2//", 108 | "-//ietf//dtd html 2.0 strict//", 109 | "-//ietf//dtd html 2.0//", 110 | "-//ietf//dtd html 2.1e//", 111 | "-//ietf//dtd html 3.0//", 112 | "-//ietf//dtd html 3.2 final//", 113 | "-//ietf//dtd html 3.2//", 114 | "-//ietf//dtd html 3//", 115 | "-//ietf//dtd html level 0//", 116 | "-//ietf//dtd html level 1//", 117 | "-//ietf//dtd html level 2//", 118 | "-//ietf//dtd html level 3//", 119 | "-//ietf//dtd html strict level 0//", 120 | "-//ietf//dtd html strict level 1//", 121 | "-//ietf//dtd html strict level 2//", 122 | "-//ietf//dtd html strict level 3//", 123 | "-//ietf//dtd html strict//", 124 | "-//ietf//dtd html//", 125 | "-//metrius//dtd metrius presentational//", 126 | "-//microsoft//dtd internet explorer 2.0 html strict//", 127 | "-//microsoft//dtd internet explorer 2.0 html//", 128 | "-//microsoft//dtd internet explorer 2.0 tables//", 129 | "-//microsoft//dtd internet explorer 3.0 html strict//", 130 | "-//microsoft//dtd internet explorer 3.0 html//", 131 | "-//microsoft//dtd internet explorer 3.0 tables//", 132 | "-//netscape comm. corp.//dtd html//", 133 | "-//netscape comm. corp.//dtd strict html//", 134 | "-//o'reilly and associates//dtd html 2.0//", 135 | "-//o'reilly and associates//dtd html extended 1.0//", 136 | "-//o'reilly and associates//dtd html extended relaxed 1.0//", 137 | "-//softquad software//dtd hotmetal pro 6.0::19990601::extensions to html 4.0//", 138 | "-//softquad//dtd hotmetal pro 4.0::19971010::extensions to html 4.0//", 139 | "-//spyglass//dtd html 2.0 extended//", 140 | "-//sq//dtd html 2.0 hotmetal + extensions//", 141 | "-//sun microsystems corp.//dtd hotjava html//", 142 | "-//sun microsystems corp.//dtd hotjava strict html//", 143 | "-//w3c//dtd html 3 1995-03-24//", 144 | "-//w3c//dtd html 3.2 draft//", 145 | "-//w3c//dtd html 3.2 final//", 146 | "-//w3c//dtd html 3.2//", 147 | "-//w3c//dtd html 3.2s draft//", 148 | "-//w3c//dtd html 4.0 frameset//", 149 | "-//w3c//dtd html 4.0 transitional//", 150 | "-//w3c//dtd html experimental 19960712//", 151 | "-//w3c//dtd html experimental 970421//", 152 | "-//w3c//dtd w3 html//", 153 | "-//w3o//dtd w3 html 3.0//", 154 | "-//webtechs//dtd mozilla html 2.0//", 155 | "-//webtechs//dtd mozilla html//", 156 | } 157 | -------------------------------------------------------------------------------- /vendor/modules.txt: -------------------------------------------------------------------------------- 1 | # github.com/PuerkitoBio/goquery v1.6.0 2 | ## explicit 3 | github.com/PuerkitoBio/goquery 4 | # github.com/andybalholm/cascadia v1.2.0 5 | ## explicit 6 | github.com/andybalholm/cascadia 7 | # github.com/inconshreveable/mousetrap v1.0.0 8 | github.com/inconshreveable/mousetrap 9 | # github.com/spf13/cobra v1.1.1 10 | ## explicit 11 | github.com/spf13/cobra 12 | # github.com/spf13/pflag v1.0.5 13 | github.com/spf13/pflag 14 | # golang.org/x/net v0.0.0-20201031054903-ff519b6c9102 15 | ## explicit 16 | golang.org/x/net/html 17 | golang.org/x/net/html/atom 18 | --------------------------------------------------------------------------------