Skip to content

Commit f013040

Browse files
add remember relay options (#1000)
don't save relay if it is the default don't use remembered relay if it is the default
1 parent 74e69e9 commit f013040

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/cli/cli.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,12 @@ func send(c *cli.Context) (err error) {
356356
if !c.IsSet("git") {
357357
crocOptions.GitIgnore = rememberedOptions.GitIgnore
358358
}
359+
if !c.IsSet("relay") && rememberedOptions.RelayAddress != models.DEFAULT_RELAY {
360+
crocOptions.RelayAddress = rememberedOptions.RelayAddress
361+
}
362+
if !c.IsSet("relay6") && rememberedOptions.RelayAddress6 != models.DEFAULT_RELAY6 {
363+
crocOptions.RelayAddress6 = rememberedOptions.RelayAddress6
364+
}
359365
}
360366

361367
var fnames []string
@@ -521,6 +527,13 @@ func saveConfig(c *cli.Context, crocOptions croc.Options) {
521527
if c.String("code") == "" {
522528
crocOptions.SharedSecret = ""
523529
}
530+
// if the relay is the default, don't save it
531+
if c.String("relay") == models.DEFAULT_RELAY {
532+
crocOptions.RelayAddress = ""
533+
}
534+
if c.String("relay6") == models.DEFAULT_RELAY6 {
535+
crocOptions.RelayAddress6 = ""
536+
}
524537
bConfig, err := json.MarshalIndent(crocOptions, "", " ")
525538
if err != nil {
526539
log.Error(err)
@@ -638,6 +651,12 @@ func receive(c *cli.Context) (err error) {
638651
if !c.IsSet("local") {
639652
crocOptions.OnlyLocal = rememberedOptions.OnlyLocal
640653
}
654+
if !c.IsSet("relay") && rememberedOptions.RelayAddress != models.DEFAULT_RELAY {
655+
crocOptions.RelayAddress = rememberedOptions.RelayAddress
656+
}
657+
if !c.IsSet("relay6") && rememberedOptions.RelayAddress6 != models.DEFAULT_RELAY6 {
658+
crocOptions.RelayAddress6 = rememberedOptions.RelayAddress6
659+
}
641660
}
642661

643662
classicInsecureMode := utils.Exists(getClassicConfigFile(true))
@@ -693,6 +712,13 @@ Or you can go back to the classic croc behavior by enabling classic mode:
693712
if doRemember {
694713
log.Debug("saving config file")
695714
var bConfig []byte
715+
// if the relay is the default, don't save it
716+
if c.String("relay") == models.DEFAULT_RELAY {
717+
crocOptions.RelayAddress = ""
718+
}
719+
if c.String("relay6") == models.DEFAULT_RELAY6 {
720+
crocOptions.RelayAddress6 = ""
721+
}
696722
bConfig, err = json.MarshalIndent(crocOptions, "", " ")
697723
if err != nil {
698724
log.Error(err)

0 commit comments

Comments
 (0)