diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c1c3c6..76f59e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.2.1] + +- [(GH-163)](https://github.com/puppetlabs/pct/issues/341) `--codedir {string}` flag is omitted, use working directory + ## [0.2.0] ### Added diff --git a/cmd/exec/exec.go b/cmd/exec/exec.go index 326314b..7200a18 100644 --- a/cmd/exec/exec.go +++ b/cmd/exec/exec.go @@ -2,6 +2,7 @@ package exec import ( "fmt" + "os" "os/user" "path/filepath" "strings" @@ -97,6 +98,14 @@ func preExecute(cmd *cobra.Command, args []string) error { prmApi.Backend = &prm.Docker{AFS: prmApi.AFS, IOFS: prmApi.IOFS, AlwaysBuild: alwaysBuild, ContextTimeout: prmApi.RunningConfig.Timeout} } + if prmApi.CodeDir == "" { + workingDirectory, err := os.Getwd() + if err != nil { + return fmt.Errorf("unable to set working directory as default codedir: %s", err) + } + prmApi.CodeDir = workingDirectory + } + // handle the default cachepath if prmApi.CacheDir == "" { usr, _ := user.Current() diff --git a/cmd/validate/validate.go b/cmd/validate/validate.go index 8689c86..81433d4 100644 --- a/cmd/validate/validate.go +++ b/cmd/validate/validate.go @@ -2,6 +2,7 @@ package validate import ( "fmt" + "os" "os/user" "path" "path/filepath" @@ -113,6 +114,14 @@ func preExecute(cmd *cobra.Command, args []string) error { return fmt.Errorf("the --resultsView flag must be set to either [terminal|file]") } + if prmApi.CodeDir == "" { + workingDirectory, err := os.Getwd() + if err != nil { + return fmt.Errorf("unable to set working directory as default codedir: %s", err) + } + prmApi.CodeDir = workingDirectory + } + if toolTimeout < 1 { return fmt.Errorf("the --toolTimeout flag must be set to a value greater than 1") } diff --git a/pkg/prm/validate.go b/pkg/prm/validate.go index 39dc0e3..1df3dd0 100644 --- a/pkg/prm/validate.go +++ b/pkg/prm/validate.go @@ -211,8 +211,13 @@ func getErrorCount(tasks []*Task[ValidationOutput]) (count int) { func createTableContents(tasks []*Task[ValidationOutput], resultsView string) (tableContents [][]string) { for _, task := range tasks { output := task.Output - if resultsView == "file" { // Will also include the path to each log file - tableContents = append(tableContents, []string{task.Name, fmt.Sprintf("%d", output.exitCode), toolLogOutputPaths[task.Name]}) + if resultsView == "file" { // Will also include the path to each + outputPath := toolLogOutputPaths[task.Name] + // Shortens the output file path so table doesn't become unreadable as a result of long file paths + if shortOutputDir := strings.Split(outputPath, ".prm-validate"); len(shortOutputDir) == 2 { + outputPath = ".prm_validate" + shortOutputDir[1] + } + tableContents = append(tableContents, []string{task.Name, fmt.Sprintf("%d", output.exitCode), outputPath}) } else { tableContents = append(tableContents, []string{task.Name, fmt.Sprintf("%d", output.exitCode)}) }