mirror of https://github.com/schollz/croc.git
simplify toggling
This commit is contained in:
parent
97d18e1fbf
commit
252e96a670
|
@ -124,47 +124,36 @@ func send(c *cli.Context) (err error) {
|
||||||
}
|
}
|
||||||
configFile = path.Join(configFile, "send.json")
|
configFile = path.Join(configFile, "send.json")
|
||||||
|
|
||||||
var crocOptions croc.Options
|
crocOptions := croc.Options{
|
||||||
|
SharedSecret: c.String("code"),
|
||||||
|
IsSender: true,
|
||||||
|
Debug: c.GlobalBool("debug"),
|
||||||
|
NoPrompt: c.GlobalBool("yes"),
|
||||||
|
RelayAddress: c.GlobalString("relay"),
|
||||||
|
Stdout: c.GlobalBool("stdout"),
|
||||||
|
DisableLocal: c.Bool("no-local"),
|
||||||
|
RelayPorts: strings.Split(c.String("ports"), ","),
|
||||||
|
}
|
||||||
b, errOpen := ioutil.ReadFile(configFile)
|
b, errOpen := ioutil.ReadFile(configFile)
|
||||||
if errOpen == nil && !c.GlobalBool("remember") {
|
if errOpen == nil && !c.GlobalBool("remember") {
|
||||||
err = json.Unmarshal(b, &crocOptions)
|
var rememberedOptions croc.Options
|
||||||
|
err = json.Unmarshal(b, &rememberedOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// update anything that has changed
|
// update anything that isn't explicitly set
|
||||||
if crocOptions.Debug != c.GlobalBool("debug") {
|
if !c.GlobalIsSet("relay") {
|
||||||
crocOptions.Debug = c.GlobalBool("debug")
|
crocOptions.RelayAddress = rememberedOptions.RelayAddress
|
||||||
}
|
}
|
||||||
if c.GlobalBool("yes") {
|
if !c.IsSet("no-local") {
|
||||||
crocOptions.NoPrompt = c.GlobalBool("yes")
|
crocOptions.DisableLocal = rememberedOptions.DisableLocal
|
||||||
}
|
}
|
||||||
if crocOptions.RelayAddress != c.GlobalString("relay") {
|
if !c.IsSet("ports") {
|
||||||
crocOptions.RelayAddress = c.GlobalString("relay")
|
crocOptions.RelayPorts = rememberedOptions.RelayPorts
|
||||||
}
|
}
|
||||||
if c.GlobalBool("stdout") {
|
if !c.IsSet("code") {
|
||||||
crocOptions.Stdout = c.GlobalBool("stdout")
|
crocOptions.SharedSecret = rememberedOptions.SharedSecret
|
||||||
}
|
|
||||||
// TODO: use c.IsSet
|
|
||||||
|
|
||||||
if c.Bool("no-local") {
|
|
||||||
crocOptions.DisableLocal = c.Bool("no-local")
|
|
||||||
}
|
|
||||||
// TODO: add ports
|
|
||||||
|
|
||||||
if c.String("code") != "" {
|
|
||||||
crocOptions.SharedSecret = ""
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
crocOptions = croc.Options{
|
|
||||||
SharedSecret: "",
|
|
||||||
IsSender: true,
|
|
||||||
Debug: c.GlobalBool("debug"),
|
|
||||||
NoPrompt: c.GlobalBool("yes"),
|
|
||||||
RelayAddress: c.GlobalString("relay"),
|
|
||||||
Stdout: c.GlobalBool("stdout"),
|
|
||||||
DisableLocal: c.Bool("no-local"),
|
|
||||||
RelayPorts: strings.Split(c.String("ports"), ","),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,9 +186,6 @@ func send(c *cli.Context) (err error) {
|
||||||
return errors.New("must specify file: croc send [filename]")
|
return errors.New("must specify file: croc send [filename]")
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.String("code") != "" {
|
|
||||||
crocOptions.SharedSecret = c.String("code")
|
|
||||||
}
|
|
||||||
if len(crocOptions.SharedSecret) == 0 {
|
if len(crocOptions.SharedSecret) == 0 {
|
||||||
// generate code phrase
|
// generate code phrase
|
||||||
crocOptions.SharedSecret = utils.GetRandomName()
|
crocOptions.SharedSecret = utils.GetRandomName()
|
||||||
|
|
Loading…
Reference in New Issue