From b607709dfddff5142079fac0e3b4ebfa5161bc31 Mon Sep 17 00:00:00 2001 From: Hilmar Falkenberg Date: Thu, 22 Feb 2024 17:09:53 +0100 Subject: [PATCH] replace --- pkg/cobrautils/flag/replace.go | 16 ++++++++++++---- pkg/cobrautils/flagsets/types.go | 10 ++++------ 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/pkg/cobrautils/flag/replace.go b/pkg/cobrautils/flag/replace.go index 5cc0f2bebe..c12895b7f5 100644 --- a/pkg/cobrautils/flag/replace.go +++ b/pkg/cobrautils/flag/replace.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 flag import ( @@ -31,3 +27,15 @@ func IntVarPF(f *pflag.FlagSet, p *int, name, shorthand string, value int, usage f.IntVarP(p, name, shorthand, value, usage) return f.Lookup(name) } + +// PathVarPF is like PathVarP, but returns the created flag. +func PathVarPF(f *pflag.FlagSet, p *string, name, shorthand string, value string, usage string) *pflag.Flag { + PathVarP(f, p, name, shorthand, value, usage) + return f.Lookup(name) +} + +// PathArrayVarPF is like PathArrayVarP, but returns the created flag. +func PathArrayVarPF(f *pflag.FlagSet, p *[]string, name, shorthand string, value []string, usage string) *pflag.Flag { + PathArrayVarP(f, p, name, shorthand, value, usage) + return f.Lookup(name) +} diff --git a/pkg/cobrautils/flagsets/types.go b/pkg/cobrautils/flagsets/types.go index 719c7d7189..02db17cbf0 100644 --- a/pkg/cobrautils/flagsets/types.go +++ b/pkg/cobrautils/flagsets/types.go @@ -147,8 +147,6 @@ func (o *StringArrayOption) Value() interface{} { // PathOptionType ////////////////////////////////////////////////////////////////////////////// -type Path string - type PathOptionType struct { TypeOptionBase } @@ -171,13 +169,13 @@ func (s *PathOptionType) Create() Option { type PathOption struct { OptionBase - value string // TODO replace with Path? + value string } var _ Option = (*PathOption)(nil) func (o *PathOption) AddFlags(fs *pflag.FlagSet) { - o.TweakFlag(flag.StringVarPF(fs, &o.value, o.otyp.GetName(), "", "", o.otyp.GetDescription())) + o.TweakFlag(flag.PathVarPF(fs, &o.value, o.otyp.GetName(), "", "", o.otyp.GetDescription())) } func (o *PathOption) Value() interface{} { @@ -208,13 +206,13 @@ func (s *PathArrayOptionType) Create() Option { type PathArrayOption struct { OptionBase - value []string // TODO replace with Path? + value []string } 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())) + o.TweakFlag(flag.PathArrayVarPF(fs, &o.value, o.otyp.GetName(), "", nil, o.otyp.GetDescription())) } func (o *PathArrayOption) Value() interface{} {