This is an automated email from the ASF dual-hosted git repository.

sjanc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-newt.git

commit 2e8bbd406e7a893c8370b05b4a15e2c36aea5384
Author: Szymon Janc <[email protected]>
AuthorDate: Mon Oct 19 17:56:08 2026 +0200

    newt/cli: Explain missing arguments of target set and cmake
    
    "newt target set <target> app" (no '=') and "newt target cmake"
    without a target printed only usage text. Print an error explaining
    what is missing.
    
    Assisted-by: Claude:claude-opus-5-5
---
 newt/cli/target_cmds.go      |  9 ++++++++-
 newt/error_reporting_test.go | 16 ++++++++++++++++
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/newt/cli/target_cmds.go b/newt/cli/target_cmds.go
index 62f26f3f..7d4d4344 100644
--- a/newt/cli/target_cmds.go
+++ b/newt/cli/target_cmds.go
@@ -362,6 +362,11 @@ func targetListCmd(cmd *cobra.Command, args []string) {
 }
 
 func targetCmakeCmd(cmd *cobra.Command, args []string) {
+       if len(args) != 1 {
+               NewtUsage(cmd,
+                       util.NewNewtError("Must specify exactly one target 
name"))
+       }
+
        TryGetProject()
 
        // Verify and resolve each specified package.
@@ -423,7 +428,9 @@ func targetSetCmd(cmd *cobra.Command, args []string) {
 
                if len(kv) == 1 {
                        // User entered a variable name without a value.
-                       NewtUsage(cmd, nil)
+                       NewtUsage(cmd, util.FmtNewtError(
+                               "Missing value for \"%s\"; expected %s=<value>",
+                               args[i], args[i]))
                }
 
                // Trim trailing slash from value.  This is necessary when tab
diff --git a/newt/error_reporting_test.go b/newt/error_reporting_test.go
index 8dfddd87..fcf3d051 100644
--- a/newt/error_reporting_test.go
+++ b/newt/error_reporting_test.go
@@ -270,3 +270,19 @@ func TestErrorReportingDocsBuild(t *testing.T) {
                t.Errorf("missing sphinx-build error\n%s", out)
        }
 }
+
+// Commands with missing arguments must explain what is missing.
+func TestErrorReportingMissingArgs(t *testing.T) {
+       t.Run("target-set-no-value", func(t *testing.T) {
+               dir := copyToTemp(t, errorReportingProjDir)
+               errorReportingExpectFail(t, dir,
+                       []string{`Error: Missing value for "app"; expected 
app=<value>`},
+                       "target", "set", "app", "app")
+       })
+
+       t.Run("target-cmake-no-target", func(t *testing.T) {
+               errorReportingExpectFail(t, errorReportingProjDir,
+                       []string{"Error: Must specify exactly one target name"},
+                       "target", "cmake")
+       })
+}

Reply via email to