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

Allow empty value for fields #1

Open
wants to merge 1 commit into
base: knative
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module sigs.k8s.io/controller-tools

go 1.21

toolchain go1.22.0
toolchain go1.22.10

require (
github.com/fatih/color v1.16.0
Expand Down
2 changes: 1 addition & 1 deletion pkg/markers/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,7 @@ func (d *Definition) Parse(rawMarker string) (interface{}, error) {

if d.Strict {
for argName, arg := range d.Fields {
if _, wasSeen := seen[argName]; !wasSeen && !arg.Optional {
if _, wasSeen := seen[argName]; !wasSeen && !arg.Optional && argName != "" {
scanner.Error(scanner, fmt.Sprintf("missing argument %q", argName))
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/markers/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ var _ = Describe("Parsing", func() {
It("should work with fiddled field names", parseTestCase{reg: &reg, raw: "+testing:custom={hi}", output: CustomType{Value: []string{"hi"}}}.Run)

It("should parse name-only markers", parseTestCase{reg: &reg, raw: "+testing:empty", output: struct{}{}}.Run)

Context("when parsing anonymous markers", func() {
It("should parse into literal-typed values", parseTestCase{reg: &reg, raw: "+testing:anonymous:literal=foo", output: "foo"}.Run)
It("should parse into literal-typed values", parseTestCase{reg: &reg, raw: "+testing:anonymous:literal=", output: ""}.Run)
It("should parse into named-typed values", parseTestCase{reg: &reg, raw: "+testing:anonymous:named=foo", output: wrappedMarkerVal("foo")}.Run)
It("shouldn't require any argument to an optional-valued marker", parseTestCase{reg: &reg, raw: "+testing:anonymousOptional", output: (*int)(nil)}.Run)
})
Expand Down