Skip to content

Commit

Permalink
fixed commands & config
Browse files Browse the repository at this point in the history
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
  • Loading branch information
fredbi committed Nov 13, 2023
1 parent da84522 commit be95b69
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
11 changes: 10 additions & 1 deletion cli/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,13 @@ func (c *Command) bindFlagsWithConfig(cfg *viper.Viper) {
}
}

// Execute the command, with a default context.Background().
//
// It ensures that all injectables are in the context.
func (c *Command) Execute() error {
return c.ExecuteContext(context.Background())
}

// ExecuteWithArgs is a convenience wrapper to execute a command with preset args.
//
// This is primarily intended for testing commands.
Expand All @@ -174,5 +181,7 @@ func (c *Command) ExecuteWithArgs(args ...string) error {
//
// It ensures that all injectables are in the context.
func (c *Command) ExecuteContext(ctx context.Context) error {
return c.Command.ExecuteContext(c.injectedContext(ctx))
ctx = c.injectedContext(ctx)

return c.Command.ExecuteContext(ctx)
}
9 changes: 4 additions & 5 deletions config/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (l *Loader) LoadForEnv(env string) (*viper.Viper, error) {
}

func (l *Loader) walkFunc(cfg *viper.Viper) filepath.WalkFunc {
return func(pth string, info os.FileInfo, err error) error {
return func(pth string, info os.FileInfo, _ error) error {
if info.IsDir() {
return nil
}
Expand Down Expand Up @@ -151,11 +151,11 @@ func (l *Loader) parseConfigFromExt(pth, ext string) (map[string]interface{}, er
switch ext {
case "yaml", "yml":
if err = yaml.Unmarshal(buf, &toMerge); err != nil {
return nil, err
return nil, fmt.Errorf("in file: %s.%s: %w", pth, ext, err)
}
case "json":
if err = json.Unmarshal(buf, &toMerge); err != nil {
return nil, err
return nil, fmt.Errorf("in file: %s.%s: %w", pth, ext, err)
}
}

Expand Down Expand Up @@ -189,13 +189,12 @@ LOOP:
}

if os.IsNotExist(err) {
cwd = filepath.Dir(cwd)

continue
}

return "", err
}
cwd = filepath.Dir(cwd)
}

if !found {
Expand Down

0 comments on commit be95b69

Please sign in to comment.