Skip to content

Commit

Permalink
introduce PathOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
hilmarf committed Feb 20, 2024
1 parent 34e6d22 commit 978344d
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 33 deletions.
58 changes: 29 additions & 29 deletions cmds/ocm/commands/ocmcmds/common/inputs/options/standard.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand All @@ -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 !<base64>")

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 !<base64>")
)

// 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")
)
80 changes: 76 additions & 4 deletions pkg/cobrautils/flagsets/types.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 978344d

Please sign in to comment.