mirror of
https://github.com/mikefarah/yq.git
synced 2024-12-19 20:19:04 +00:00
Fixed error flag
This commit is contained in:
parent
d9ae8e1e5a
commit
767709fef5
@ -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")
|
||||
}
|
||||
|
@ -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`
|
||||
|
Loading…
Reference in New Issue
Block a user