2020-08-30 03:30:07 +00:00
|
|
|
package configfilearg
|
|
|
|
|
|
|
|
import (
|
2022-03-02 23:47:27 +00:00
|
|
|
"github.com/k3s-io/k3s/pkg/cli/cmds"
|
|
|
|
"github.com/k3s-io/k3s/pkg/version"
|
2020-08-30 03:30:07 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
2021-11-12 00:01:23 +00:00
|
|
|
"github.com/urfave/cli"
|
2020-08-30 03:30:07 +00:00
|
|
|
)
|
|
|
|
|
2021-12-01 20:06:51 +00:00
|
|
|
var DefaultParser = &Parser{
|
2021-11-12 00:01:23 +00:00
|
|
|
After: []string{"server", "agent", "etcd-snapshot:1"},
|
2023-06-07 22:57:52 +00:00
|
|
|
ConfigFlags: []string{"--config", "-c"},
|
2021-11-12 00:01:23 +00:00
|
|
|
EnvName: version.ProgramUpper + "_CONFIG_FILE",
|
|
|
|
DefaultConfig: "/etc/rancher/" + version.Program + "/config.yaml",
|
|
|
|
ValidFlags: map[string][]cli.Flag{"server": cmds.ServerFlags, "etcd-snapshot": cmds.EtcdSnapshotFlags},
|
|
|
|
}
|
|
|
|
|
2020-08-30 03:30:07 +00:00
|
|
|
func MustParse(args []string) []string {
|
2021-12-01 20:06:51 +00:00
|
|
|
result, err := DefaultParser.Parse(args)
|
2020-08-30 03:30:07 +00:00
|
|
|
if err != nil {
|
|
|
|
logrus.Fatal(err)
|
|
|
|
}
|
|
|
|
return result
|
|
|
|
}
|
2020-12-16 17:27:57 +00:00
|
|
|
|
|
|
|
func MustFindString(args []string, target string) string {
|
|
|
|
parser := &Parser{
|
2023-06-07 22:57:52 +00:00
|
|
|
OverrideFlags: []string{"--help", "-h", "--version", "-v"},
|
2020-12-16 17:27:57 +00:00
|
|
|
EnvName: version.ProgramUpper + "_CONFIG_FILE",
|
|
|
|
DefaultConfig: "/etc/rancher/" + version.Program + "/config.yaml",
|
|
|
|
}
|
|
|
|
result, err := parser.FindString(args, target)
|
|
|
|
if err != nil {
|
|
|
|
logrus.Fatal(err)
|
|
|
|
}
|
|
|
|
return result
|
|
|
|
}
|