-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
helpers.go
68 lines (59 loc) · 1.58 KB
/
helpers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// SPDX-License-Identifier: Apache-2.0
// Copyright 2021 The Kubernetes Authors
package env
import (
"fmt"
"sigs.k8s.io/controller-runtime/tools/setup-envtest/versions"
)
// orderPlatforms orders platforms by OS then arch.
func orderPlatforms(first, second versions.Platform) bool {
// sort by OS, then arch
if first.OS != second.OS {
return first.OS < second.OS
}
return first.Arch < second.Arch
}
// PrintFormat indicates how to print out fetch and switch results.
// It's a valid pflag.Value so it can be used as a flag directly.
type PrintFormat int
const (
// PrintOverview prints human-readable data,
// including path, version, arch, and checksum (when available).
PrintOverview PrintFormat = iota
// PrintPath prints *only* the path, with no decoration.
PrintPath
// PrintEnv prints the path with the corresponding env variable, so that
// you can source the output like
// `source $(fetch-envtest switch -p env 1.20.x)`.
PrintEnv
)
func (f PrintFormat) String() string {
switch f {
case PrintOverview:
return "overview"
case PrintPath:
return "path"
case PrintEnv:
return "env"
default:
panic(fmt.Sprintf("unexpected print format %d", int(f)))
}
}
// Set sets the value of this as a flag.
func (f *PrintFormat) Set(val string) error {
switch val {
case "overview":
*f = PrintOverview
case "path":
*f = PrintPath
case "env":
*f = PrintEnv
default:
return fmt.Errorf("unknown print format %q, use one of overview|path|env", val)
}
return nil
}
// Type is the type of this value as a flag.
func (PrintFormat) Type() string {
return "{overview|path|env}"
}