Skip to content

Commit

Permalink
align config option handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mandelsoft committed Dec 9, 2024
1 parent 53a8088 commit 696173d
Show file tree
Hide file tree
Showing 32 changed files with 415 additions and 513 deletions.
97 changes: 97 additions & 0 deletions api/ocm/extensions/accessmethods/options/deprecated.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package options

import (
"ocm.software/ocm/api/utils/cobrautils/flagsets"
)

const (
// Deprecated: use package [flagsets].
TYPE_STRING = flagsets.TYPE_STRING
// Deprecated: use package [flagsets].
TYPE_STRINGARRAY = flagsets.TYPE_STRINGARRAY
// Deprecated: use package [flagsets].
TYPE_STRING2STRING = flagsets.TYPE_STRING2STRING
// Deprecated: use package [flagsets].
TYPE_INT = flagsets.TYPE_INT
// Deprecated: use package [flagsets].
TYPE_BOOL = flagsets.TYPE_BOOL
// Deprecated: use package [flagsets].
TYPE_YAML = flagsets.TYPE_YAML
// Deprecated: use package [flagsets].
TYPE_STRINGMAPYAML = flagsets.TYPE_STRINGMAPYAML
// Deprecated: use package [flagsets].
TYPE_STRING2YAML = flagsets.TYPE_STRING2YAML
// Deprecated: use package [flagsets].
TYPE_STRING2STRINGSLICE = flagsets.TYPE_STRING2STRINGSLICE
// Deprecated: use package [flagsets].
TYPE_STRINGCOLONSTRINGSLICE = flagsets.TYPE_STRINGCOLONSTRINGSLICE
// Deprecated: use package [flagsets].
TYPE_BYTES = flagsets.TYPE_BYTES
// Deprecated: use package [flagsets].
TYPE_IDENTITYPATH = flagsets.TYPE_IDENTITYPATH
)

// Deprecated: use packagge [flagsets].
type OptionType = flagsets.ConfigOptionType

////////////////////////////////////////////////////////////////////////////////

// Deprecated: use packagge [flagsets].
func NewStringOptionType(name, desc string) OptionType {
return flagsets.NewStringOptionType(name, desc)
}

// Deprecated: use packagge [flagsets].
func NewStringArrayOptionType(name, desc string) OptionType {
return flagsets.NewStringArrayOptionType(name, desc)
}

// Deprecated: use packagge [flagsets].
func NewIntOptionType(name, desc string) OptionType {
return flagsets.NewIntOptionType(name, desc)
}

// Deprecated: use packagge [flagsets].
func NewBoolOptionType(name, desc string) OptionType {
return flagsets.NewBoolOptionType(name, desc)
}

// Deprecated: use packagge [flagsets].
func NewYAMLOptionType(name, desc string) OptionType {
return flagsets.NewYAMLOptionType(name, desc)
}

// Deprecated: use packagge [flagsets].
func NewValueMapYAMLOptionType(name, desc string) OptionType {
return flagsets.NewValueMapYAMLOptionType(name, desc)
}

// Deprecated: use packagge [flagsets].
func NewValueMapOptionType(name, desc string) OptionType {
return flagsets.NewValueMapOptionType(name, desc)
}

// Deprecated: use packagge [flagsets].
func NewStringMapOptionType(name, desc string) OptionType {
return flagsets.NewStringMapOptionType(name, desc)
}

// Deprecated: use packagge [flagsets].
func NewStringSliceMapOptionType(name, desc string) OptionType {
return flagsets.NewStringSliceMapOptionType(name, desc)
}

// Deprecated: use packagge [flagsets].
func NewStringSliceMapColonOptionType(name, desc string) OptionType {
return flagsets.NewStringSliceMapColonOptionType(name, desc)
}

// Deprecated: use packagge [flagsets].
func NewBytesOptionType(name, desc string) OptionType {
return flagsets.NewBytesOptionType(name, desc)
}

// Deprecated: use packagge [flagsets].
func NewIdentityPathOptionType(name, desc string) OptionType {
return flagsets.NewIdentityPathOptionType(name, desc)
}
30 changes: 3 additions & 27 deletions api/ocm/extensions/accessmethods/options/init.go
Original file line number Diff line number Diff line change
@@ -1,34 +1,10 @@
package options

const (
TYPE_STRING = "string"
TYPE_STRINGARRAY = "[]string"
TYPE_STRING2STRING = "string=string"
TYPE_INT = "int"
TYPE_BOOL = "bool"
TYPE_YAML = "YAML"
TYPE_STRINGMAPYAML = "map[string]YAML"
TYPE_STRING2YAML = "string=YAML"
TYPE_STRING2STRINGSLICE = "string=string,string"
TYPE_STRINGCOLONSTRINGSLICE = "string:string,string"
TYPE_BYTES = "[]byte"
TYPE_IDENTITYPATH = "[]identity"
import (
"ocm.software/ocm/api/utils/cobrautils/flagsets"
)

func init() {
DefaultRegistry.RegisterValueType(TYPE_STRING, NewStringOptionType, "string value")
DefaultRegistry.RegisterValueType(TYPE_STRINGARRAY, NewStringArrayOptionType, "list of string values")
DefaultRegistry.RegisterValueType(TYPE_STRING2STRING, NewStringMapOptionType, "string map defined by dedicated assignments")
DefaultRegistry.RegisterValueType(TYPE_INT, NewIntOptionType, "integer value")
DefaultRegistry.RegisterValueType(TYPE_BOOL, NewBoolOptionType, "boolean flag")
DefaultRegistry.RegisterValueType(TYPE_YAML, NewYAMLOptionType, "JSON or YAML document string")
DefaultRegistry.RegisterValueType(TYPE_STRINGMAPYAML, NewValueMapYAMLOptionType, "JSON or YAML map")
DefaultRegistry.RegisterValueType(TYPE_STRING2YAML, NewValueMapOptionType, "string map with arbitrary values defined by dedicated assignments")
DefaultRegistry.RegisterValueType(TYPE_STRING2STRINGSLICE, NewStringSliceMapOptionType, "string map defined by dedicated assignment of comma separated strings")
DefaultRegistry.RegisterValueType(TYPE_STRINGCOLONSTRINGSLICE, NewStringSliceMapColonOptionType, "string map defined by dedicated assignment of comma separated strings")
DefaultRegistry.RegisterValueType(TYPE_BYTES, NewBytesOptionType, "byte value")
DefaultRegistry.RegisterValueType(TYPE_IDENTITYPATH, NewIdentityPathOptionType, "identity path")
}
var DefaultRegistry = flagsets.SetBaseTypes(flagsets.NewConfigOptionTypeRegistry())

func RegisterOption(o OptionType) OptionType {
DefaultRegistry.RegisterOptionType(o)
Expand Down
50 changes: 0 additions & 50 deletions api/ocm/extensions/accessmethods/options/registry_test.go

This file was deleted.

62 changes: 33 additions & 29 deletions api/ocm/extensions/accessmethods/options/standard.go
Original file line number Diff line number Diff line change
@@ -1,84 +1,88 @@
package options

import (
"ocm.software/ocm/api/utils/cobrautils/flagsets"
)

// HintOption .
var HintOption = RegisterOption(NewStringOptionType("hint", "(repository) hint for local artifacts"))
var HintOption = RegisterOption(flagsets.NewStringOptionType("hint", "(repository) hint for local artifacts"))

// MediatypeOption .
var MediatypeOption = RegisterOption(NewStringOptionType("mediaType", "media type for artifact blob representation"))
var MediatypeOption = RegisterOption(flagsets.NewStringOptionType("mediaType", "media type for artifact blob representation"))

// SizeOption .
var SizeOption = RegisterOption(NewIntOptionType("size", "blob size"))
var SizeOption = RegisterOption(flagsets.NewIntOptionType("size", "blob size"))

// DigestOption .
var DigestOption = RegisterOption(NewStringOptionType("digest", "blob digest"))
var DigestOption = RegisterOption(flagsets.NewStringOptionType("digest", "blob digest"))

// ReferenceOption .
var ReferenceOption = RegisterOption(NewStringOptionType("reference", "reference name"))
var ReferenceOption = RegisterOption(flagsets.NewStringOptionType("reference", "reference name"))

// PackageOption .
var PackageOption = RegisterOption(NewStringOptionType("package", "package or object name"))
var PackageOption = RegisterOption(flagsets.NewStringOptionType("package", "package or object name"))

// ArtifactOption .
var ArtifactOption = RegisterOption(NewStringOptionType("artifactId", "maven artifact id"))
var ArtifactOption = RegisterOption(flagsets.NewStringOptionType("artifactId", "maven artifact id"))

// GroupOption .
var GroupOption = RegisterOption(NewStringOptionType("groupId", "maven group id"))
var GroupOption = RegisterOption(flagsets.NewStringOptionType("groupId", "maven group id"))

// RepositoryOption .
var RepositoryOption = RegisterOption(NewStringOptionType("accessRepository", "repository or registry URL"))
var RepositoryOption = RegisterOption(flagsets.NewStringOptionType("accessRepository", "repository or registry URL"))

// HostnameOption .
var HostnameOption = RegisterOption(NewStringOptionType("accessHostname", "hostname used for access"))
var HostnameOption = RegisterOption(flagsets.NewStringOptionType("accessHostname", "hostname used for access"))

// CommitOption .
var CommitOption = RegisterOption(NewStringOptionType("commit", "git commit id"))
var CommitOption = RegisterOption(flagsets.NewStringOptionType("commit", "git commit id"))

// GlobalAccessOption .
var GlobalAccessOption = RegisterOption(NewValueMapYAMLOptionType("globalAccess", "access specification for global access"))
var GlobalAccessOption = RegisterOption(flagsets.NewValueMapYAMLOptionType("globalAccess", "access specification for global access"))

// RegionOption .
var RegionOption = RegisterOption(NewStringOptionType("region", "region name"))
var RegionOption = RegisterOption(flagsets.NewStringOptionType("region", "region name"))

// BucketOption .
var BucketOption = RegisterOption(NewStringOptionType("bucket", "bucket name"))
var BucketOption = RegisterOption(flagsets.NewStringOptionType("bucket", "bucket name"))

// VersionOption .
var VersionOption = RegisterOption(NewStringOptionType("accessVersion", "version for access specification"))
var VersionOption = RegisterOption(flagsets.NewStringOptionType("accessVersion", "version for access specification"))

// ComponentOption.
var ComponentOption = RegisterOption(NewStringOptionType("accessComponent", "component for access specification"))
var ComponentOption = RegisterOption(flagsets.NewStringOptionType("accessComponent", "component for access specification"))

// IdentityPathOption.
var IdentityPathOption = RegisterOption(NewIdentityPathOptionType("identityPath", "identity path for specification"))
var IdentityPathOption = RegisterOption(flagsets.NewIdentityPathOptionType("identityPath", "identity path for specification"))

// URLOption.
var URLOption = RegisterOption(NewStringOptionType("url", "artifact or server url"))
var URLOption = RegisterOption(flagsets.NewStringOptionType("url", "artifact or server url"))

var HTTPHeaderOption = RegisterOption(NewStringSliceMapColonOptionType("header", "http headers"))
var HTTPHeaderOption = RegisterOption(flagsets.NewStringSliceMapColonOptionType("header", "http headers"))

var HTTPVerbOption = RegisterOption(NewStringOptionType("verb", "http request method"))
var HTTPVerbOption = RegisterOption(flagsets.NewStringOptionType("verb", "http request method"))

var HTTPBodyOption = RegisterOption(NewStringOptionType("body", "body of a http request"))
var HTTPBodyOption = RegisterOption(flagsets.NewStringOptionType("body", "body of a http request"))

var HTTPRedirectOption = RegisterOption(NewBoolOptionType("noredirect", "http redirect behavior"))
var HTTPRedirectOption = RegisterOption(flagsets.NewBoolOptionType("noredirect", "http redirect behavior"))

// CommentOption .
var CommentOption = RegisterOption(NewStringOptionType("comment", "comment field value"))
var CommentOption = RegisterOption(flagsets.NewStringOptionType("comment", "comment field value"))

// ClassifierOption the optional classifier of a maven resource.
var ClassifierOption = RegisterOption(NewStringOptionType("classifier", "maven classifier"))
var ClassifierOption = RegisterOption(flagsets.NewStringOptionType("classifier", "maven classifier"))

// ExtensionOption the optional extension of a maven resource.
var ExtensionOption = RegisterOption(NewStringOptionType("extension", "maven extension name"))
var ExtensionOption = RegisterOption(flagsets.NewStringOptionType("extension", "maven extension name"))

// NPMRegistryOption sets the registry of the npm resource.
var NPMRegistryOption = RegisterOption(NewStringOptionType("registry", "npm package registry"))
var NPMRegistryOption = RegisterOption(flagsets.NewStringOptionType("registry", "npm package registry"))

// NPMPackageOption sets what package should be fetched from the npm registry.
var NPMPackageOption = RegisterOption(NewStringOptionType("package", "npm package name"))
var NPMPackageOption = PackageOption

// NPMVersionOption sets the version of the npm package.
var NPMVersionOption = RegisterOption(NewStringOptionType("version", "npm package version"))
var NPMVersionOption = RegisterOption(flagsets.NewStringOptionType("version", "npm package version"))

// IdPathOption is a path of identity specs.
var IdPathOption = RegisterOption(NewStringArrayOptionType("idpath", "identity path (attr=value{,attr=value}"))
var IdPathOption = RegisterOption(flagsets.NewStringArrayOptionType("idpath", "identity path (attr=value{,attr=value}"))
Loading

0 comments on commit 696173d

Please sign in to comment.