2022-01-13 12:29:00 +00:00
|
|
|
/**
|
|
|
|
# Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved.
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
**/
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
|
2022-11-01 19:05:23 +00:00
|
|
|
"github.com/NVIDIA/nvidia-container-toolkit/cmd/nvidia-ctk/cdi"
|
2023-03-13 12:33:10 +00:00
|
|
|
"github.com/NVIDIA/nvidia-container-toolkit/cmd/nvidia-ctk/config"
|
2022-03-14 11:53:22 +00:00
|
|
|
"github.com/NVIDIA/nvidia-container-toolkit/cmd/nvidia-ctk/hook"
|
2022-06-20 11:53:16 +00:00
|
|
|
infoCLI "github.com/NVIDIA/nvidia-container-toolkit/cmd/nvidia-ctk/info"
|
2022-01-14 13:57:51 +00:00
|
|
|
"github.com/NVIDIA/nvidia-container-toolkit/cmd/nvidia-ctk/runtime"
|
2023-01-27 10:38:36 +00:00
|
|
|
"github.com/NVIDIA/nvidia-container-toolkit/cmd/nvidia-ctk/system"
|
2022-05-12 12:02:06 +00:00
|
|
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/info"
|
2023-03-22 12:27:43 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
2022-06-20 11:53:16 +00:00
|
|
|
|
2022-01-13 12:29:00 +00:00
|
|
|
cli "github.com/urfave/cli/v2"
|
|
|
|
)
|
|
|
|
|
2023-03-13 12:31:58 +00:00
|
|
|
// options defines the options that can be set for the CLI through config files,
|
2022-01-13 12:29:00 +00:00
|
|
|
// environment variables, or command line flags
|
2023-03-13 12:31:58 +00:00
|
|
|
type options struct {
|
2022-01-13 12:29:00 +00:00
|
|
|
// Debug indicates whether the CLI is started in "debug" mode
|
|
|
|
Debug bool
|
2023-06-30 13:55:13 +00:00
|
|
|
// Quiet indicates whether the CLI is started in "quiet" mode
|
|
|
|
Quiet bool
|
2022-01-13 12:29:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
2023-03-22 12:27:43 +00:00
|
|
|
logger := logrus.New()
|
|
|
|
|
2023-03-13 12:31:58 +00:00
|
|
|
// Create a options struct to hold the parsed environment variables or command line flags
|
|
|
|
opts := options{}
|
2022-01-13 12:29:00 +00:00
|
|
|
|
|
|
|
// Create the top-level CLI
|
|
|
|
c := cli.NewApp()
|
2022-05-12 12:02:06 +00:00
|
|
|
c.Name = "NVIDIA Container Toolkit CLI"
|
2022-01-13 12:29:00 +00:00
|
|
|
c.UseShortOptionHandling = true
|
|
|
|
c.EnableBashCompletion = true
|
|
|
|
c.Usage = "Tools to configure the NVIDIA Container Toolkit"
|
2022-05-12 12:02:06 +00:00
|
|
|
c.Version = info.GetVersionString()
|
2022-01-13 12:29:00 +00:00
|
|
|
|
|
|
|
// Setup the flags for this command
|
|
|
|
c.Flags = []cli.Flag{
|
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "debug",
|
|
|
|
Aliases: []string{"d"},
|
|
|
|
Usage: "Enable debug-level logging",
|
2023-03-13 12:31:58 +00:00
|
|
|
Destination: &opts.Debug,
|
2022-01-13 12:29:00 +00:00
|
|
|
EnvVars: []string{"NVIDIA_CTK_DEBUG"},
|
|
|
|
},
|
2023-06-30 13:55:13 +00:00
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "quiet",
|
|
|
|
Usage: "Suppress all output except for errors; overrides --debug",
|
|
|
|
Destination: &opts.Quiet,
|
|
|
|
EnvVars: []string{"NVIDIA_CTK_QUIET"},
|
|
|
|
},
|
2022-01-13 12:29:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set log-level for all subcommands
|
|
|
|
c.Before = func(c *cli.Context) error {
|
2023-03-22 12:27:43 +00:00
|
|
|
logLevel := logrus.InfoLevel
|
2023-03-13 12:31:58 +00:00
|
|
|
if opts.Debug {
|
2023-03-22 12:27:43 +00:00
|
|
|
logLevel = logrus.DebugLevel
|
2022-01-13 12:29:00 +00:00
|
|
|
}
|
2023-06-30 13:55:13 +00:00
|
|
|
if opts.Quiet {
|
|
|
|
logLevel = logrus.ErrorLevel
|
|
|
|
}
|
2022-01-13 12:29:00 +00:00
|
|
|
logger.SetLevel(logLevel)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Define the subcommands
|
2022-03-14 11:53:22 +00:00
|
|
|
c.Commands = []*cli.Command{
|
|
|
|
hook.NewCommand(logger),
|
2022-01-14 13:57:51 +00:00
|
|
|
runtime.NewCommand(logger),
|
2022-06-20 11:53:16 +00:00
|
|
|
infoCLI.NewCommand(logger),
|
2022-11-01 19:05:23 +00:00
|
|
|
cdi.NewCommand(logger),
|
2023-01-27 10:38:36 +00:00
|
|
|
system.NewCommand(logger),
|
2023-03-13 12:33:10 +00:00
|
|
|
config.NewCommand(logger),
|
2022-03-14 11:53:22 +00:00
|
|
|
}
|
2022-01-13 12:29:00 +00:00
|
|
|
|
|
|
|
// Run the CLI
|
|
|
|
err := c.Run(os.Args)
|
|
|
|
if err != nil {
|
2023-03-22 12:27:43 +00:00
|
|
|
logger.Errorf("%v", err)
|
|
|
|
os.Exit(1)
|
2022-01-13 12:29:00 +00:00
|
|
|
}
|
|
|
|
}
|