diff --git a/cmds/ocm/commands/ocmcmds/common/inputs/options/standard.go b/cmds/ocm/commands/ocmcmds/common/inputs/options/standard.go index 0ba2712520..dc7391b91d 100644 --- a/cmds/ocm/commands/ocmcmds/common/inputs/options/standard.go +++ b/cmds/ocm/commands/ocmcmds/common/inputs/options/standard.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2022 SAP SE or an SAP affiliate company and Open Component Model contributors. -// -// SPDX-License-Identifier: Apache-2.0 - package options import ( @@ -14,41 +10,45 @@ var ( MediaTypeOption = options.MediatypeOption ) -var PathOption = flagsets.NewStringOptionType("inputPath", "path field for input") - +// string options var ( - CompressOption = flagsets.NewBoolOptionType("inputCompress", "compress option for input") - ExcludeOption = flagsets.NewStringArrayOptionType("inputExcludes", "excludes (path) for inputs") + VersionOption = flagsets.NewStringOptionType("inputVersion", "version info for inputs") + TextOption = flagsets.NewStringOptionType("inputText", "utf8 text") + HelmRepositoryOption = flagsets.NewStringOptionType("inputHelmRepository", "helm repository base URL") +) +var ( + VariantsOption = flagsets.NewStringArrayOptionType("inputVariants", "(platform) variants for inputs") + ExcludeOption = flagsets.NewStringArrayOptionType("inputExcludes", "excludes (path) for inputs") + PlatformsOption = flagsets.NewStringArrayOptionType("inputPlatforms", "input filter for image platforms ([os]/[architecture])") ) +// path options var ( - IncludeOption = flagsets.NewStringArrayOptionType("inputIncludes", "includes (path) for inputs") - PreserveDirOption = flagsets.NewBoolOptionType("inputPreserveDir", "preserve directory in archive for inputs") + PathOption = flagsets.NewPathOptionType("inputPath", "path field for input") +) +var ( + IncludeOption = flagsets.NewPathArrayOptionType("inputIncludes", "includes (path) for inputs") + LibrariesOption = flagsets.NewPathArrayOptionType("inputLibraries", "library path for inputs") ) +// boolean options var ( + CompressOption = flagsets.NewBoolOptionType("inputCompress", "compress option for input") + PreserveDirOption = flagsets.NewBoolOptionType("inputPreserveDir", "preserve directory in archive for inputs") FollowSymlinksOption = flagsets.NewBoolOptionType("inputFollowSymlinks", "follow symbolic links during archive creation for inputs") - VariantsOption = flagsets.NewStringArrayOptionType("inputVariants", "(platform) variants for inputs") ) -var LibrariesOption = flagsets.NewStringArrayOptionType("inputLibraries", "library path for inputs") - -var VersionOption = flagsets.NewStringOptionType("inputVersion", "version info for inputs") - -var ValuesOption = flagsets.NewValueMapYAMLOptionType("inputValues", "YAML based generic values for inputs") - -var DataOption = flagsets.NewBytesOptionType("inputData", "data (string, !!string or !") - -var TextOption = flagsets.NewStringOptionType("inputText", "utf8 text") - -var YAMLOption = flagsets.NewYAMLOptionType("inputYaml", "YAML formatted text") - -var JSONOption = flagsets.NewYAMLOptionType("inputJson", "JSON formatted text") - -var FormattedJSONOption = flagsets.NewYAMLOptionType("inputFormattedJson", "JSON formatted text") - -var HelmRepositoryOption = flagsets.NewStringOptionType("inputHelmRepository", "helm repository base URL") +// data options +var ( + DataOption = flagsets.NewBytesOptionType("inputData", "data (string, !!string or !") +) +// yaml/json options var ( - PlatformsOption = flagsets.NewStringArrayOptionType("inputPlatforms", "input filter for image platforms ([os]/[architecture])") + YAMLOption = flagsets.NewYAMLOptionType("inputYaml", "YAML formatted text") + JSONOption = flagsets.NewYAMLOptionType("inputJson", "JSON formatted text") + FormattedJSONOption = flagsets.NewYAMLOptionType("inputFormattedJson", "JSON formatted text") +) +var ( + ValuesOption = flagsets.NewValueMapYAMLOptionType("inputValues", "YAML based generic values for inputs") ) diff --git a/pkg/cobrautils/flagsets/types.go b/pkg/cobrautils/flagsets/types.go index bb1c165d77..719c7d7189 100644 --- a/pkg/cobrautils/flagsets/types.go +++ b/pkg/cobrautils/flagsets/types.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2022 SAP SE or an SAP affiliate company and Open Component Model contributors. -// -// SPDX-License-Identifier: Apache-2.0 - package flagsets import ( @@ -149,6 +145,82 @@ func (o *StringArrayOption) Value() interface{} { return o.value } +// PathOptionType ////////////////////////////////////////////////////////////////////////////// + +type Path string + +type PathOptionType struct { + TypeOptionBase +} + +func NewPathOptionType(name string, description string) ConfigOptionType { + return &PathOptionType{ + TypeOptionBase: TypeOptionBase{name, description}, + } +} + +func (s *PathOptionType) Equal(optionType ConfigOptionType) bool { + return reflect.DeepEqual(s, optionType) +} + +func (s *PathOptionType) Create() Option { + return &PathOption{ + OptionBase: NewOptionBase(s), + } +} + +type PathOption struct { + OptionBase + value string // TODO replace with Path? +} + +var _ Option = (*PathOption)(nil) + +func (o *PathOption) AddFlags(fs *pflag.FlagSet) { + o.TweakFlag(flag.StringVarPF(fs, &o.value, o.otyp.GetName(), "", "", o.otyp.GetDescription())) +} + +func (o *PathOption) Value() interface{} { + return o.value +} + +// PathArrayOptionType ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +type PathArrayOptionType struct { + TypeOptionBase +} + +func NewPathArrayOptionType(name string, description string) ConfigOptionType { + return &PathArrayOptionType{ + TypeOptionBase: TypeOptionBase{name, description}, + } +} + +func (s *PathArrayOptionType) Equal(optionType ConfigOptionType) bool { + return reflect.DeepEqual(s, optionType) +} + +func (s *PathArrayOptionType) Create() Option { + return &PathArrayOption{ + OptionBase: NewOptionBase(s), + } +} + +type PathArrayOption struct { + OptionBase + value []string // TODO replace with Path? +} + +var _ Option = (*PathArrayOption)(nil) + +func (o *PathArrayOption) AddFlags(fs *pflag.FlagSet) { + o.TweakFlag(flag.StringArrayVarPF(fs, &o.value, o.otyp.GetName(), "", nil, o.otyp.GetDescription())) +} + +func (o *PathArrayOption) Value() interface{} { + return o.value +} + //////////////////////////////////////////////////////////////////////////////// type BoolOptionType struct {