Repository: nats-io/natscli

Issue:
mirror creation with --defaults option
### Observed behavior

Using the new nats-cli 0.3.0 I found the following creating a mirror:
Something like this works fine:
nats stream add --mirror=FOO SFOO
It goes over all the questions to setup the mirror stream and then the mirror options.
Doing this does not work anymore:
nats stream add --mirror=FOO --defaults SFOO
It creates a regular stream called SFOO, listening to subjects SFOO

### Expected behavior

It should create a mirror stream, replicating from FOO

### Server and client version

nats cli 0.3.0

### Host environment

_No response_

### Steps to reproduce

_No response_

Discussion:

Solution patch:
diff --git a/cli/stream_command.go b/cli/stream_command.go
index e1cd5ab..96d369a 100644
--- a/cli/stream_command.go
+++ b/cli/stream_command.go
@@ -2836,9 +2836,7 @@ func (c *streamCmd) prepareConfig(_ *fisk.ParseContext, requireSize bool) api.St
 			cfg.Mirror, err = c.parseStreamSource(c.mirror)
 			fisk.FatalIfError(err, "invalid mirror")
 		} else {
-			if !c.acceptDefaults {
-				cfg.Mirror = c.askMirror()
-			}
+			cfg.Mirror = c.askMirror()
 		}
 	}
 
@@ -2881,6 +2879,10 @@ func (c *streamCmd) prepareConfig(_ *fisk.ParseContext, requireSize bool) api.St
 
 func (c *streamCmd) askMirror() *api.StreamSource {
 	mirror := &api.StreamSource{Name: c.mirror}
+	if c.acceptDefaults {
+		return mirror
+	}
+
 	ok, err := askConfirmation("Adjust mirror start", false)
 	fisk.FatalIfError(err, "Could not request mirror details")
 	if ok {



Test patch:
diff --git a/nats/tests/stream_command_test.go b/nats/tests/stream_command_test.go
index 0999107..10d959f 100644
--- a/nats/tests/stream_command_test.go
+++ b/nats/tests/stream_command_test.go
@@ -46,7 +46,7 @@ func TestStreamAdd(t *testing.T) {
 			t.Errorf("failed to add stream %s: %s", name, err)
 		}
 
-		// persis mode
+		// persist mode
 		checkErr(t, s.Delete(), "delete failed")
 		runNatsCli(t, fmt.Sprintf("--server='%s' stream add %s --defaults --subjects=test --persist-mode async", srv.ClientURL(), name))
 		s, err = mgr.LoadStream(name)
@@ -61,6 +61,29 @@ func TestStreamAdd(t *testing.T) {
 	})
 }
 
+func TestStreamAddDefaultMirror(t *testing.T) {
+	withJSServer(t, func(t *testing.T, srv *server.Server, nc *nats.Conn, mgr *jsm.Manager) error {
+		name := setupStreamTest(t, mgr)
+		mirrorName := fmt.Sprintf("%s_MIRROR", name)
+
+		runNatsCli(t, fmt.Sprintf("--server='%s' stream add %s --defaults --mirror %s", srv.ClientURL(), mirrorName, name))
+		s, err := mgr.LoadStream(mirrorName)
+		if err != nil {
+			t.Errorf("failed to add stream %s: %s", name, err)
+		}
+
+		if !s.IsMirror() && s.Mirror().Name != name {
+			t.Fatalf("Expected %s to be a mirror of %q got %v", mirrorName, name, s.Mirror())
+		}
+		if len(s.Subjects()) != 0 {
+			t.Fatalf("Expected no subjects, got %v", s.Subjects())
+		}
+
+		return nil
+	})
+
+}
+
 func TestStreamLS(t *testing.T) {
 	withJSServer(t, func(t *testing.T, srv *server.Server, nc *nats.Conn, mgr *jsm.Manager) error {
 		name := setupStreamTest(t, mgr)