| 1 | // Copyright 2013 Google Inc. 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 getoptscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/ |
| 6 | |
| 7 | import ( |
| 8 | "bytesscip-go gomod github.com/golang/go/src go1.13 bytes/" |
| 9 | "fmtscip-go gomod github.com/golang/go/src go1.13 fmt/" |
| 10 | "pathscip-go gomod github.com/golang/go/src go1.13 path/" |
| 11 | "reflectscip-go gomod github.com/golang/go/src go1.13 reflect/" |
| 12 | "runtimescip-go gomod github.com/golang/go/src go1.13 runtime/" |
| 13 | "stringsscip-go gomod github.com/golang/go/src go1.13 strings/" |
| 14 | ) |
| 15 | |
| 16 | var errorStringscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/errorString. string |
| 17 | |
| 18 | func resetscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/reset().() { |
| 19 | CommandLinescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/CommandLine..shortOptionsscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#shortOptions. = make(map[rune]*optionscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/option#) |
| 20 | CommandLinescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/CommandLine..longOptionsscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#longOptions. = make(map[string]*optionscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/option#) |
| 21 | CommandLinescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/CommandLine..optionsscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#options. = nil |
| 22 | CommandLinescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/CommandLine..argsscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#args. = nil |
| 23 | CommandLinescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/CommandLine..programscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#program. = "" |
| 24 | errorStringscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/errorString. = "" |
| 25 | } |
| 26 | |
| 27 | func parsescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/parse().(args []string) { |
| 28 | err := CommandLinescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/CommandLine..Getoptscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#Getopt().(args, nil) |
| 29 | if err != nil { |
| 30 | b := &bytesscip-go gomod github.com/golang/go/src go1.13 bytes/.Bufferscip-go gomod github.com/golang/go/src go1.13 bytes/Buffer#{} |
| 31 | |
| 32 | fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Fprintlnscip-go gomod github.com/golang/go/src go1.13 fmt/Fprintln().(b, CommandLinescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/CommandLine..programscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#program.+": "+err.Error()) |
| 33 | CommandLinescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/CommandLine..PrintUsagescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#PrintUsage().(b) |
| 34 | errorStringscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/errorString. = b.Stringscip-go gomod github.com/golang/go/src go1.13 bytes/Buffer#String().() |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | func badSlicescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/badSlice().(a, b []string) bool { |
| 39 | if len(a) != len(b) { |
| 40 | return true |
| 41 | } |
| 42 | for x, v := range a { |
| 43 | if b[x] != v { |
| 44 | return true |
| 45 | } |
| 46 | } |
| 47 | return false |
| 48 | } |
| 49 | |
| 50 | func locscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/loc().() string { |
| 51 | _, file, line, _ := runtimescip-go gomod github.com/golang/go/src go1.13 runtime/.Callerscip-go gomod github.com/golang/go/src go1.13 runtime/Caller().(1) |
| 52 | return fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.13 fmt/Sprintf().("%s:%d", pathscip-go gomod github.com/golang/go/src go1.13 path/.Basescip-go gomod github.com/golang/go/src go1.13 path/Base().(file), line) |
| 53 | } |
| 54 | |
| 55 | func (o *optionscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/option#) Equalscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/option#Equal().(opt *optionscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/option#) bool { |
| 56 | if o.valuescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/option#value. != nil && opt.valuescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/option#value. == nil { |
| 57 | return false |
| 58 | } |
| 59 | if o.valuescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/option#value. == nil && opt.valuescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/option#value. != nil { |
| 60 | return false |
| 61 | } |
| 62 | if o.valuescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/option#value. != nil && o.valuescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/option#value..Stringscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Value#String.() != opt.valuescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/option#value..Stringscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Value#String.() { |
| 63 | return false |
| 64 | } |
| 65 | |
| 66 | oc := *o |
| 67 | optc := *opt |
| 68 | oc.valuescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/option#value. = nil |
| 69 | optc.valuescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/option#value. = nil |
| 70 | return reflectscip-go gomod github.com/golang/go/src go1.13 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.13 reflect/DeepEqual().(&oc, &optc) |
| 71 | } |
| 72 | |
| 73 | func newStringValuescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/newStringValue().(s string) *stringValuescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/stringValue# { return (*stringValuescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/stringValue#)(&s) } |
| 74 | |
| 75 | func checkErrorscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/checkError().(err string) string { |
| 76 | switch { |
| 77 | case err == errorStringscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/errorString.: |
| 78 | return "" |
| 79 | case err == "": |
| 80 | return fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.13 fmt/Sprintf().("unexpected error %q", errorStringscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/errorString.) |
| 81 | case errorStringscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/errorString. == "": |
| 82 | return fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.13 fmt/Sprintf().("did not get expected error %q", err) |
| 83 | case !stringsscip-go gomod github.com/golang/go/src go1.13 strings/.HasPrefixscip-go gomod github.com/golang/go/src go1.13 strings/HasPrefix().(errorStringscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/errorString., err): |
| 84 | return fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.13 fmt/Sprintf().("got error %q, want %q", errorStringscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/errorString., err) |
| 85 | } |
| 86 | return "" |
| 87 | } |