diff --git a/cmd/read.go b/cmd/read.go index 9039b907..8e68f77c 100644 --- a/cmd/read.go +++ b/cmd/read.go @@ -51,7 +51,7 @@ func readProperty(cmd *cobra.Command, args []string) error { matchingNodes, errorReadingStream := readYamlFile(args[0], path, updateAll, docIndexInt) - if exitStatus { + if exitStatus && len(matchingNodes) == 0 { cmd.SilenceUsage = true return errors.New("No matches found") } diff --git a/cmd/read_test.go b/cmd/read_test.go index 1906bfd9..f4990449 100644 --- a/cmd/read_test.go +++ b/cmd/read_test.go @@ -17,6 +17,30 @@ func TestReadCmd(t *testing.T) { test.AssertResult(t, "2\n", result.Output) } +func TestReadCmdWithExitStatus(t *testing.T) { + cmd := getRootCommand() + result := test.RunCmd(cmd, "read ../examples/sample.yaml b.c -e") + if result.Error != nil { + t.Error(result.Error) + } + test.AssertResult(t, "2\n", result.Output) +} + +func TestReadCmdWithExitStatusNotExist(t *testing.T) { + cmd := getRootCommand() + result := test.RunCmd(cmd, "read ../examples/sample.yaml caterpillar -e") + test.AssertResult(t, "No matches found", result.Error.Error()) +} + +func TestReadCmdNotExist(t *testing.T) { + cmd := getRootCommand() + result := test.RunCmd(cmd, "read ../examples/sample.yaml caterpillar") + if result.Error != nil { + t.Error(result.Error) + } + test.AssertResult(t, "", result.Output) +} + func TestReadUnwrapCmd(t *testing.T) { content := `b: 'frog' # my favourite`