Skip to content

Commit

Permalink
fix: remove config limitation (#1984)
Browse files Browse the repository at this point in the history
* fix: remove config limitation

Signed-off-by: charankamarapu <kamarapucharan@gmail.com>

* fix: remove config limitation

Signed-off-by: charankamarapu <kamarapucharan@gmail.com>

---------

Signed-off-by: charankamarapu <kamarapucharan@gmail.com>
  • Loading branch information
charankamarapu committed Jun 21, 2024
1 parent 36af420 commit 0538c5f
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions cli/provider/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ func (c *CmdConfigurator) AddFlags(cmd *cobra.Command) error {
return errors.New(errMsg)
}
case "record", "test":
cmd.Flags().String("configPath", ".", "Path to the local directory where keploy configuration file is stored")
cmd.Flags().StringP("path", "p", ".", "Path to local directory where generated testcases/mocks are stored")
cmd.Flags().Uint32("port", c.cfg.Port, "GraphQL server port used for executing testcases in unit test library integration")
cmd.Flags().Uint32("proxyPort", c.cfg.ProxyPort, "Port used by the Keploy proxy server to intercept the outgoing dependency calls")
Expand Down Expand Up @@ -264,6 +263,8 @@ func (c *CmdConfigurator) AddFlags(cmd *cobra.Command) error {
default:
return errors.New("unknown command name")
}
cmd.Flags().String("configPath", ".", "Path to the local directory where keploy configuration file is stored")

return nil
}

Expand Down Expand Up @@ -304,25 +305,24 @@ func (c *CmdConfigurator) ValidateFlags(ctx context.Context, cmd *cobra.Command)
utils.LogError(c.logger, err, errMsg)
return errors.New(errMsg)
}
if cmd.Name() == "test" || cmd.Name() == "record" {
configPath, err := cmd.Flags().GetString("configPath")
if err != nil {
utils.LogError(c.logger, nil, "failed to read the config path")
return err
}
viper.SetConfigName("keploy")
viper.SetConfigType("yml")
viper.AddConfigPath(configPath)
if err := viper.ReadInConfig(); err != nil {
var configFileNotFoundError viper.ConfigFileNotFoundError
if !errors.As(err, &configFileNotFoundError) {
errMsg := "failed to read config file"
utils.LogError(c.logger, err, errMsg)
return errors.New(errMsg)
}
c.logger.Info("config file not found; proceeding with flags only")
configPath, err := cmd.Flags().GetString("configPath")
if err != nil {
utils.LogError(c.logger, nil, "failed to read the config path")
return err
}
viper.SetConfigName("keploy")
viper.SetConfigType("yml")
viper.AddConfigPath(configPath)
if err := viper.ReadInConfig(); err != nil {
var configFileNotFoundError viper.ConfigFileNotFoundError
if !errors.As(err, &configFileNotFoundError) {
errMsg := "failed to read config file"
utils.LogError(c.logger, err, errMsg)
return errors.New(errMsg)
}
c.logger.Info("config file not found; proceeding with flags only")
}

if err := viper.Unmarshal(c.cfg); err != nil {
errMsg := "failed to unmarshal the config"
utils.LogError(c.logger, err, errMsg)
Expand Down

0 comments on commit 0538c5f

Please sign in to comment.