mirror of
https://github.com/taigrr/yq
synced 2025-01-18 04:53:17 -08: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)
|
matchingNodes, errorReadingStream := readYamlFile(args[0], path, updateAll, docIndexInt)
|
||||||
|
|
||||||
if exitStatus {
|
if exitStatus && len(matchingNodes) == 0 {
|
||||||
cmd.SilenceUsage = true
|
cmd.SilenceUsage = true
|
||||||
return errors.New("No matches found")
|
return errors.New("No matches found")
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,30 @@ func TestReadCmd(t *testing.T) {
|
|||||||
test.AssertResult(t, "2\n", result.Output)
|
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) {
|
func TestReadUnwrapCmd(t *testing.T) {
|
||||||
|
|
||||||
content := `b: 'frog' # my favourite`
|
content := `b: 'frog' # my favourite`
|
||||||
|
Loading…
x
Reference in New Issue
Block a user