Skip to content

Commit 0f823e6

Browse files
committed
[no-relnote] Set Before and Action in declaration
Signed-off-by: Evan Lezar <elezar@nvidia.com>
1 parent 907e6bf commit 0f823e6

File tree

2 files changed

+35
-37
lines changed

2 files changed

+35
-37
lines changed

cmd/nvidia-cdi-hook/main.go

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,29 @@ func main() {
5151
Version: info.GetVersionString(),
5252
// Define the subcommands
5353
Commands: commands.New(logger),
54-
}
55-
// We set the default action for the `nvidia-cdi-hook` command to issue a
56-
// warning and exit with no error.
57-
// This means that if an unsupported hook is run, a container will not fail
58-
// to launch. An unsupported hook could be the result of a CDI specification
59-
// referring to a new hook that is not yet supported by an older NVIDIA
60-
// Container Toolkit version or a hook that has been removed in newer
61-
// version.
62-
c.Action = func(ctx context.Context, cmd *cli.Command) error {
63-
commands.IssueUnsupportedHookWarning(logger, cmd)
64-
return nil
54+
// Set log-level for all subcommands
55+
Before: func(ctx context.Context, cmd *cli.Command) (context.Context, error) {
56+
logLevel := logrus.InfoLevel
57+
if opts.Debug {
58+
logLevel = logrus.DebugLevel
59+
}
60+
if opts.Quiet {
61+
logLevel = logrus.ErrorLevel
62+
}
63+
logger.SetLevel(logLevel)
64+
return ctx, nil
65+
},
66+
// We set the default action for the `nvidia-cdi-hook` command to issue a
67+
// warning and exit with no error.
68+
// This means that if an unsupported hook is run, a container will not fail
69+
// to launch. An unsupported hook could be the result of a CDI specification
70+
// referring to a new hook that is not yet supported by an older NVIDIA
71+
// Container Toolkit version or a hook that has been removed in newer
72+
// version.
73+
Action: func(ctx context.Context, cmd *cli.Command) error {
74+
commands.IssueUnsupportedHookWarning(logger, cmd)
75+
return nil
76+
},
6577
}
6678

6779
// Setup the flags for this command
@@ -83,19 +95,6 @@ func main() {
8395
},
8496
}
8597

86-
// Set log-level for all subcommands
87-
c.Before = func(ctx context.Context, cmd *cli.Command) (context.Context, error) {
88-
logLevel := logrus.InfoLevel
89-
if opts.Debug {
90-
logLevel = logrus.DebugLevel
91-
}
92-
if opts.Quiet {
93-
logLevel = logrus.ErrorLevel
94-
}
95-
logger.SetLevel(logLevel)
96-
return ctx, nil
97-
}
98-
9998
// Run the CLI
10099
err := c.Run(context.Background(), os.Args)
101100
if err != nil {

cmd/nvidia-ctk/main.go

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,18 @@ func main() {
5656
EnableShellCompletion: true,
5757
Usage: "Tools to configure the NVIDIA Container Toolkit",
5858
Version: info.GetVersionString(),
59+
// Set log-level for all subcommands
60+
Before: func(ctx context.Context, cmd *cli.Command) (context.Context, error) {
61+
logLevel := logrus.InfoLevel
62+
if opts.Debug {
63+
logLevel = logrus.DebugLevel
64+
}
65+
if opts.Quiet {
66+
logLevel = logrus.ErrorLevel
67+
}
68+
logger.SetLevel(logLevel)
69+
return ctx, nil
70+
},
5971
}
6072

6173
// Setup the flags for this command
@@ -75,19 +87,6 @@ func main() {
7587
},
7688
}
7789

78-
// Set log-level for all subcommands
79-
c.Before = func(ctx context.Context, cmd *cli.Command) (context.Context, error) {
80-
logLevel := logrus.InfoLevel
81-
if opts.Debug {
82-
logLevel = logrus.DebugLevel
83-
}
84-
if opts.Quiet {
85-
logLevel = logrus.ErrorLevel
86-
}
87-
logger.SetLevel(logLevel)
88-
return ctx, nil
89-
}
90-
9190
// Define the subcommands
9291
c.Commands = []*cli.Command{
9392
hook.NewCommand(logger),

0 commit comments

Comments
 (0)