mirror of
https://github.com/NVIDIA/nvidia-container-toolkit
synced 2025-06-26 18:18:24 +00:00
Move formatJSON and formatYAML to nvcdi/spec package
Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
@@ -25,6 +25,11 @@ import (
|
||||
const (
|
||||
// DetectMinimumVersion is a constant that triggers a spec to detect the minimum required version.
|
||||
DetectMinimumVersion = "DETECT_MINIMUM_VERSION"
|
||||
|
||||
// FormatJSON indicates a JSON output format
|
||||
FormatJSON = "json"
|
||||
// FormatYAML indicates a YAML output format
|
||||
FormatYAML = "yaml"
|
||||
)
|
||||
|
||||
// Interface is the interface for the spec API
|
||||
|
||||
@@ -33,8 +33,8 @@ type builder struct {
|
||||
format string
|
||||
}
|
||||
|
||||
// NewBuilder creates a new spec builder with the supplied options
|
||||
func NewBuilder(opts ...Option) *builder {
|
||||
// newBuilder creates a new spec builder with the supplied options
|
||||
func newBuilder(opts ...Option) *builder {
|
||||
s := &builder{}
|
||||
for _, opt := range opts {
|
||||
opt(s)
|
||||
@@ -48,6 +48,9 @@ func NewBuilder(opts ...Option) *builder {
|
||||
if s.class == "" {
|
||||
s.class = "gpu"
|
||||
}
|
||||
if s.format == "" {
|
||||
s.format = FormatYAML
|
||||
}
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ var _ Interface = (*spec)(nil)
|
||||
|
||||
// New creates a new spec with the specified options.
|
||||
func New(opts ...Option) (Interface, error) {
|
||||
return NewBuilder(opts...).Build()
|
||||
return newBuilder(opts...).Build()
|
||||
}
|
||||
|
||||
// Save writes the spec to the specified path and overwrites the file if it exists.
|
||||
@@ -98,9 +98,9 @@ func (s *spec) normalizePath(path string) string {
|
||||
|
||||
func (s *spec) extension() string {
|
||||
switch s.format {
|
||||
case "json":
|
||||
case FormatJSON:
|
||||
return ".json"
|
||||
case "yaml", "yml":
|
||||
case FormatYAML:
|
||||
return ".yaml"
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user