From 92fee7bff6eac8833c0519e807ae328883c7b4ff Mon Sep 17 00:00:00 2001 From: Pat Downey Date: Wed, 4 Nov 2026 10:12:39 +0000 Subject: [PATCH] fix(deps): require upstream urfave/sflags instead of the patdowney fork The InheritHidden/InheritDeprecated options the fork added were merged upstream (urfave/sflags b88b11d) but are not yet in a tagged release. Require that commit by pseudo-version and drop the replace directive, so consumers get the fix through normal version selection instead of each carrying their own replace (which also blocks `go install module@latest`). Pinned to b88b11d rather than main HEAD to avoid also taking the later strings.SplitN value-splitting change unreviewed. Adds a test pinning the nested hidden/deprecated flag inheritance that consumers rely on to keep config blocks out of --help. Refs #17 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01SS4MAynosZMkKwVBuvNmA9 --- command_test.go | 52 +++++++++++++++++++++++++++++++++++++++++++++++++ go.mod | 4 +--- go.sum | 4 ++-- 3 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 command_test.go diff --git a/command_test.go b/command_test.go new file mode 100644 index 0000000..348574a --- /dev/null +++ b/command_test.go @@ -0,0 +1,52 @@ +package cli + +import ( + "context" + "testing" + + "github.com/spf13/cobra" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +type nestedFlagBlock struct { + Address string `desc:"listen address" mapstructure:"address"` + Port int `desc:"listen port" mapstructure:"port"` +} + +type inheritFlagsConfig struct { + Visible string `desc:"a visible flag" mapstructure:"visible"` + Hidden nestedFlagBlock `flag:",hidden" mapstructure:"hidden"` + Deprecated nestedFlagBlock `flag:",deprecated" mapstructure:"deprecated"` +} + +// TestNewCommand_NestedFlagsInheritParentTags pins the behaviour consumers +// rely on to keep whole config blocks out of --help: a hidden or deprecated +// tag on a struct field applies to every flag generated from its fields. +func TestNewCommand_NestedFlagsInheritParentTags(t *testing.T) { + t.Parallel() + + cmd := NewCommand(&cobra.Command{Use: "test"}, func(context.Context, *inheritFlagsConfig) error { return nil }, &inheritFlagsConfig{}) + + tests := []struct { + flag string + wantHidden bool + wantDeprecated bool + }{ + {flag: "visible"}, + {flag: "hidden-address", wantHidden: true}, + {flag: "hidden-port", wantHidden: true}, + {flag: "deprecated-address", wantDeprecated: true}, + {flag: "deprecated-port", wantDeprecated: true}, + } + for _, tt := range tests { + t.Run(tt.flag, func(t *testing.T) { + t.Parallel() + + f := cmd.Flags().Lookup(tt.flag) + require.NotNil(t, f, "flag --%s was not registered", tt.flag) + assert.Equal(t, tt.wantHidden, f.Hidden, "hidden") + assert.Equal(t, tt.wantDeprecated, f.Deprecated != "", "deprecated") + }) + } +} diff --git a/go.mod b/go.mod index 237a578..309cc89 100644 --- a/go.mod +++ b/go.mod @@ -2,8 +2,6 @@ module github.com/dioad/cli go 1.25.0 -replace github.com/urfave/sflags => github.com/patdowney/sflags v0.4.2-patdowney - require ( github.com/dioad/config v0.1.0 github.com/mitchellh/go-homedir v1.1.0 @@ -12,7 +10,7 @@ require ( github.com/spf13/pflag v1.0.10 github.com/spf13/viper v1.21.0 github.com/stretchr/testify v1.12.1 - github.com/urfave/sflags v0.4.1 + github.com/urfave/sflags v0.4.2-0.20250718033027-b88b11ddd16a gopkg.in/natefinch/lumberjack.v2 v2.2.1 ) diff --git a/go.sum b/go.sum index 85984b7..566cd36 100644 --- a/go.sum +++ b/go.sum @@ -25,8 +25,6 @@ github.com/mattn/go-isatty v0.0.22 h1:j8l17JJ9i6VGPUFUYoTUKPSgKe/83EYU2zBC7YNKMw github.com/mattn/go-isatty v0.0.22/go.mod h1:ZXfXG4SQHsB/w3ZeOYbR0PrPwLy+n6xiMrJlRFqopa4= github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= -github.com/patdowney/sflags v0.4.2-patdowney h1:EKBusbuHXXq3+cxQS7dIcOVxxuJq2qXdqvjWB8ZyH18= -github.com/patdowney/sflags v0.4.2-patdowney/go.mod h1:NCIz2mBC+woyrkl88PeiKAuQUKJdEre2Y4at5SreAeU= github.com/pelletier/go-toml/v2 v2.3.1 h1:MYEvvGnQjeNkRF1qUuGolNtNExTDwct51yp7olPtrEc= github.com/pelletier/go-toml/v2 v2.3.1/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY= github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ= @@ -51,6 +49,8 @@ github.com/stretchr/testify v1.12.1 h1:EuwCh5fleGS7H32xRwO3wRGT7DxrDhLAT6FF8MpWD github.com/stretchr/testify v1.12.1/go.mod h1:MDEgiDPPsNp5cuIrHPPCyornHKgEVbtFUmoNlxoYthg= github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= +github.com/urfave/sflags v0.4.2-0.20250718033027-b88b11ddd16a h1:+5ZNCBFsB5BpcX/mPAtqlCvSiryv6Ed2D4L4IS5G55Q= +github.com/urfave/sflags v0.4.2-0.20250718033027-b88b11ddd16a/go.mod h1:NCIz2mBC+woyrkl88PeiKAuQUKJdEre2Y4at5SreAeU= go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg= go.yaml.in/yaml/v3 v3.0.5 h1:N6y/pJk8buWs9NY5ERU2HSMfm+IuD/OtfdAnq6kESPw= go.yaml.in/yaml/v3 v3.0.5/go.mod h1:HVTZu1O7/Vkt2N+BFy8Zza+lnLsABggaTM2ZpNIGuKg=