From c0340c314d451408b6b1f4b0dbbcbd479ea9d745 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Thu, 21 Mar 2024 08:36:17 +0100 Subject: [PATCH] cmd/cue: deprecate `cue somecmd` in favor of `cue cmd somecmd` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit v0.9.0-alpha.1 will be released with the deprecation warning to stderr, and a future release like v0.10 or v0.11 can remove support entirely. Note that even when we remove support for the short form, this shouldn't be a hard breakage for any users, as they can switch to the long form by adding the "cmd" argument. Also rewrite a few tests which didn't need to use the short form. Only one other test case remains with the short form, as it explicitly tests for an edge case bug relating to the short form. That test case can be removed entirely once we drop support. Updates #2519. Signed-off-by: Daniel Martí Change-Id: I04aa48b048bb3f1c397f8b95a36933d797734930 Dispatch-Trailer: {"type":"trybot","CL":1185473,"patchset":1,"ref":"refs/changes/73/1185473/1","targetBranch":"master"} --- cmd/cue/cmd/cmd.go | 4 ++++ cmd/cue/cmd/testdata/script/cmd_embed.txtar | 4 ++-- cmd/cue/cmd/testdata/script/cmd_func.txtar | 2 +- cmd/cue/cmd/testdata/script/cmd_short.txtar | 19 +++++++++++++++++++ 4 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 cmd/cue/cmd/testdata/script/cmd_short.txtar diff --git a/cmd/cue/cmd/cmd.go b/cmd/cue/cmd/cmd.go index 87340b5c9..0f59756ad 100644 --- a/cmd/cue/cmd/cmd.go +++ b/cmd/cue/cmd/cmd.go @@ -175,6 +175,10 @@ Run "cue help commands" for more details on tasks and commands. } // Presumably the *cobra.Command argument should be cmd.Command, // as that is the one which will have the right settings applied. + if isRootCmd { + cmd.PrintErrf("The short-form 'cue %[1]s' is deprecated; use 'cue cmd %[1]s'.\n", args[0]) + cmd.PrintErrf("See: https://cuelang.org/issue/2519\n") + } return sub.RunE(cmd.Command, args[1:]) }), } diff --git a/cmd/cue/cmd/testdata/script/cmd_embed.txtar b/cmd/cue/cmd/testdata/script/cmd_embed.txtar index b74a3cd8d..6db206eaa 100644 --- a/cmd/cue/cmd/testdata/script/cmd_embed.txtar +++ b/cmd/cue/cmd/testdata/script/cmd_embed.txtar @@ -4,11 +4,11 @@ exec cue export cmp stdout expect/concrete.json # Using the explicitly written command works OK. -exec cue hello1 +exec cue cmd hello1 stdout 'hello, world' # Using the command that's defined externally fails. -exec cue hello +exec cue cmd hello stdout 'hello, world' diff --git a/cmd/cue/cmd/testdata/script/cmd_func.txtar b/cmd/cue/cmd/testdata/script/cmd_func.txtar index 7921b3c67..0bc7a3722 100644 --- a/cmd/cue/cmd/testdata/script/cmd_func.txtar +++ b/cmd/cue/cmd/testdata/script/cmd_func.txtar @@ -1,5 +1,5 @@ # Issue #578 -exec cue dump ./... +exec cue cmd dump ./... cmp stdout stdout-expect -- k1.cue -- package kube diff --git a/cmd/cue/cmd/testdata/script/cmd_short.txtar b/cmd/cue/cmd/testdata/script/cmd_short.txtar new file mode 100644 index 000000000..d55529ec3 --- /dev/null +++ b/cmd/cue/cmd/testdata/script/cmd_short.txtar @@ -0,0 +1,19 @@ +exec cue cmd hello +stdout 'Hello world!' +! stderr . + +exec cue hello +stdout 'Hello world!' +cmp stderr stderr-warning + +-- stderr-warning -- +The short-form 'cue hello' is deprecated; use 'cue cmd hello'. +See: https://cuelang.org/issue/2519 +-- task_tool.cue -- +package home + +import "tool/cli" + +command: hello: cli.Print & { + text: "Hello world!" +}