diff --git a/etcdctl/ctlv3/command/get_command.go b/etcdctl/ctlv3/command/get_command.go index 809ee8df2c3d..54354ec379ae 100644 --- a/etcdctl/ctlv3/command/get_command.go +++ b/etcdctl/ctlv3/command/get_command.go @@ -15,6 +15,7 @@ package command import ( + "errors" "fmt" "strings" @@ -105,6 +106,13 @@ func getGetOp(cmd *cobra.Command, args []string) (string, []clientv3.OpOption) { opts = append(opts, clientv3.WithRev(getRev)) } + if getSortOrder == "" && getSortTarget != "" { + ExitWithError(ExitBadArgs, errors.New("missing sort order (--order)")) + } + if getSortOrder != "" && getSortTarget == "" { + ExitWithError(ExitBadArgs, errors.New("missing sort target (--sort-by)")) + } + sortByOrder := clientv3.SortNone sortOrder := strings.ToUpper(getSortOrder) switch {