Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support of CLI option groups #172

Merged
merged 1 commit into from
Nov 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion cmds/ocm/commands/ocmcmds/common/inputs/inputtype.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@ type inputTypeScheme struct {
func NewInputTypeScheme(defaultRepoDecoder runtime.TypedObjectDecoder) InputTypeScheme {
var rt InputSpec
scheme := runtime.MustNewDefaultScheme(&rt, &UnknownInputSpec{}, false, defaultRepoDecoder)
return &inputTypeScheme{scheme, flagsets.NewTypedConfigProvider("input", "blob input specification")}
prov := flagsets.NewTypedConfigProvider("input", "blob input specification")
prov.AddGroups("Input Specification Options")
return &inputTypeScheme{scheme, prov}
}

func (t *inputTypeScheme) AddKnownTypes(s InputTypeScheme) {
Expand Down
33 changes: 21 additions & 12 deletions cmds/ocm/commands/ocmcmds/common/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (

"github.com/mandelsoft/vfs/pkg/vfs"
"github.com/spf13/pflag"
"golang.org/x/text/cases"
"golang.org/x/text/language"
"gopkg.in/yaml.v3"
"k8s.io/apimachinery/pkg/util/validation/field"

Expand Down Expand Up @@ -138,17 +140,19 @@ type ResourceMetaDataSpecificationsProvider struct {
}

func NewResourceMetaDataSpecificationsProvider(name string, adder flagsets.ConfigAdder, types ...flagsets.ConfigOptionType) *ResourceMetaDataSpecificationsProvider {
meta := flagsets.NewPlainConfigProvider(name, flagsets.ComposedAdder(addMeta(name), adder),
append(types,
flagsets.NewYAMLOptionType(name, fmt.Sprintf("%s meta data (yaml)", name)),
flagsets.NewStringOptionType("name", fmt.Sprintf("%s name", name)),
flagsets.NewStringOptionType("version", fmt.Sprintf("%s version", name)),
flagsets.NewStringMapOptionType("extra", fmt.Sprintf("%s extra identity", name)),
flagsets.NewValueMapOptionType("label", fmt.Sprintf("%s label (leading * indicates signature relevant, optional version separated by @)", name)),
)...,
)
meta.AddGroups(cases.Title(language.English).String(fmt.Sprintf("%s meta data options", name)))
a := &ResourceMetaDataSpecificationsProvider{
typename: name,
metaProvider: flagsets.NewPlainConfigProvider(name, flagsets.ComposedAdder(addMeta(name), adder),
append(types,
flagsets.NewYAMLOptionType(name, fmt.Sprintf("%s meta data (yaml)", name)),
flagsets.NewStringOptionType("name", fmt.Sprintf("%s name", name)),
flagsets.NewStringOptionType("version", fmt.Sprintf("%s version", name)),
flagsets.NewStringMapOptionType("extra", fmt.Sprintf("%s extra identity", name)),
flagsets.NewValueMapOptionType("label", fmt.Sprintf("%s label (leading * indicates signature relevant, optional version separated by @)", name)),
)...,
),
typename: name,
metaProvider: meta,
}
a.metaOptions = a.metaProvider.CreateOptions()
return a
Expand Down Expand Up @@ -259,14 +263,19 @@ or <code>input</code> fields of the description file format.
func (a *ContentResourceSpecificationsProvider) AddFlags(fs *pflag.FlagSet) {
a.ResourceMetaDataSpecificationsProvider.AddFlags(fs)

acctypes := a.ctx.OCMContext().AccessMethods().ConfigTypeSetConfigProvider()
inptypes := inputs.For(a.ctx).ConfigTypeSetConfigProvider()

set := flagsets.NewConfigOptionSet("resources")
set.AddAll(a.ctx.OCMContext().AccessMethods().ConfigTypeSetConfigProvider())
dup, err := set.AddAll(inputs.For(a.ctx).ConfigTypeSetConfigProvider())
set.AddAll(acctypes)
dup, err := set.AddAll(inptypes)
if err != nil {
panic(err)
}
a.shared = dup
a.options = set.CreateOptions()
a.options.AddTypeSetGroupsToOptions(acctypes)
a.options.AddTypeSetGroupsToOptions(inptypes)
a.options.AddFlags(fs)
}

Expand Down
12 changes: 9 additions & 3 deletions docs/reference/ocm_add_references.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,20 @@ ocm add references [<options>] <target> {<referencefile> | <var>=<value>}

```
--addenv access environment for templating
-h, --help help for references
-s, --settings stringArray settings file with variable settings (yaml)
--templater string templater to use (subst, spiff, go) (default "subst")
```


#### Reference Meta Data Options

```
--component string component name
--extra <name>=<value> reference extra identity (default [])
-h, --help help for references
--label <name>=<YAML> reference label (leading * indicates signature relevant, optional version separated by @)
--name string reference name
--reference YAML reference meta data (yaml)
-s, --settings stringArray settings file with variable settings (yaml)
--templater string templater to use (subst, spiff, go) (default "subst")
--version string reference version
```

Expand Down
40 changes: 30 additions & 10 deletions docs/reference/ocm_add_resource-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,37 @@ ocm add resource-configuration [<options>] <target> {<configfile> | <var>=<value

### Options

```
--addenv access environment for templating
-h, --help help for resource-configuration
-s, --settings stringArray settings file with variable settings (yaml)
--templater string templater to use (subst, spiff, go) (default "none")
```


#### Access Specification Options

```
--access YAML blob access specification (YAML)
--accessHostname string hostname used for access
--accessRepository string repository URL
--accessType string type of blob access specification
--accessVersion string version for access specification
--addenv access environment for templating
--bucket string bucket name
--commit string git commit id
--digest string blob digest
--external flag non-local resource
--extra <name>=<value> resource extra identity (default [])
--globalAccess YAML access specification for global access
-h, --help help for resource-configuration
--hint string (repository) hint for local artifacts
--mediaType string media type for artifact blob representation
--reference string reference name
--region string region name
--size int blob size
```


#### Input Specification Options

```
--hint string (repository) hint for local artifacts
--input YAML blob input specification (YAML)
--inputCompress compress option for input
Expand All @@ -35,15 +52,18 @@ ocm add resource-configuration [<options>] <target> {<configfile> | <var>=<value
--inputValues YAML YAML based generic values for inputs
--inputVariants stringArray (platform) variants for inputs
--inputVersion stringArray version info for inputs
--label <name>=<YAML> resource label (leading * indicates signature relevant, optional version separated by @)
--mediaType string media type for artifact blob representation
```


#### Resource Meta Data Options

```
--external flag non-local resource
--extra <name>=<value> resource extra identity (default [])
--label <name>=<YAML> resource label (leading * indicates signature relevant, optional version separated by @)
--name string resource name
--reference string reference name
--region string region name
--resource YAML resource meta data (yaml)
-s, --settings stringArray settings file with variable settings (yaml)
--size int blob size
--templater string templater to use (subst, spiff, go) (default "none")
--type string resource type
--version string resource version
```
Expand Down
40 changes: 30 additions & 10 deletions docs/reference/ocm_add_resources.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,37 @@ ocm add resources [<options>] <target> {<resourcefile> | <var>=<value>}

### Options

```
--addenv access environment for templating
-h, --help help for resources
-s, --settings stringArray settings file with variable settings (yaml)
--templater string templater to use (subst, spiff, go) (default "subst")
```


#### Access Specification Options

```
--access YAML blob access specification (YAML)
--accessHostname string hostname used for access
--accessRepository string repository URL
--accessType string type of blob access specification
--accessVersion string version for access specification
--addenv access environment for templating
--bucket string bucket name
--commit string git commit id
--digest string blob digest
--external flag non-local resource
--extra <name>=<value> resource extra identity (default [])
--globalAccess YAML access specification for global access
-h, --help help for resources
--hint string (repository) hint for local artifacts
--mediaType string media type for artifact blob representation
--reference string reference name
--region string region name
--size int blob size
```


#### Input Specification Options

```
--hint string (repository) hint for local artifacts
--input YAML blob input specification (YAML)
--inputCompress compress option for input
Expand All @@ -35,15 +52,18 @@ ocm add resources [<options>] <target> {<resourcefile> | <var>=<value>}
--inputValues YAML YAML based generic values for inputs
--inputVariants stringArray (platform) variants for inputs
--inputVersion stringArray version info for inputs
--label <name>=<YAML> resource label (leading * indicates signature relevant, optional version separated by @)
--mediaType string media type for artifact blob representation
```


#### Resource Meta Data Options

```
--external flag non-local resource
--extra <name>=<value> resource extra identity (default [])
--label <name>=<YAML> resource label (leading * indicates signature relevant, optional version separated by @)
--name string resource name
--reference string reference name
--region string region name
--resource YAML resource meta data (yaml)
-s, --settings stringArray settings file with variable settings (yaml)
--size int blob size
--templater string templater to use (subst, spiff, go) (default "subst")
--type string resource type
--version string resource version
```
Expand Down
38 changes: 29 additions & 9 deletions docs/reference/ocm_add_source-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,37 @@ ocm add source-configuration [<options>] <target> {<configfile> | <var>=<value>}

### Options

```
--addenv access environment for templating
-h, --help help for source-configuration
-s, --settings stringArray settings file with variable settings (yaml)
--templater string templater to use (subst, spiff, go) (default "none")
```


#### Access Specification Options

```
--access YAML blob access specification (YAML)
--accessHostname string hostname used for access
--accessRepository string repository URL
--accessType string type of blob access specification
--accessVersion string version for access specification
--addenv access environment for templating
--bucket string bucket name
--commit string git commit id
--digest string blob digest
--extra <name>=<value> source extra identity (default [])
--globalAccess YAML access specification for global access
-h, --help help for source-configuration
--hint string (repository) hint for local artifacts
--mediaType string media type for artifact blob representation
--reference string reference name
--region string region name
--size int blob size
```


#### Input Specification Options

```
--hint string (repository) hint for local artifacts
--input YAML blob input specification (YAML)
--inputCompress compress option for input
Expand All @@ -34,15 +52,17 @@ ocm add source-configuration [<options>] <target> {<configfile> | <var>=<value>}
--inputValues YAML YAML based generic values for inputs
--inputVariants stringArray (platform) variants for inputs
--inputVersion stringArray version info for inputs
--label <name>=<YAML> source label (leading * indicates signature relevant, optional version separated by @)
--mediaType string media type for artifact blob representation
```


#### Source Meta Data Options

```
--extra <name>=<value> source extra identity (default [])
--label <name>=<YAML> source label (leading * indicates signature relevant, optional version separated by @)
--name string source name
--reference string reference name
--region string region name
-s, --settings stringArray settings file with variable settings (yaml)
--size int blob size
--source YAML source meta data (yaml)
--templater string templater to use (subst, spiff, go) (default "none")
--type string source type
--version string source version
```
Expand Down
38 changes: 29 additions & 9 deletions docs/reference/ocm_add_sources.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,37 @@ ocm add sources [<options>] <target> {<resourcefile> | <var>=<value>}

### Options

```
--addenv access environment for templating
-h, --help help for sources
-s, --settings stringArray settings file with variable settings (yaml)
--templater string templater to use (subst, spiff, go) (default "subst")
```


#### Access Specification Options

```
--access YAML blob access specification (YAML)
--accessHostname string hostname used for access
--accessRepository string repository URL
--accessType string type of blob access specification
--accessVersion string version for access specification
--addenv access environment for templating
--bucket string bucket name
--commit string git commit id
--digest string blob digest
--extra <name>=<value> source extra identity (default [])
--globalAccess YAML access specification for global access
-h, --help help for sources
--hint string (repository) hint for local artifacts
--mediaType string media type for artifact blob representation
--reference string reference name
--region string region name
--size int blob size
```


#### Input Specification Options

```
--hint string (repository) hint for local artifacts
--input YAML blob input specification (YAML)
--inputCompress compress option for input
Expand All @@ -34,15 +52,17 @@ ocm add sources [<options>] <target> {<resourcefile> | <var>=<value>}
--inputValues YAML YAML based generic values for inputs
--inputVariants stringArray (platform) variants for inputs
--inputVersion stringArray version info for inputs
--label <name>=<YAML> source label (leading * indicates signature relevant, optional version separated by @)
--mediaType string media type for artifact blob representation
```


#### Source Meta Data Options

```
--extra <name>=<value> source extra identity (default [])
--label <name>=<YAML> source label (leading * indicates signature relevant, optional version separated by @)
--name string source name
--reference string reference name
--region string region name
-s, --settings stringArray settings file with variable settings (yaml)
--size int blob size
--source YAML source meta data (yaml)
--templater string templater to use (subst, spiff, go) (default "subst")
--type string source type
--version string source version
```
Expand Down
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ module github.com/open-component-model/ocm

go 1.18

replace github.com/spf13/cobra => github.com/mandelsoft/cobra v1.4.1-0.20220816123314-fd3b703d78bf
replace (
github.com/spf13/cobra => github.com/mandelsoft/cobra v1.4.1-0.20220816123314-fd3b703d78bf
github.com/spf13/pflag => github.com/mandelsoft/pflag v0.0.0-20221101220350-bbff7bc4f7b5
)

require (
github.com/docker/cli v20.10.17+incompatible
Expand Down
11 changes: 2 additions & 9 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -815,10 +815,10 @@ github.com/mandelsoft/cobra v1.4.1-0.20220816123314-fd3b703d78bf/go.mod h1:IOw/A
github.com/mandelsoft/filepath v0.0.0-20200909114706-3df73d378d55/go.mod h1:n4xEiUD2HNHnn2w5ZKF0qgjDecHVCWAl5DxZ7+pcFU8=
github.com/mandelsoft/filepath v0.0.0-20220503095057-4432a2285b68 h1:99GWPlKVS110Cm+/YRVRaUJN5CpTeWFazWg2sXJdf70=
github.com/mandelsoft/filepath v0.0.0-20220503095057-4432a2285b68/go.mod h1:n4xEiUD2HNHnn2w5ZKF0qgjDecHVCWAl5DxZ7+pcFU8=
github.com/mandelsoft/logging v0.0.0-20221008125016-927a97d3006c h1:ZQV4QUvXKbbScq83qg1q2EILSP2ht1JvcVEMOoMaJtc=
github.com/mandelsoft/logging v0.0.0-20221008125016-927a97d3006c/go.mod h1:vxGpzOesdqLGRSWb4fz5DaH0ekJvkISst4qq6UZ2xFA=
github.com/mandelsoft/logging v0.0.0-20221012190501-e17f7961076e h1:vhm0x0KCMwjyrm/WkFXYw68QCWCBVzL1HVnOk0uOJa0=
github.com/mandelsoft/logging v0.0.0-20221012190501-e17f7961076e/go.mod h1:vxGpzOesdqLGRSWb4fz5DaH0ekJvkISst4qq6UZ2xFA=
github.com/mandelsoft/pflag v0.0.0-20221101220350-bbff7bc4f7b5 h1:yt0I6oxpTzxAPh+lwUinBiWibbmGXvQJdGzdu0sNMAM=
github.com/mandelsoft/pflag v0.0.0-20221101220350-bbff7bc4f7b5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/mandelsoft/spiff v1.7.0-beta-3 h1:AvZldpnctpyfQqtAA5uxokD5rlCK52mGAXxg7tnW5Ag=
github.com/mandelsoft/spiff v1.7.0-beta-3/go.mod h1:3Kg6qrggWO4oc1k++acd6xhcWisJ2YkzxpVZpuYONGg=
github.com/mandelsoft/vfs v0.0.0-20201002080026-d03d33d5889a/go.mod h1:74aV7kulg9C434HiI3zNALN79QHc9IZMN+SI4UdLn14=
Expand Down Expand Up @@ -1111,13 +1111,6 @@ github.com/spf13/jwalterweatherman v0.0.0-20141219030609-3d60171a6431/go.mod h1:
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
github.com/spf13/jwalterweatherman v1.1.0 h1:ue6voC5bR5F8YxI5S67j9i582FU4Qvo2bmqnqMYADFk=
github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo=
github.com/spf13/pflag v0.0.0-20170130214245-9ff6c6923cff/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/pflag v1.0.0/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/pflag v1.0.1-0.20171106142849-4c012f6dcd95/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/pflag v1.0.1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/viper v0.0.0-20150530192845-be5ff3e4840c/go.mod h1:A8kyI5cUJhb8N+3pkfONlcEcZbueH6nhAm0Fq7SrnBM=
github.com/spf13/viper v1.7.1 h1:pM5oEahlgWv/WnHXpgbKz7iLIxRf65tye2Ci+XFK5sk=
github.com/spf13/viper v1.7.1/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg=
Expand Down
Loading