Skip to content

Commit ec80b74

Browse files
committed
chore: address PR comments
- use existing const for "json" parameter - lowercase file permissions - comment file permissions, interfaces
1 parent d94d2be commit ec80b74

File tree

7 files changed

+13
-12
lines changed

7 files changed

+13
-12
lines changed

internal/commands/ostest/depgraph_flow.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ func handleOutput(
150150
errFactory *errors.ErrorFactory,
151151
) ([]workflow.Data, error) {
152152
config := ictx.GetConfiguration()
153-
jsonOutput := config.GetBool("json")
153+
jsonOutput := config.GetBool(outputworkflow.OutputConfigKeyJSON)
154154
jsonFileOutput := config.GetString(outputworkflow.OutputConfigKeyJSONFile)
155155

156156
// Human-readable output is suppressed only when --json is specified.

internal/commands/ostest/test_execution.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ func prepareOutput(
151151
outputData = append(outputData, summaryData)
152152
}
153153

154-
wantsJSONStdOut := config.GetBool("json")
154+
wantsJSONStdOut := config.GetBool(outputworkflow.OutputConfigKeyJSON)
155155
jsonFileOutput := config.GetString(outputworkflow.OutputConfigKeyJSONFile)
156156
wantsJSONFile := jsonFileOutput != ""
157157
wantsAnyJSON := wantsJSONStdOut || wantsJSONFile

internal/commands/ostest/workflow_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
common "github.com/snyk/cli-extension-os-flows/internal/common"
2626
"github.com/snyk/cli-extension-os-flows/internal/flags"
2727
"github.com/snyk/cli-extension-os-flows/internal/legacy/definitions"
28+
"github.com/snyk/cli-extension-os-flows/internal/outputworkflow"
2829
)
2930

3031
var legacyWorkflowID = workflow.NewWorkflowIdentifier("legacycli")
@@ -462,7 +463,7 @@ func TestOSWorkflow_AllProjects_UnifiedFlow(t *testing.T) {
462463
config.Set(ostest.FeatureFlagRiskScore, true)
463464
config.Set(ostest.FeatureFlagRiskScoreInCLI, true)
464465
config.Set(flags.FlagAllProjects, true)
465-
config.Set("json", true)
466+
config.Set(outputworkflow.OutputConfigKeyJSON, true)
466467

467468
// Temporarily reduce the poll interval for this test to avoid timeouts.
468469
originalPollInterval := ostest.PollInterval

internal/outputworkflow/delayedfileopenwritecloser.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func (wc *delayedFileOpenWriteCloser) Write(p []byte) (n int, err error) {
2121
return 0, pathError
2222
}
2323

24-
file, fileErr := os.OpenFile(wc.Filename, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, Fileperm666)
24+
file, fileErr := os.OpenFile(wc.Filename, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, fileperm666)
2525
if fileErr != nil {
2626
return 0, fmt.Errorf("failed to open file %s: %w", wc.Filename, fileErr)
2727
}

internal/outputworkflow/file_utils.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ import (
88
)
99

1010
const (
11-
// Fileperm755 is a constant for file permissions.
12-
Fileperm755 fs.FileMode = 0o755 // Owner=rwx, Group=r-x, Other=r-x
13-
// Fileperm666 is a constant for file permissions.
14-
Fileperm666 fs.FileMode = 0o666 // Owner=rw-, Group=rw-, Other=rw-
11+
// fileperm755 is the permission for creating directories: Owner=rwx, Group=r-x, Other=r-x.
12+
fileperm755 fs.FileMode = 0o755
13+
// fileperm666 is the permission file output: Owner=rw-, Group=rw-, Other=rw-.
14+
fileperm666 fs.FileMode = 0o666
1515
)
1616

1717
// CreateFilePath creates the directory path for a file if it doesn't exist.
1818
func CreateFilePath(path string) error {
1919
dirPath := filepath.Dir(path)
2020
if _, err := os.Stat(dirPath); os.IsNotExist(err) {
21-
mkdirErr := os.MkdirAll(dirPath, Fileperm755)
21+
mkdirErr := os.MkdirAll(dirPath, fileperm755)
2222
if mkdirErr != nil {
2323
return fmt.Errorf("failed to create directory path %s: %w", dirPath, mkdirErr)
2424
}

internal/outputworkflow/output_destination.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"os"
99
)
1010

11-
// OutputDestination is an interface for output destinations.
11+
// OutputDestination is an interface for where to direct workflow output.
1212
type OutputDestination interface {
1313
Println(a ...any) (n int, err error)
1414
Remove(name string) error

internal/outputworkflow/output_workflow_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ func Test_Output_InitOutputWorkflow(t *testing.T) {
3030
err := InitOutputWorkflow(engine)
3131
assert.Nil(t, err)
3232

33-
json := config.GetBool("json")
33+
json := config.GetBool(OutputConfigKeyJSON)
3434
assert.Equal(t, false, json)
3535

36-
jsonFileOutput := config.GetString("json-file-output")
36+
jsonFileOutput := config.GetString(OutputConfigKeyJSONFile)
3737
assert.Equal(t, "", jsonFileOutput)
3838
}
3939

0 commit comments

Comments
 (0)