Skip to content

Commit

Permalink
Add subject-filter flag to read and bulk delete
Browse files Browse the repository at this point in the history
  • Loading branch information
josephschorr committed Nov 9, 2021
1 parent 221a4d5 commit e918419
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions cmd/zed/relationship.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ func registerRelationshipCmd(rootCmd *cobra.Command) {
relationshipCmd.AddCommand(readCmd)
readCmd.Flags().Bool("json", false, "output as JSON")
readCmd.Flags().String("revision", "", "optional revision at which to check")
readCmd.Flags().String("subject-filter", "", "optional subject filter")

relationshipCmd.AddCommand(bulkDeleteCmd)
bulkDeleteCmd.Flags().Bool("force", false, "force deletion immediately without confirmation")
bulkDeleteCmd.Flags().String("subject-filter", "", "optional subject filter")
}

var relationshipCmd = &cobra.Command{
Expand Down Expand Up @@ -181,9 +183,14 @@ func buildReadRequest(cmd *cobra.Command, args []string) (*v1.ReadRelationshipsR
readFilter.OptionalRelation = args[1]
}

if len(args) == 3 {
if strings.Contains(args[2], ":") {
subjectNS, subjectID, subjectRel, err := parseSubject(args[2])
if len(args) == 3 || cobrautil.MustGetString(cmd, "subject-filter") != "" {
filter := cobrautil.MustGetString(cmd, "subject-filter")
if filter == "" && len(args) == 3 {
filter = args[2]
}

if strings.Contains(filter, ":") {
subjectNS, subjectID, subjectRel, err := parseSubject(filter)
if err != nil {
return nil, err
}
Expand All @@ -197,7 +204,7 @@ func buildReadRequest(cmd *cobra.Command, args []string) (*v1.ReadRelationshipsR
}
} else {
readFilter.OptionalSubjectFilter = &v1.SubjectFilter{
SubjectType: args[2],
SubjectType: filter,
}
}
}
Expand Down

0 comments on commit e918419

Please sign in to comment.