From ba94b93a422d60152a02cb60c88156c2cecde8dd Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Thu, 15 Aug 2024 16:07:06 -0400 Subject: [PATCH] cmd/probs: fix handling of optional directory argument If a positional argument is passed to 'bbi probs', the command looks there for model files. Otherwise it falls back to using the current working directory. The handling of the argument is incorrect unless it happens to point to the current working directory. The model files come back relative from ListModels, so modSummaries will look in the current directory for them despite the directory being specified. Fix the error by making the files absolute before passing them to modSummaries. --- cmd/project.go | 9 ++++++++- integration/nmless/bbi_probs_test.go | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/cmd/project.go b/cmd/project.go index 0fd7eb87..0df63cdc 100644 --- a/cmd/project.go +++ b/cmd/project.go @@ -58,7 +58,14 @@ func probs(_ *cobra.Command, args []string) error { if err != nil { return err } - modelSummaries := modSummaries(AppFs, modelFiles) + + filesAbs := make([]string, len(modelFiles)) + for i := range modelFiles { + filesAbs[i] = filepath.Join(dirPath, modelFiles[i]) + } + + modelSummaries := modSummaries(AppFs, filesAbs) + if Json { err = utils.PrintJSON(modelSummaries) if err != nil { diff --git a/integration/nmless/bbi_probs_test.go b/integration/nmless/bbi_probs_test.go index 032ec696..d7c7b036 100644 --- a/integration/nmless/bbi_probs_test.go +++ b/integration/nmless/bbi_probs_test.go @@ -121,6 +121,24 @@ func TestProbs(tt *testing.T) { } } }) + + t.Run("directory argument", func(t *wrapt.T) { + cmd1 := exec.Command("bbi", "nonmem", "probs") + cmd1.Dir = dir + + bs1, err := cmd1.Output() + if err != nil { + t.Fatal(err) + } + + cmd2 := exec.Command("bbi", "nonmem", "probs", dir) + bs2, err := cmd2.Output() + if err != nil { + t.Fatal(err) + } + + t.A.Equal(bs1, bs2) + }) } func TestProbsErrors(tt *testing.T) {