mirror of
https://github.com/turbot/steampipe.git
synced 2025-12-19 18:12:43 -05:00
* Add test for #4707: hideRootFlags should handle non-existent flags * Fix #4707: Add nil check in hideRootFlags
This commit is contained in:
@@ -80,7 +80,9 @@ func InitCmd() {
|
||||
|
||||
func hideRootFlags(flags ...string) {
|
||||
for _, flag := range flags {
|
||||
rootCmd.Flag(flag).Hidden = true
|
||||
if f := rootCmd.Flag(flag); f != nil {
|
||||
f.Hidden = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
19
cmd/root_test.go
Normal file
19
cmd/root_test.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
// TestHideRootFlags_NonExistentFlag tests that hideRootFlags handles non-existent flags gracefully
|
||||
// Bug #4707: hideRootFlags panics when called with a flag that doesn't exist
|
||||
func TestHideRootFlags_NonExistentFlag(t *testing.T) {
|
||||
// Initialize the root command
|
||||
InitCmd()
|
||||
|
||||
// Test that calling hideRootFlags with a non-existent flag should NOT panic
|
||||
assert.NotPanics(t, func() {
|
||||
hideRootFlags("non-existent-flag")
|
||||
}, "hideRootFlags should handle non-existent flags without panicking")
|
||||
}
|
||||
Reference in New Issue
Block a user