MCPcopy Create free account
hub / github.com/BernardoGiordano/Checkpoint / parseOnePositional

Function parseOnePositional

tools/chlink/common.go:32–50  ·  view source on GitHub ↗

parseOnePositional parses fs while allowing the single positional argument to come before the flags (Go's flag package stops parsing at the first non-flag argument, but the documented syntax is "chlink send --to ...").

(fs *flag.FlagSet, args []string, what string)

Source from the content-addressed store, hash-verified

30// to come before the flags (Go's flag package stops parsing at the first
31// non-flag argument, but the documented syntax is "chlink send <path> --to ...").
32func parseOnePositional(fs *flag.FlagSet, args []string, what string) (string, error) {
33 if len(args) > 0 && !strings.HasPrefix(args[0], "-") {
34 if err := fs.Parse(args[1:]); err != nil {
35 return "", err
36 }
37 if fs.NArg() != 0 {
38 return "", fmt.Errorf("unexpected extra arguments: %v", fs.Args())
39 }
40 return args[0], nil
41 }
42 if err := fs.Parse(args); err != nil {
43 return "", err
44 }
45 if fs.NArg() != 1 {
46 fs.Usage()
47 return "", fmt.Errorf("expected exactly one %s", what)
48 }
49 return fs.Arg(0), nil
50}
51
52// resolveTarget turns "ip" or "ip:port" into "host:port", defaulting the port.
53func resolveTarget(to string, defaultPort int) (string, error) {

Callers 3

cmdZipFunction · 0.85
cmdUnzipFunction · 0.85
cmdSendFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected