From 7f4b520a5978a962c098b659d528c5e689b8931d Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Sat, 26 Oct 2024 21:10:14 +0200 Subject: [PATCH] [no-relnote] Merge verifyFlags and validateFlags Signed-off-by: Evan Lezar --- tools/container/nvidia-toolkit/run.go | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/tools/container/nvidia-toolkit/run.go b/tools/container/nvidia-toolkit/run.go index 842d7099..abc0a2cd 100644 --- a/tools/container/nvidia-toolkit/run.go +++ b/tools/container/nvidia-toolkit/run.go @@ -130,6 +130,12 @@ func main() { } func validateFlags(_ *cli.Context, o *options) error { + if o.root == "" { + return fmt.Errorf("the install root must be specified") + } + if _, exists := availableRuntimes[o.runtime]; !exists { + return fmt.Errorf("unknown runtime: %v", o.runtime) + } if filepath.Base(o.pidFile) != toolkitPidFilename { return fmt.Errorf("invalid toolkit.pid path %v", o.pidFile) } @@ -144,12 +150,7 @@ func validateFlags(_ *cli.Context, o *options) error { // Run runs the core logic of the CLI func Run(c *cli.Context, o *options) error { - err := verifyFlags(o) - if err != nil { - return fmt.Errorf("unable to verify flags: %v", err) - } - - err = initialize(o.pidFile) + err := initialize(o.pidFile) if err != nil { return fmt.Errorf("unable to initialize: %v", err) } @@ -217,18 +218,6 @@ func ParseArgs(args []string) ([]string, string, error) { return nil, "", fmt.Errorf("unexpected positional argument(s) %v", args[2:lastPositionalArg+1]) } -func verifyFlags(o *options) error { - log.Infof("Verifying Flags") - if o.root == "" { - return fmt.Errorf("the install root must be specified") - } - - if _, exists := availableRuntimes[o.runtime]; !exists { - return fmt.Errorf("unknown runtime: %v", o.runtime) - } - return nil -} - func initialize(pidFile string) error { log.Infof("Initializing")