Skip to content

Commit

Permalink
fix: correctly handle input flag
Browse files Browse the repository at this point in the history
The input flag should have been using `-` to indicate that it was
reading input from standard in, and therefore the `--input` flag
should have been mandatory.
  • Loading branch information
russell committed Aug 16, 2021
1 parent 5729bfc commit d9e7126
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
3 changes: 2 additions & 1 deletion cmd/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,6 @@ func init() {
manifestCmd.Flags().StringP("state-file", "s", ".stately-files.yaml", "The state file to use")
manifestCmd.Flags().StringP("output-dir", "o", cwd, "The location to copy to")
manifestCmd.Flags().StringP("name", "n", "default", "The name of the file set to track")
manifestCmd.Flags().StringP("input", "", "", "The input file or - for stdin")
manifestCmd.Flags().StringP("input", "i", "", "The input file or - for stdin")
manifestCmd.MarkFlagRequired("input")
}
16 changes: 13 additions & 3 deletions pkg/stately/actions/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,24 @@ func Manifest(o *ManifestOptions) error {
currentState, _ = config.NewStateConfigFromFile(o.StateFile)
}

var manifests models.ManifestContainer
var newFiles []config.StateFile
stateFile, _ := filepath.Abs(o.StateFile)
stateFileDir := filepath.Dir(stateFile)

// Manifest files
manifests, err := models.NewManifestContainerFromStdin()
if err != nil {
return err
if o.InputFile == "-" {
var err error
manifests, err = models.NewManifestContainerFromStdin()
if err != nil {
return err
}
} else {
var err error
manifests, err = models.NewManifestContainerFromFile(o.InputFile)
if err != nil {
return err
}
}

for _, file := range manifests.Files {
Expand Down
2 changes: 1 addition & 1 deletion tests/manifest_dhall_test.bats
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ source "tests/common.sh"
setup_file() {
export OUTPUT_DIR=$(mktemp -d)
local TEST_DIR=$PWD
(cd "$OUTPUT_DIR"; stately manifest < "$TEST_DIR/tests/dhall-render-test.json")
(cd "$OUTPUT_DIR"; stately manifest -i "$TEST_DIR/tests/dhall-render-test.json")
}

teardown_file() {
Expand Down
2 changes: 1 addition & 1 deletion tests/manifest_test.bats
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ source "tests/common.sh"

setup_file() {
export OUTPUT_DIR=$(mktemp -d)
stately manifest -o "$OUTPUT_DIR" < "tests/test.json"
stately manifest -o "$OUTPUT_DIR" -i - < "tests/test.json"
}

teardown_file() {
Expand Down

0 comments on commit d9e7126

Please sign in to comment.