Skip to content

Commit

Permalink
replace
Browse files Browse the repository at this point in the history
  • Loading branch information
hilmarf committed Feb 22, 2024
1 parent 7f6dfa2 commit b607709
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
16 changes: 12 additions & 4 deletions pkg/cobrautils/flag/replace.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 flag

import (
Expand Down Expand Up @@ -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)
}
10 changes: 4 additions & 6 deletions pkg/cobrautils/flagsets/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,6 @@ func (o *StringArrayOption) Value() interface{} {

// PathOptionType //////////////////////////////////////////////////////////////////////////////

type Path string

type PathOptionType struct {
TypeOptionBase
}
Expand All @@ -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{} {
Expand Down Expand Up @@ -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{} {
Expand Down

0 comments on commit b607709

Please sign in to comment.