mirror of
https://github.com/NVIDIA/nvidia-container-toolkit
synced 2024-11-22 00:08:11 +00:00
Add stub nvidia-ctk CLI
This change adds an nvidia-ctk CLI that is used as the basis for utilities related to the NVIDIA Container Toolkit. Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
parent
7914957105
commit
c945cc714d
1
.gitignore
vendored
1
.gitignore
vendored
@ -5,4 +5,5 @@ dist
|
|||||||
/test/output/
|
/test/output/
|
||||||
/nvidia-container-runtime
|
/nvidia-container-runtime
|
||||||
/nvidia-container-toolkit
|
/nvidia-container-toolkit
|
||||||
|
/nvidia-ctk
|
||||||
/shared-*
|
/shared-*
|
||||||
|
3
cmd/nvidia-ctk/README.md
Normal file
3
cmd/nvidia-ctk/README.md
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# NVIDIA Container Toolkit CLI
|
||||||
|
|
||||||
|
The NVIDIA Container Toolkit CLI `nvidia-ctk` provides a number of utilities that are useful for working with the NVIDIA Container Toolkit.
|
79
cmd/nvidia-ctk/main.go
Normal file
79
cmd/nvidia-ctk/main.go
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
/**
|
||||||
|
# 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"
|
||||||
|
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
cli "github.com/urfave/cli/v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
var version string
|
||||||
|
|
||||||
|
var logger = log.New()
|
||||||
|
|
||||||
|
// config defines the options that can be set for the CLI through config files,
|
||||||
|
// environment variables, or command line flags
|
||||||
|
type config struct {
|
||||||
|
// Debug indicates whether the CLI is started in "debug" mode
|
||||||
|
Debug bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
// Create a config struct to hold the parsed environment variables or command line flags
|
||||||
|
config := config{}
|
||||||
|
|
||||||
|
// Create the top-level CLI
|
||||||
|
c := cli.NewApp()
|
||||||
|
c.UseShortOptionHandling = true
|
||||||
|
c.EnableBashCompletion = true
|
||||||
|
c.Usage = "Tools to configure the NVIDIA Container Toolkit"
|
||||||
|
c.Version = version
|
||||||
|
|
||||||
|
// Setup the flags for this command
|
||||||
|
c.Flags = []cli.Flag{
|
||||||
|
&cli.BoolFlag{
|
||||||
|
Name: "debug",
|
||||||
|
Aliases: []string{"d"},
|
||||||
|
Usage: "Enable debug-level logging",
|
||||||
|
Destination: &config.Debug,
|
||||||
|
EnvVars: []string{"NVIDIA_CTK_DEBUG"},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set log-level for all subcommands
|
||||||
|
c.Before = func(c *cli.Context) error {
|
||||||
|
logLevel := log.InfoLevel
|
||||||
|
if config.Debug {
|
||||||
|
logLevel = log.DebugLevel
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.SetLevel(logLevel)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Define the subcommands
|
||||||
|
c.Commands = []*cli.Command{}
|
||||||
|
|
||||||
|
// Run the CLI
|
||||||
|
err := c.Run(os.Args)
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("%v", err)
|
||||||
|
log.Exit(1)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user