Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions internal/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,11 @@ zed permission check --explain document:firstdoc writer user:emilia

relCmd := commands.RegisterRelationshipCmd(rootCmd)

commands.RegisterWatchCmd(rootCmd)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is one of the aliases that we removed.

commands.RegisterWatchRelationshipCmd(relCmd)

schemaCmd := commands.RegisterSchemaCmd(rootCmd)
schemaCompileCmd := registerAdditionalSchemaCmds(schemaCmd)
registerPreviewCmd(rootCmd, schemaCompileCmd)
Comment on lines -130 to -131
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We no longer pass out the schemaCompileCmd as it's no longer needed as an arg to the preview command.

registerAdditionalSchemaCmds(schemaCmd)
registerPreviewCmd(rootCmd)

return rootCmd
}
Expand Down
10 changes: 1 addition & 9 deletions internal/cmd/preview.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,11 @@ import (
"github.com/spf13/cobra"
)

func registerPreviewCmd(rootCmd *cobra.Command, schemaCompileCmd *cobra.Command) {
func registerPreviewCmd(rootCmd *cobra.Command) {
previewCmd := &cobra.Command{
Use: "preview <subcommand>",
Short: "Experimental commands that have been made available for preview",
}

schemaCmd := &cobra.Command{
Use: "schema <subcommand>",
Short: "Manage schema for a permissions system",
Deprecated: "please use `zed schema compile`",
}
Comment on lines -13 to -17
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer any commands under this.


rootCmd.AddCommand(previewCmd)
previewCmd.AddCommand(schemaCmd)
schemaCmd.AddCommand(schemaCompileCmd)
}
8 changes: 3 additions & 5 deletions internal/cmd/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (rtc *realTermChecker) IsTerminal(fd int) bool {
return term.IsTerminal(fd)
}

func registerAdditionalSchemaCmds(schemaCmd *cobra.Command) *cobra.Command {
func registerAdditionalSchemaCmds(schemaCmd *cobra.Command) {
schemaWriteCmd := &cobra.Command{
Use: "write <file?>",
Args: commands.ValidationWrapper(cobra.MaximumNArgs(1)),
Expand Down Expand Up @@ -82,9 +82,9 @@ func registerAdditionalSchemaCmds(schemaCmd *cobra.Command) *cobra.Command {
Short: "Compile a schema that uses extended syntax into one that can be written to SpiceDB",
Example: `
Write to stdout:
zed preview schema compile root.zed
zed schema compile root.zed
Write to an output file:
zed preview schema compile root.zed --out compiled.zed
zed schema compile root.zed --out compiled.zed
`,
ValidArgsFunction: commands.FileExtensionCompletions("zed"),
RunE: func(cmd *cobra.Command, args []string) error {
Expand All @@ -104,8 +104,6 @@ func registerAdditionalSchemaCmds(schemaCmd *cobra.Command) *cobra.Command {

schemaCmd.AddCommand(schemaCompileCmd)
schemaCompileCmd.Flags().String("out", "", "output filepath; omitting writes to stdout")

return schemaCompileCmd
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See note about no longer passing things out of this command.

}

func schemaDiffCmdFunc(_ *cobra.Command, args []string) error {
Expand Down
42 changes: 5 additions & 37 deletions internal/commands/permission.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,6 @@ func consistencyFromCmd(cmd *cobra.Command) (c *v1.Consistency, err error) {
c = &v1.Consistency{Requirement: &v1.Consistency_AtLeastAsFresh{AtLeastAsFresh: &v1.ZedToken{Token: atLeast}}}
}

// Deprecated (hidden) flag.
if revision := cobrautil.MustGetStringExpanded(cmd, "revision"); revision != "" {
Comment on lines -50 to -51
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now covered by the consistency option; we want to get rid of the old way of doing things.

if c != nil {
return nil, ErrMultipleConsistencies
}
c = &v1.Consistency{Requirement: &v1.Consistency_AtLeastAsFresh{AtLeastAsFresh: &v1.ZedToken{Token: revision}}}
}

if exact := cobrautil.MustGetStringExpanded(cmd, "consistency-at-exactly"); exact != "" {
if c != nil {
return nil, ErrMultipleConsistencies
Expand All @@ -76,10 +68,11 @@ func RegisterPermissionCmd(rootCmd *cobra.Command) *cobra.Command {
}

checkBulkCmd := &cobra.Command{
Use: "bulk <resource:id#permission@subject:id> <resource:id#permission@subject:id> ...",
Short: "Check permissions in bulk exist for resource-permission-subject triplets",
Args: ValidationWrapper(cobra.MinimumNArgs(1)),
RunE: checkBulkCmdFunc,
Use: "bulk <resource:id#permission@subject:id> <resource:id#permission@subject:id> ...",
Short: "Check permissions in bulk exist for resource-permission-subject triplets",
Args: ValidationWrapper(cobra.MinimumNArgs(1)),
RunE: checkBulkCmdFunc,
Aliases: []string{"check-bulk", "bulk-check"},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding aliases here.

}

checkCmd := &cobra.Command{
Expand All @@ -106,16 +99,6 @@ func RegisterPermissionCmd(rootCmd *cobra.Command) *cobra.Command {
RunE: lookupResourcesCmdFunc,
}

lookupCmd := &cobra.Command{
Use: "lookup <type> <permission> <subject:id>",
Comment on lines -109 to -110
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer using a separate command for lookup. This is covered by lookup-resources.

Short: "Enumerates the resources of a given type for which a subject has permission",
Args: ValidationWrapper(cobra.ExactArgs(3)),
ValidArgsFunction: GetArgs(ResourceType, Permission, SubjectID),
RunE: lookupResourcesCmdFunc,
Deprecated: "prefer lookup-resources",
Hidden: true,
}

lookupSubjectsCmd := &cobra.Command{
Use: "lookup-subjects <resource:id> <permission> <subject_type#optional_subject_relation>",
Short: "Enumerates the subjects of a given type for which the subject has permission on the resource",
Expand All @@ -128,38 +111,24 @@ func RegisterPermissionCmd(rootCmd *cobra.Command) *cobra.Command {

permissionCmd.AddCommand(checkCmd)
checkCmd.Flags().Bool("json", false, "output as JSON")
checkCmd.Flags().String("revision", "", "optional revision at which to check")
_ = checkCmd.Flags().MarkHidden("revision")
checkCmd.Flags().Bool("explain", false, "requests debug information from SpiceDB and prints out a trace of the requests")
checkCmd.Flags().Bool("schema", false, "requests debug information from SpiceDB and prints out the schema used")
checkCmd.Flags().Bool("error-on-no-permission", false, "if true, zed will return exit code 1 if subject does not have unconditional permission")
checkCmd.Flags().String("caveat-context", "", "the caveat context to send along with the check, in JSON form")
registerConsistencyFlags(checkCmd.Flags())

permissionCmd.AddCommand(checkBulkCmd)
checkBulkCmd.Flags().String("revision", "", "optional revision at which to check")
Copy link
Contributor

@miparnisari miparnisari Oct 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one wasn't marked as hidden, can we actually remove it?

i also see this

readCmd.Flags().String("revision", "", "optional revision at which to check")
_ = readCmd.Flags().MarkHidden("revision")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would argue yes, as long as we document it

checkBulkCmd.Flags().Bool("json", false, "output as JSON")
checkBulkCmd.Flags().Bool("explain", false, "requests debug information from SpiceDB and prints out a trace of the requests")
checkBulkCmd.Flags().Bool("schema", false, "requests debug information from SpiceDB and prints out the schema used")
registerConsistencyFlags(checkBulkCmd.Flags())

permissionCmd.AddCommand(expandCmd)
expandCmd.Flags().Bool("json", false, "output as JSON")
expandCmd.Flags().String("revision", "", "optional revision at which to check")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same deal here.

registerConsistencyFlags(expandCmd.Flags())

// NOTE: `lookup` is an alias of `lookup-resources` (below)
// and must have the same list of flags in order for it to work.
permissionCmd.AddCommand(lookupCmd)
lookupCmd.Flags().Bool("json", false, "output as JSON")
lookupCmd.Flags().String("revision", "", "optional revision at which to check")
lookupCmd.Flags().String("caveat-context", "", "the caveat context to send along with the lookup, in JSON form")
lookupCmd.Flags().Uint32("page-limit", 0, "limit of relations returned per page")
registerConsistencyFlags(lookupCmd.Flags())

permissionCmd.AddCommand(lookupResourcesCmd)
lookupResourcesCmd.Flags().Bool("json", false, "output as JSON")
lookupResourcesCmd.Flags().String("revision", "", "optional revision at which to check")
lookupResourcesCmd.Flags().String("caveat-context", "", "the caveat context to send along with the lookup, in JSON form")
lookupResourcesCmd.Flags().Uint32("page-limit", 0, "limit of relations returned per page")
lookupResourcesCmd.Flags().String("cursor", "", "resume pagination from a specific cursor token")
Expand All @@ -168,7 +137,6 @@ func RegisterPermissionCmd(rootCmd *cobra.Command) *cobra.Command {

permissionCmd.AddCommand(lookupSubjectsCmd)
lookupSubjectsCmd.Flags().Bool("json", false, "output as JSON")
lookupSubjectsCmd.Flags().String("revision", "", "optional revision at which to check")
lookupSubjectsCmd.Flags().String("caveat-context", "", "the caveat context to send along with the lookup, in JSON form")
registerConsistencyFlags(lookupSubjectsCmd.Flags())

Expand Down
5 changes: 1 addition & 4 deletions internal/commands/relationship.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func RegisterRelationshipCmd(rootCmd *cobra.Command) *cobra.Command {
Args: ValidationWrapper(StdinOrExactArgs(3)),
ValidArgsFunction: GetArgs(ResourceID, Permission, SubjectTypeWithOptionalRelation),
RunE: writeRelationshipCmdFunc(v1.RelationshipUpdate_OPERATION_CREATE, os.Stdin),
Aliases: []string{"write"},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding zed relationship write as an alias - this is what i always want to write.

Example: `
zed relationship create document:budget view user:anne --expiration-time "2025-12-31T23:59:59Z"
zed relationship create document:budget view user:anne --caveat ip_address:'{"ip": "192.168.0.1"}
Expand Down Expand Up @@ -104,8 +105,6 @@ func RegisterRelationshipCmd(rootCmd *cobra.Command) *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().MarkHidden("revision")
readCmd.Flags().String("subject-filter", "", "optional subject filter")
readCmd.Flags().Uint32("page-limit", 100, "limit of relations returned per page")
registerConsistencyFlags(readCmd.Flags())
Expand All @@ -114,8 +113,6 @@ func RegisterRelationshipCmd(rootCmd *cobra.Command) *cobra.Command {
bulkDeleteCmd.Flags().Bool("force", false, "force deletion of all elements in batches defined by <optional-limit>")
bulkDeleteCmd.Flags().String("subject-filter", "", "optional subject filter")
bulkDeleteCmd.Flags().Uint32("optional-limit", 1000, "the max amount of elements to delete. If you want to delete all in batches of size <optional-limit>, set --force to true")
bulkDeleteCmd.Flags().Bool("estimate-count", true, "estimate the count of relationships to be deleted")
_ = bulkDeleteCmd.Flags().MarkDeprecated("estimate-count", "no longer used, make use of --optional-limit instead")
return relationshipCmd
}

Expand Down
16 changes: 0 additions & 16 deletions internal/commands/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,6 @@ var (
watchRelationshipFilters []string
)

func RegisterWatchCmd(rootCmd *cobra.Command) *cobra.Command {
watchCmd := &cobra.Command{
Use: "watch [object_types, ...] [revision]",
Short: "Watches the stream of relationship updates and schema updates from the server",
Args: ValidationWrapper(cobra.RangeArgs(0, 2)),
RunE: watchCmdFunc,
Deprecated: "please use `zed relationships watch` instead",
}

rootCmd.AddCommand(watchCmd)
watchCmd.Flags().StringSliceVar(&watchObjectTypes, "object_types", nil, "optional object types to watch updates for")
watchCmd.Flags().StringVar(&watchRevision, "revision", "", "optional revision at which to start watching")
watchCmd.Flags().BoolVar(&watchTimestamps, "timestamp", false, "shows timestamp of incoming update events")
return watchCmd
}

func RegisterWatchRelationshipCmd(parentCmd *cobra.Command) *cobra.Command {
watchRelationshipsCmd := &cobra.Command{
Use: "watch [object_types, ...] [revision]",
Expand Down
Loading