@@ -44,52 +44,37 @@ func main() {
4444 // Create a options struct to hold the parsed environment variables or command line flags
4545 opts := options {}
4646
47- // Create the top-level CLI
48- c := cli.Command {
49- Name : "NVIDIA CDI Hook" ,
50- Usage : "Command to structure files for usage inside a container, called as hooks from a container runtime, defined in a CDI yaml file" ,
51- Version : info .GetVersionString (),
52- // Set log-level for all subcommands
53- Before : func (ctx context.Context , cmd * cli.Command ) (context.Context , error ) {
54- logLevel := logrus .InfoLevel
55- if opts .Debug {
56- logLevel = logrus .DebugLevel
57- }
58- if opts .Quiet {
59- logLevel = logrus .ErrorLevel
60- }
61- logger .SetLevel (logLevel )
62- return ctx , nil
63- },
64- // We set the default action for the `nvidia-cdi-hook` command to issue a
65- // warning and exit with no error.
66- // This means that if an unsupported hook is run, a container will not fail
67- // to launch. An unsupported hook could be the result of a CDI specification
68- // referring to a new hook that is not yet supported by an older NVIDIA
69- // Container Toolkit version or a hook that has been removed in newer
70- // version.
71- Action : func (ctx context.Context , cmd * cli.Command ) error {
72- commands .IssueUnsupportedHookWarning (logger , cmd )
73- return nil
47+ c := commands .NewHookCommand (logger )
48+ c .Name = "NVIDIA CDI Hook"
49+ c .Usage = "Command to structure files for usage inside a container, called as hooks from a container runtime, defined in a CDI yaml file"
50+ c .Version = info .GetVersionString ()
51+ // Set log-level for all subcommands
52+ c .Before = func (ctx context.Context , cmd * cli.Command ) (context.Context , error ) {
53+ logLevel := logrus .InfoLevel
54+ if opts .Debug {
55+ logLevel = logrus .DebugLevel
56+ }
57+ if opts .Quiet {
58+ logLevel = logrus .ErrorLevel
59+ }
60+ logger .SetLevel (logLevel )
61+ return ctx , nil
62+ }
63+ c .Flags = []cli.Flag {
64+ & cli.BoolFlag {
65+ Name : "debug" ,
66+ Aliases : []string {"d" },
67+ Usage : "Enable debug-level logging" ,
68+ Destination : & opts .Debug ,
69+ // TODO: Support for NVIDIA_CDI_DEBUG is deprecated and NVIDIA_CTK_DEBUG should be used instead.
70+ Sources : cli .EnvVars ("NVIDIA_CTK_DEBUG" , "NVIDIA_CDI_DEBUG" ),
7471 },
75- // Define the subcommands
76- Commands : commands .New (logger ),
77- Flags : []cli.Flag {
78- & cli.BoolFlag {
79- Name : "debug" ,
80- Aliases : []string {"d" },
81- Usage : "Enable debug-level logging" ,
82- Destination : & opts .Debug ,
83- // TODO: Support for NVIDIA_CDI_DEBUG is deprecated and NVIDIA_CTK_DEBUG should be used instead.
84- Sources : cli .EnvVars ("NVIDIA_CTK_DEBUG" , "NVIDIA_CDI_DEBUG" ),
85- },
86- & cli.BoolFlag {
87- Name : "quiet" ,
88- Usage : "Suppress all output except for errors; overrides --debug" ,
89- Destination : & opts .Quiet ,
90- // TODO: Support for NVIDIA_CDI_QUIET is deprecated and NVIDIA_CTK_QUIET should be used instead.
91- Sources : cli .EnvVars ("NVIDIA_CTK_QUIET" , "NVIDIA_CDI_QUIET" ),
92- },
72+ & cli.BoolFlag {
73+ Name : "quiet" ,
74+ Usage : "Suppress all output except for errors; overrides --debug" ,
75+ Destination : & opts .Quiet ,
76+ // TODO: Support for NVIDIA_CDI_QUIET is deprecated and NVIDIA_CTK_QUIET should be used instead.
77+ Sources : cli .EnvVars ("NVIDIA_CTK_QUIET" , "NVIDIA_CDI_QUIET" ),
9378 },
9479 }
9580
0 commit comments