Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cmd): allow passing a working directory for flipt validate command #2936

Merged
merged 3 commits into from
Apr 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions cmd/flipt/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"encoding/json"
"errors"
"fmt"
"os"

Expand All @@ -15,6 +16,7 @@ type validateCommand struct {
issueExitCode int
format string
extraPath string
workDirectory string
}

const (
Expand All @@ -31,7 +33,7 @@ func newValidateCommand() *cobra.Command {
RunE: v.run,
}

cmd.Flags().IntVar(&v.issueExitCode, "issue-exit-code", 1, "Exit code to use when issues are found")
cmd.Flags().IntVar(&v.issueExitCode, "issue-exit-code", 1, "exit code to use when issues are found")

cmd.Flags().StringVarP(
&v.format,
Expand All @@ -47,6 +49,13 @@ func newValidateCommand() *cobra.Command {
"path to extra schema constraints",
)

cmd.Flags().StringVarP(
&v.workDirectory,
"work-dir", "d",
".",
"set the working directory",
)

return cmd
}

Expand All @@ -68,10 +77,14 @@ func (v *validateCommand) run(cmd *cobra.Command, args []string) error {
))
}

if v.workDirectory == "" {
return errors.New("non-empty working directory expected")
}

if len(args) == 0 {
_, err = fs.SnapshotFromFS(logger, os.DirFS("."), opts...)
_, err = fs.SnapshotFromFS(logger, os.DirFS(v.workDirectory), opts...)
} else {
_, err = fs.SnapshotFromPaths(logger, os.DirFS("."), args, opts...)
_, err = fs.SnapshotFromPaths(logger, os.DirFS(v.workDirectory), args, opts...)
}

errs, ok := validation.Unwrap(err)
Expand Down
Loading