Skip to content

Commit

Permalink
Merge pull request #167 from lets-cli/fix-bug-run-ref-in-depends
Browse files Browse the repository at this point in the history
fix bug - run ref in depends
  • Loading branch information
kindermax authored Feb 16, 2022
2 parents 2894fa5 + 3da8052 commit dec4c27
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
10 changes: 7 additions & 3 deletions config/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ func withColor(msg string) string {
}

// Validate loaded config.
// nolint:revive
func validate(config *config.Config, letsVersion string) error {
if err := validateVersion(config, letsVersion); err != nil {
return err
}

if err := validateCommandInDependsExists(config); err != nil {
return err
}
Expand All @@ -30,7 +35,7 @@ func validate(config *config.Config, letsVersion string) error {
return err
}

return validateVersion(config, letsVersion)
return nil
}

func validateVersion(cfg *config.Config, letsVersion string) error {
Expand All @@ -49,8 +54,7 @@ func validateVersion(cfg *config.Config, letsVersion string) error {
return fmt.Errorf("failed to parse lets version: %w", err)
}

// in dev (where version is 0.0.0-dev) this predicate will be always false
isDev := letsVersionParsed.String() == "0.0.0-dev"
isDev := letsVersionParsed.PreRelease == "dev"
if letsVersionParsed.LessThan(*cfgVersionParsed) && !isDev {
return fmt.Errorf(
"config version '%s' is not compatible with 'lets' version '%s'. "+
Expand Down
8 changes: 7 additions & 1 deletion runner/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,16 @@ func NewRunner(cmd *config.Command, cfg *config.Config, out io.Writer) *Runner {
}

func NewChildRunner(cmd *config.Command, parentRunner *Runner) *Runner {
cfg := parentRunner.cfg
if cmd.Ref != "" {
newCmd := cfg.Commands[cmd.Ref].FromRef(*cmd, cfg)
cmd = &newCmd
}

return &Runner{
cmd: cmd,
parentCmd: parentRunner.cmd,
cfg: parentRunner.cfg,
cfg: cfg,
out: parentRunner.out,
}
}
Expand Down
7 changes: 7 additions & 0 deletions tests/command_depends.bats
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,10 @@ setup() {
assert_line --index 0 "Hello world with level DEBUG"
assert_line --index 1 "Override env"
}

@test "command_depends: ref works in depends" {
run lets with-ref-in-depends
assert_success
assert_line --index 0 "Hello Developer with level INFO"
assert_line --index 1 "I have ref in depends"
}
8 changes: 8 additions & 0 deletions tests/command_depends/lets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,13 @@ commands:
LEVEL: INFO
cmd: echo Hello ${LETSOPT_NAME:-world} with level ${LEVEL}

greet-dev:
ref: greet
args: Developer

bar:
cmd: echo Bar

with-ref-in-depends:
depends: [greet-dev]
cmd: echo I have ref in depends

0 comments on commit dec4c27

Please sign in to comment.