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

Commit

Permalink
(GH-163) Fix --codedir flag default
Browse files Browse the repository at this point in the history
This commit sets the default `--codedir {string}` value to the current
working directory.
  • Loading branch information
petergmurphy committed May 10, 2022
1 parent 1b117ff commit 431b92d
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 = ".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 431b92d

Please sign in to comment.