Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Commit

Permalink
Merge pull request #165 from puppetlabs/gh-163/main/fix_codedir_omission
Browse files Browse the repository at this point in the history
(GH-163) Fix `--codedir` flag default
  • Loading branch information
chelnak authored May 10, 2022
2 parents 861af16 + 86c9d2d commit b5e3cde
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- [(GH-163)](https://github.com/puppetlabs/pct/issues/341) `--codedir {string}` flag is omitted, use working directory

## [0.2.0]

### Added
Expand Down
9 changes: 9 additions & 0 deletions cmd/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package exec

import (
"fmt"
"os"
"os/user"
"path/filepath"
"strings"
Expand Down Expand Up @@ -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()
Expand Down
9 changes: 9 additions & 0 deletions cmd/validate/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package validate

import (
"fmt"
"os"
"os/user"
"path"
"path/filepath"
Expand Down Expand Up @@ -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")
}
Expand Down
9 changes: 7 additions & 2 deletions pkg/prm/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 = fmt.Sprint(".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)})
}
Expand Down

0 comments on commit b5e3cde

Please sign in to comment.