Skip to content

Commit 8df8a5a

Browse files
authored
Merge pull request #466 from dsidirop/ksidirop/NCLI-0465-connection-name-flag
#465 connection name flag
2 parents 13775fd + d9042d4 commit 8df8a5a

File tree

4 files changed

+12
-3
lines changed

4 files changed

+12
-3
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,4 @@ pkg
4747
dist
4848
natscli
4949
nats/nats
50+
nats/main

cli/cli.go

+2
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ type Options struct {
6969
TlsCA string
7070
// Timeout is how long to wait for operations
7171
Timeout time.Duration
72+
// ConnectionName is the name to use for the underlying NATS connection
73+
ConnectionName string
7274
// Username is the username or token to connect with
7375
Username string
7476
// Password is the password to connect with

cli/util.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -395,8 +395,13 @@ func natsOpts() []nats.Option {
395395
copts, err := opts.Config.NATSOptions()
396396
kingpin.FatalIfError(err, "configuration error")
397397

398+
connectionName := strings.TrimSpace(opts.ConnectionName)
399+
if len(connectionName) == 0 {
400+
connectionName = "NATS CLI Version " + Version
401+
}
402+
398403
return append(copts, []nats.Option{
399-
nats.Name("NATS CLI Version " + Version),
404+
nats.Name(connectionName),
400405
nats.MaxReconnects(-1),
401406
nats.DisconnectErrHandler(func(nc *nats.Conn, err error) {
402407
if err != nil {

nats/main.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ See 'nats cheat' for a quick cheatsheet of commands
4747
ncli.Flag("server", "NATS server urls").Short('s').Envar("NATS_URL").PlaceHolder("NATS_URL").StringVar(&opts.Servers)
4848
ncli.Flag("user", "Username or Token").Envar("NATS_USER").PlaceHolder("NATS_USER").StringVar(&opts.Username)
4949
ncli.Flag("password", "Password").Envar("NATS_PASSWORD").PlaceHolder("NATS_PASSWORD").StringVar(&opts.Password)
50+
ncli.Flag("connection-name", "Nickname to use for the underlying NATS Connection").Default("NATS CLI Version " + version).PlaceHolder("NAME").StringVar(&opts.ConnectionName)
5051
ncli.Flag("creds", "User credentials").Envar("NATS_CREDS").PlaceHolder("NATS_CREDS").StringVar(&opts.Creds)
5152
ncli.Flag("nkey", "User NKEY").Envar("NATS_NKEY").PlaceHolder("NATS_NKEY").StringVar(&opts.Nkey)
5253
ncli.Flag("tlscert", "TLS public certificate").Envar("NATS_CERT").PlaceHolder("NATS_CERT").ExistingFileVar(&opts.TlsCert)
@@ -55,9 +56,9 @@ See 'nats cheat' for a quick cheatsheet of commands
5556
ncli.Flag("timeout", "Time to wait on responses from NATS").Default("5s").Envar("NATS_TIMEOUT").PlaceHolder("NATS_TIMEOUT").DurationVar(&opts.Timeout)
5657
ncli.Flag("js-api-prefix", "Subject prefix for access to JetStream API").PlaceHolder("PREFIX").StringVar(&opts.JsApiPrefix)
5758
ncli.Flag("js-event-prefix", "Subject prefix for access to JetStream Advisories").PlaceHolder("PREFIX").StringVar(&opts.JsEventPrefix)
58-
ncli.Flag("js-domain", "JetStream domain to access").PlaceHolder("PREFIX").PlaceHolder("DOMAIN").StringVar(&opts.JsDomain)
59+
ncli.Flag("js-domain", "JetStream domain to access").PlaceHolder("DOMAIN").StringVar(&opts.JsDomain)
5960
ncli.Flag("inbox-prefix", "Custom inbox prefix to use for inboxes").PlaceHolder("PREFIX").StringVar(&opts.InboxPrefix)
60-
ncli.Flag("domain", "JetStream domain to access").PlaceHolder("PREFIX").PlaceHolder("DOMAIN").Hidden().StringVar(&opts.JsDomain)
61+
ncli.Flag("domain", "JetStream domain to access").PlaceHolder("DOMAIN").Hidden().StringVar(&opts.JsDomain)
6162
ncli.Flag("context", "Configuration context").Envar("NATS_CONTEXT").StringVar(&opts.CfgCtx)
6263
ncli.Flag("trace", "Trace API interactions").BoolVar(&opts.Trace)
6364

0 commit comments

Comments
 (0)