-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This allow users to compare paths between two YAML files. Return equal paths in both files. Enable `by-value` flag for `compare` cmd: This enable/disable a comparison for paths with the same value.
- Loading branch information
1 parent
114f894
commit add5930
Showing
5 changed files
with
191 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
# structure with maps | ||
yaml: | ||
structure: | ||
somekey: foo | ||
dot: samevalue | ||
|
||
# structure with a list of maps | ||
list: | ||
- name: one | ||
somekey: foo | ||
- name: sametwo | ||
somekey: samekey | ||
|
||
# structure with a simple list | ||
simpleList: | ||
- one |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
# structure with maps | ||
yaml: | ||
structure: | ||
somekey: bar | ||
dot: samevalue | ||
|
||
# structure with a list of maps | ||
list: | ||
- name: two | ||
somekey: bar | ||
- name: sametwo | ||
somekey: samekey |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright © 2018 Matthias Diester | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/HeavyWombat/ytbx/pkg/v1/ytbx" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var comparePathsByValue bool | ||
|
||
// compareCmd represents the compare command | ||
var compareCmd = &cobra.Command{ | ||
Use: "compare <from_file> <to_file>", | ||
Args: cobra.RangeArgs(1, 2), | ||
Short: "Compare YAML paths", | ||
Long: `Compare YAML paths between two files.`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
list, err := ytbx.ComparePaths(args[0], args[1], ytbx.GoPatchStyle, comparePathsByValue) | ||
if err != nil { | ||
exitWithError("Failed to get paths from file", err) | ||
} | ||
for _, entry := range list { | ||
fmt.Println(entry) | ||
} | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(compareCmd) | ||
compareCmd.PersistentFlags().BoolVar(&comparePathsByValue, "by-value", false, "compare only paths with same value") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters