diff --git a/config.go b/config.go index b5e3f07..9b54f26 100644 --- a/config.go +++ b/config.go @@ -9,6 +9,7 @@ import ( "path/filepath" "strings" + "github.com/go-viper/mapstructure/v2" "github.com/mitchellh/go-homedir" "github.com/rs/zerolog/log" "github.com/spf13/cobra" @@ -101,17 +102,24 @@ func InitViperConfigWithFlagSet(orgName, appName string, cfg interface{}, parsed // - Automatic logging configuration // - Configuration hot-reloading via Viper watchers func InitConfig(orgName, appName string, cmd *cobra.Command, cfgFile string, cfg interface{}) (*CommonConfig, error) { - viper.SetEnvPrefix(appName) - viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_", ".", "_")) + err := ValidateOrgAndAppName(orgName, appName) + if err != nil { + return nil, fmt.Errorf("error validating org and app name: %w", err) + } - err := viper.BindPFlags(cmd.Flags()) + v := viper.New() + + v.SetEnvPrefix(appName) + v.SetEnvKeyReplacer(strings.NewReplacer("-", "_", ".", "_")) + + err = v.BindPFlags(cmd.Flags()) if err != nil { return nil, err } if cfgFile != "" { // Use config file from the flag. - viper.SetConfigFile(cfgFile) + v.SetConfigFile(cfgFile) } else { systemConfigPath := filepath.Join("/etc", orgName, appName) @@ -125,14 +133,14 @@ func InitConfig(orgName, appName string, cmd *cobra.Command, cfgFile string, cfg fullCommandName := fmt.Sprintf("%v\n", strings.Join(commandParts(cmd), "-")) // Search config in home directory with name "config" (without extension). - viper.SetConfigName(fullCommandName) - viper.SetConfigType("yaml") - viper.AddConfigPath(systemConfigPath) - viper.AddConfigPath(homeConfigPath) + v.SetConfigName(fullCommandName) + v.SetConfigType("yaml") + v.AddConfigPath(systemConfigPath) + v.AddConfigPath(homeConfigPath) } - viper.AutomaticEnv() + v.AutomaticEnv() // If a config file is found, read it in. - err = viper.ReadInConfig() + err = v.ReadInConfig() // cobra.CheckErr(err) @@ -144,25 +152,25 @@ func InitConfig(orgName, appName string, cmd *cobra.Command, cfgFile string, cfg // Str("file", viper.ConfigFileUsed()). // Msg("error reading config") // } else { - viper.WatchConfig() + v.WatchConfig() } var c CommonConfig - err = viper.Unmarshal(&c) // , viper.DecodeHook(util.MaskedStringDecodeHook)) + err = UnmarshalConfig(v, &c) if err != nil { return nil, err } logging.ConfigureCmdLogger(c.Logging) - err = viper.Unmarshal(cfg, viper.DecodeHook(util.MaskedStringDecodeHook)) + err = UnmarshalConfig(v, cfg) if err != nil { return &c, err } log.Logger.Debug(). - Str("file", viper.ConfigFileUsed()). + Str("file", v.ConfigFileUsed()). Interface("config", cfg). Interface("common", c). Msg("initialising") @@ -170,6 +178,20 @@ func InitConfig(orgName, appName string, cmd *cobra.Command, cfgFile string, cfg return &c, nil } +// UnmarshalConfig unmarshals Viper configuration into the provided struct with custom decode hooks. +// +// It uses a composed decode hook to handle special types like MaskedString, time.Duration, +// net.IP, and net.IPNet. This allows for seamless unmarshalling of complex configuration fields. +func UnmarshalConfig(v *viper.Viper, c interface{}) error { + decodeHook := mapstructure.ComposeDecodeHookFunc( + util.MaskedStringDecodeHook, + mapstructure.StringToTimeDurationHookFunc(), + mapstructure.StringToIPHookFunc(), + mapstructure.StringToIPNetHookFunc(), + ) + return v.Unmarshal(c, viper.DecodeHook(decodeHook)) +} + // IsDocker detects if the application is running inside a Docker container. // // It checks for the presence of /.dockerenv file, which is a standard @@ -182,11 +204,73 @@ func IsDocker() bool { return false } +// ValidateName checks that the provided name is valid for use in configuration paths. +// +// It ensures that the name is not empty, does not contain path separators, +// does not start or end with spaces, and does not contain special characters. +// This validation helps prevent directory traversal issues and ensures clean config paths. +func ValidateName(name string) error { + if strings.TrimSpace(name) == "" { + return fmt.Errorf("name must not be empty") + } + + if strings.Contains(name, string(os.PathSeparator)) { + return fmt.Errorf("name must not contain path separators") + } + + if name == "." || name == ".." { + return fmt.Errorf("name must not be '.' or '..'") + } + if strings.HasPrefix(name, " ") { + return fmt.Errorf("name must not start with a space") + } + + if strings.HasSuffix(name, " ") { + return fmt.Errorf("name must not end with a space") + } + + if strings.Contains(name, " ") { + return fmt.Errorf("name must not contain spaces") + } + + specialChars := "/\\:*?\"<>|(){}[]!@#$%^&*+=~`" + for _, char := range specialChars { + if strings.Contains(name, string(char)) { + return fmt.Errorf("name must not contain special characters like %s", string(char)) + } + } + + return nil +} + +// ValidateOrgAndAppName validates that orgName and appName are acceptable names. +// +// It delegates to ValidateName, which ensures that names are non-empty, do not +// contain path separators, spaces (including leading or trailing spaces), or +// various special characters. This helps prevent issues when constructing +// configuration paths and other filesystem-related operations. +func ValidateOrgAndAppName(orgName, appName string) error { + if err := ValidateName(orgName); err != nil { + return fmt.Errorf("invalid orgName: %w", err) + } + + if err := ValidateName(appName); err != nil { + return fmt.Errorf("invalid appName: %w", err) + } + + return nil +} + // DefaultUserConfigPath returns the default configuration directory for the user. // // For non-Docker environments, it returns $HOME/.config/{orgName}/{appName} // and creates the directory if it doesn't exist with 0700 permissions. func DefaultUserConfigPath(orgName, appName string) (string, error) { + err := ValidateOrgAndAppName(orgName, appName) + if err != nil { + return "", fmt.Errorf("error validating org and app name: %w", err) + } + currentUser, err := user.Current() if err != nil { return "", err @@ -208,6 +292,11 @@ func DefaultPersistencePath(orgName, appName string) (string, error) { return "/persist", nil } + err := ValidateOrgAndAppName(orgName, appName) + if err != nil { + return "", fmt.Errorf("error validating org and app name: %w", err) + } + return DefaultUserConfigPath(orgName, appName) } @@ -295,7 +384,8 @@ func SetAppName(appName string) ContextOpt { } } -func getOrgName(ctx context.Context) string { +// OrgNameFromContext retrieves the organization name from the context. +func OrgNameFromContext(ctx context.Context) string { orgName, ok := ctx.Value(orgNameContextKey{}).(string) if !ok { return "" @@ -303,7 +393,8 @@ func getOrgName(ctx context.Context) string { return orgName } -func getAppName(ctx context.Context) string { +// AppNameFromContext retrieves the application name from the context. +func AppNameFromContext(ctx context.Context) string { appName, ok := ctx.Value(appNameContextKey{}).(string) if !ok { return "" @@ -320,8 +411,8 @@ type CobraOpt[T any] func(*T) // and passes configured values to the execution function. func CobraRunEWithConfig[T any](execFunc func(context.Context, *T) error, cfg *T) func(cmd *cobra.Command, args []string) error { return func(cmd *cobra.Command, args []string) error { - orgName := getOrgName(cmd.Context()) - appName := getAppName(cmd.Context()) + orgName := OrgNameFromContext(cmd.Context()) + appName := AppNameFromContext(cmd.Context()) var configFile string configFlag := cmd.Flag("config") @@ -341,8 +432,8 @@ func CobraRunEWithConfig[T any](execFunc func(context.Context, *T) error, cfg *T // applies functional options to modify configuration, and passes configured values to the execution function. func CobraRunE[T any](execFunc func(*T) error, opt ...CobraOpt[T]) func(cmd *cobra.Command, args []string) error { return func(cmd *cobra.Command, args []string) error { - orgName := getOrgName(cmd.Context()) - appName := getAppName(cmd.Context()) + orgName := OrgNameFromContext(cmd.Context()) + appName := AppNameFromContext(cmd.Context()) var cfg T diff --git a/config_test.go b/config_test.go index bcdae4d..3fda3a5 100644 --- a/config_test.go +++ b/config_test.go @@ -1,14 +1,23 @@ +// Package cli_test contains unit tests for the cli package. +// TODO: need to remove reliance on file system for config path tests, +// need to refactor to allow in-memory testing. package cli_test import ( "context" + "net" "os" "path/filepath" "strings" "testing" + "time" - "github.com/dioad/cli" "github.com/spf13/cobra" + "github.com/spf13/pflag" + "github.com/spf13/viper" + "github.com/stretchr/testify/assert" + + "github.com/dioad/cli" ) // TestIsDocker verifies Docker detection logic. @@ -46,32 +55,101 @@ func TestIsDocker(t *testing.T) { } } +func TestValidateName(t *testing.T) { + tests := []struct { + label string + name string + wantErr bool + }{ + { + label: "valid names", + name: "validname", + wantErr: false, + }, + { + label: "empty org name", + name: "", + wantErr: true, + }, + { + label: "names with spaces", + name: "org with spaces", + wantErr: true, + }, + { + label: "names with special characters", + name: "org/\\:*?\"<>|(){}[]!@#$%^&*+=~`", + wantErr: true, + }, + { + label: "names with unicode characters", + name: "组织", + wantErr: false, // Assuming unicode is allowed + }, + {label: "names with dashes and underscores", + name: "org-name_with-dash", + wantErr: false, + }, + { + label: "names with leading spaces", + name: " orgname", + wantErr: true, + }, + { + label: "names with trailing spaces", + name: "orgname ", + wantErr: true, + }, + { + label: "names with only spaces", + name: " ", + wantErr: true, + }, + { + label: "no path separators", + name: "org/name", + wantErr: true, + }, + } + + for _, tt := range tests { + t.Run(tt.label, func(t *testing.T) { + err := cli.ValidateName(tt.name) + if (err != nil) != tt.wantErr { + t.Errorf("validateName() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + // TestDefaultUserConfigPath verifies config path generation and creation. func TestDefaultUserConfigPath(t *testing.T) { orgName := "testorg" appName := "testapp" - path, err := cli.DefaultUserConfigPath(orgName, appName) + filePath, err := cli.DefaultUserConfigPath(orgName, appName) if err != nil { t.Fatalf("DefaultUserConfigPath() error = %v", err) } - if path == "" { + if filePath == "" { t.Error("DefaultUserConfigPath() returned empty path") } // Verify directory was created - if _, err := os.Stat(path); err != nil { + if _, err := os.Stat(filePath); err != nil { t.Fatalf("DefaultUserConfigPath() created path not found: %v", err) } // Verify path contains org and app names - if !strings.Contains(path, orgName) { - t.Errorf("DefaultUserConfigPath() path doesn't contain orgName: %s", path) + if !strings.Contains(filePath, orgName) { + t.Errorf("DefaultUserConfigPath() path doesn't contain orgName: %s", filePath) } - // Cleanup - os.RemoveAll(path) + err = os.RemoveAll(filepath.Dir(filePath)) + if err != nil { + t.Fatalf("Failed to cleanup persistence file: %v", err) + } } // TestDefaultConfigPath returns the correct path based on environment. @@ -79,17 +157,17 @@ func TestDefaultConfigPath(t *testing.T) { orgName := "testorg" appName := "testapp" - path, err := cli.DefaultConfigPath(orgName, appName) + filePath, err := cli.DefaultConfigPath(orgName, appName) if err != nil { t.Fatalf("DefaultConfigPath() error = %v", err) } - if path == "" { + if filePath == "" { t.Error("DefaultConfigPath() returned empty path") } // Verify path is valid - if _, err := os.Stat(path); err != nil { + if _, err := os.Stat(filePath); err != nil { if !os.IsNotExist(err) { t.Fatalf("DefaultConfigPath() stat error: %v", err) } @@ -97,7 +175,10 @@ func TestDefaultConfigPath(t *testing.T) { } // Cleanup - os.RemoveAll(path) + err = os.RemoveAll(filepath.Dir(filePath)) + if err != nil { + t.Fatalf("Failed to cleanup persistence file: %v", err) + } } // TestDefaultPersistencePath returns the correct path. @@ -105,17 +186,20 @@ func TestDefaultPersistencePath(t *testing.T) { orgName := "testorg" appName := "testapp" - path, err := cli.DefaultPersistencePath(orgName, appName) + filePath, err := cli.DefaultPersistencePath(orgName, appName) if err != nil { t.Fatalf("DefaultPersistencePath() error = %v", err) } - if path == "" { + if filePath == "" { t.Error("DefaultPersistencePath() returned empty path") } // Cleanup - os.RemoveAll(path) + err = os.RemoveAll(filepath.Dir(filePath)) + if err != nil { + t.Fatalf("Failed to cleanup persistence file: %v", err) + } } // TestDefaultConfigFile returns the correct file path. @@ -139,7 +223,10 @@ func TestDefaultConfigFile(t *testing.T) { } // Cleanup - os.RemoveAll(filepath.Dir(filePath)) + err = os.RemoveAll(filepath.Dir(filePath)) + if err != nil { + t.Fatalf("Failed to cleanup persistence file: %v", err) + } } // TestDefaultPersistenceFile returns the correct file path. @@ -162,7 +249,10 @@ func TestDefaultPersistenceFile(t *testing.T) { } // Cleanup - os.RemoveAll(filepath.Dir(filePath)) + err = os.RemoveAll(filepath.Dir(filePath)) + if err != nil { + t.Fatalf("Failed to cleanup persistence file: %v", err) + } } // TestContext creates and retrieves context values. @@ -191,11 +281,8 @@ func TestContext(t *testing.T) { // TestContextWithNilBase creates context with nil base context. func TestContextWithNilBase(t *testing.T) { - ctx := cli.Context(nil) - - if ctx == nil { - t.Error("Context(nil) returned nil") - } + ctx := cli.Context(nil) //lint:ignore SA1012 specifically testing behaviour is nil is passed + assert.NotNil(t, ctx) // Verify context is usable select { @@ -262,7 +349,7 @@ func TestNewCommand(t *testing.T) { ) if cmd == nil { - t.Error("NewCommand() returned nil command") + t.Fatal("NewCommand() returned nil command") } if cmd.Use != "test" { @@ -294,13 +381,13 @@ func TestNewCommandWithConfigFlag(t *testing.T) { ) if cmd == nil { - t.Error("NewCommand() returned nil") + t.Fatal("NewCommand() returned nil") } // Verify config flag was added configFlag := cmd.Flag("config") if configFlag == nil { - t.Error("NewCommand() did not add config flag") + t.Fatal("NewCommand() did not add config flag") } if configFlag.Shorthand != "c" { @@ -317,10 +404,58 @@ func TestWithConfigFlag(t *testing.T) { configFlag := cmd.Flag("config") if configFlag == nil { - t.Error("WithConfigFlag() did not add config flag") + t.Fatal("WithConfigFlag() did not add config flag") } if configFlag.DefValue != "my-config.yaml" { t.Errorf("config flag default = %s, want my-config.yaml", configFlag.DefValue) } } + +func TestUnmarshalConfig(t *testing.T) { + type TestConfig struct { + Name string `mapstructure:"name"` + Port int `mapstructure:"port"` + Duration time.Duration `mapstructure:"duration"` + IP net.IP `mapstructure:"ip"` + CIDR *net.IPNet `mapstructure:"cidr"` + } + + cfg := &TestConfig{} + + flags := &pflag.FlagSet{} + flags.String("name", "", "") + flags.String("port", "", "") + flags.String("duration", "", "") + flags.String("ip", "", "") + flags.String("cidr", "", "") + + err := flags.Parse([]string{ + "--name=test", + "--port=8080", + "--duration=60s", + "--ip=1.2.3.4", + "--cidr=2.3.4.5/24", + }) + assert.NoErrorf(t, err, "flag parse error") + + v := viper.New() + + err = v.BindPFlags(flags) + assert.NoError(t, err) + + err = cli.UnmarshalConfig(v, cfg) + assert.NoErrorf(t, err, "UnmarshalConfig() error") + + assert.Equal(t, cfg.Name, "test") + assert.Equal(t, "test", cfg.Name) + assert.Equal(t, 8080, cfg.Port) + assert.Equal(t, 60*time.Second, cfg.Duration) + + ip := net.ParseIP("1.2.3.4") + assert.Equal(t, ip, cfg.IP) + + _, cidr, err := net.ParseCIDR("2.3.4.5/24") + assert.NoError(t, err) + assert.Equal(t, cidr, cfg.CIDR) +} diff --git a/go.mod b/go.mod index eb31e63..d439d33 100644 --- a/go.mod +++ b/go.mod @@ -6,20 +6,21 @@ replace github.com/urfave/sflags => github.com/patdowney/sflags v0.4.2-patdowney require ( github.com/dioad/util v0.7.0 + github.com/go-viper/mapstructure/v2 v2.5.0 github.com/mitchellh/go-homedir v1.1.0 github.com/rs/zerolog v1.34.0 github.com/spf13/cobra v1.10.2 github.com/spf13/pflag v1.0.10 github.com/spf13/viper v1.21.0 + github.com/stretchr/testify v1.11.1 github.com/urfave/sflags v0.4.1 gopkg.in/natefinch/lumberjack.v2 v2.2.1 ) require ( github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect - github.com/dioad/generics v0.0.7 // indirect + github.com/dioad/generics v0.0.8 // indirect github.com/fsnotify/fsnotify v1.9.0 // indirect - github.com/go-viper/mapstructure/v2 v2.5.0 // indirect github.com/google/go-cmp v0.7.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/mattn/go-colorable v0.1.14 // indirect @@ -32,8 +33,8 @@ require ( github.com/spf13/cast v1.10.0 // indirect github.com/subosito/gotenv v1.6.0 // indirect go.yaml.in/yaml/v3 v3.0.4 // indirect - golang.org/x/sys v0.40.0 // indirect - golang.org/x/text v0.33.0 // indirect + golang.org/x/sys v0.41.0 // indirect + golang.org/x/text v0.34.0 // indirect gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index b6d8e8d..2b67820 100644 --- a/go.sum +++ b/go.sum @@ -2,16 +2,14 @@ github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSV github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/dioad/generics v0.0.7 h1:a4yxCB+GDZ6NodxYnkikgOb6Lq9RBsKWVahkS97F5eg= -github.com/dioad/generics v0.0.7/go.mod h1:NFn4N/41m2Ln8xjKm6c9ieZQeKohyCEg0RfQg34aVRg= +github.com/dioad/generics v0.0.8 h1:16B4qDVZZP+wsTeDT+9ecmIyF8GuFrwdrvm5a9l3Qa4= +github.com/dioad/generics v0.0.8/go.mod h1:NFn4N/41m2Ln8xjKm6c9ieZQeKohyCEg0RfQg34aVRg= github.com/dioad/util v0.7.0 h1:DdSits6ZE/m6FSkSHLrPFehJJT7VlDGxxHkiZQ4xzaQ= github.com/dioad/util v0.7.0/go.mod h1:FqqqoXSEV4Mh2DEYzw4rsWReDvyykQItBgrsj6w14FY= github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k= github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0= -github.com/go-viper/mapstructure/v2 v2.4.0 h1:EBsztssimR/CONLSZZ04E8qAkxNYq4Qp9LvH92wZUgs= -github.com/go-viper/mapstructure/v2 v2.4.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM= github.com/go-viper/mapstructure/v2 v2.5.0 h1:vM5IJoUAy3d7zRSVtIwQgBj7BiWtMPfmPEgAXnvj1Ro= github.com/go-viper/mapstructure/v2 v2.5.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= @@ -54,8 +52,6 @@ github.com/spf13/afero v1.15.0 h1:b/YBCLWAJdFWJTN9cLhiXXcD7mzKn9Dm86dNnfyQw1I= github.com/spf13/afero v1.15.0/go.mod h1:NC2ByUVxtQs4b3sIUphxK0NioZnmxgyCrfzeuq8lxMg= github.com/spf13/cast v1.10.0 h1:h2x0u2shc1QuLHfxi+cTJvs30+ZAHOGRic8uyGTDWxY= github.com/spf13/cast v1.10.0/go.mod h1:jNfB8QC9IA6ZuY2ZjDp0KtFO2LZZlg4S/7bzP6qqeHo= -github.com/spf13/cobra v1.10.1 h1:lJeBwCfmrnXthfAupyUTzJ/J4Nc1RsHC/mSRU2dll/s= -github.com/spf13/cobra v1.10.1/go.mod h1:7SmJGaTHFVBY0jW4NXGluQoLvhqFQM+6XSKD+P4XaB0= github.com/spf13/cobra v1.10.2 h1:DMTTonx5m65Ic0GOoRY2c16WCbHxOOw6xxezuLaBpcU= github.com/spf13/cobra v1.10.2/go.mod h1:7C1pvHqHw5A4vrJfjNwvOdzYu0Gml16OCs2GRiTUUS4= github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= @@ -72,14 +68,10 @@ go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.37.0 h1:fdNQudmxPjkdUTPnLn5mdQv7Zwvbvpaxqs831goi9kQ= -golang.org/x/sys v0.37.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= -golang.org/x/sys v0.40.0 h1:DBZZqJ2Rkml6QMQsZywtnjnnGvHza6BTfYFWY9kjEWQ= -golang.org/x/sys v0.40.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= -golang.org/x/text v0.30.0 h1:yznKA/E9zq54KzlzBEAWn1NXSQ8DIp/NYMy88xJjl4k= -golang.org/x/text v0.30.0/go.mod h1:yDdHFIX9t+tORqspjENWgzaCVXgk0yYnYuSZ8UzzBVM= -golang.org/x/text v0.33.0 h1:B3njUFyqtHDUI5jMn1YIr5B0IE2U0qck04r6d4KPAxE= -golang.org/x/text v0.33.0/go.mod h1:LuMebE6+rBincTi9+xWTY8TztLzKHc/9C1uBCG27+q8= +golang.org/x/sys v0.41.0 h1:Ivj+2Cp/ylzLiEU89QhWblYnOE9zerudt9Ftecq2C6k= +golang.org/x/sys v0.41.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= +golang.org/x/text v0.34.0 h1:oL/Qq0Kdaqxa1KbNeMKwQq0reLCCaFtqu2eNuSeNHbk= +golang.org/x/text v0.34.0/go.mod h1:homfLqTYRFyVYemLBFl5GgL/DWEiH5wcsQ5gSh1yziA= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= diff --git a/integration_test.go b/integration_test.go index eefcb96..e9336e7 100644 --- a/integration_test.go +++ b/integration_test.go @@ -6,9 +6,10 @@ import ( "os/exec" "testing" + "github.com/spf13/cobra" + "github.com/dioad/cli" "github.com/dioad/cli/logging" - "github.com/spf13/cobra" ) // TestFullIntegration demonstrates a complete integration scenario. @@ -60,10 +61,6 @@ func TestFullIntegration(t *testing.T) { rootCmd.AddCommand(subCmd) // Verify the structure - if rootCmd == nil { - t.Fatal("Root command is nil") - } - if len(rootCmd.Commands()) == 0 { t.Error("No subcommands added") }