@@ -44,54 +44,41 @@ 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 {
47+ c := & cli.Command {
4948 Name : "NVIDIA CDI Hook" ,
5049 Usage : "Command to structure files for usage inside a container, called as hooks from a container runtime, defined in a CDI yaml file" ,
5150 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
51+ }
52+ // Set log-level for all subcommands
53+ c .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+ c .Flags = []cli.Flag {
65+ & cli.BoolFlag {
66+ Name : "debug" ,
67+ Aliases : []string {"d" },
68+ Usage : "Enable debug-level logging" ,
69+ Destination : & opts .Debug ,
70+ // TODO: Support for NVIDIA_CDI_DEBUG is deprecated and NVIDIA_CTK_DEBUG should be used instead.
71+ Sources : cli .EnvVars ("NVIDIA_CTK_DEBUG" , "NVIDIA_CDI_DEBUG" ),
7472 },
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- },
73+ & cli.BoolFlag {
74+ Name : "quiet" ,
75+ Usage : "Suppress all output except for errors; overrides --debug" ,
76+ Destination : & opts .Quiet ,
77+ // TODO: Support for NVIDIA_CDI_QUIET is deprecated and NVIDIA_CTK_QUIET should be used instead.
78+ Sources : cli .EnvVars ("NVIDIA_CTK_QUIET" , "NVIDIA_CDI_QUIET" ),
9379 },
9480 }
81+ c = commands .ConfigureCDIHookCommand (c , logger )
9582
9683 // Run the CLI
9784 err := c .Run (context .Background (), os .Args )
0 commit comments