mirror of
https://github.com/schollz/croc.git
synced 2025-10-11 05:11:06 +02:00
Update CLI to v2
Signed-off-by: jolheiser <john.olheiser@gmail.com>
This commit is contained in:
parent
f2c5ca820a
commit
9a20d507a7
3 changed files with 50 additions and 50 deletions
2
go.mod
2
go.mod
|
@ -20,7 +20,7 @@ require (
|
||||||
github.com/spaolacci/murmur3 v1.1.0 // indirect
|
github.com/spaolacci/murmur3 v1.1.0 // indirect
|
||||||
github.com/stretchr/testify v1.4.0
|
github.com/stretchr/testify v1.4.0
|
||||||
github.com/tscholl2/siec v0.0.0-20191122224205-8da93652b094
|
github.com/tscholl2/siec v0.0.0-20191122224205-8da93652b094
|
||||||
github.com/urfave/cli v1.22.4
|
github.com/urfave/cli/v2 v2.2.0
|
||||||
golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a
|
golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a
|
||||||
golang.org/x/net v0.0.0-20200822124328-c89045814202 // indirect
|
golang.org/x/net v0.0.0-20200822124328-c89045814202 // indirect
|
||||||
golang.org/x/sys v0.0.0-20200831180312-196b9ba8737a // indirect
|
golang.org/x/sys v0.0.0-20200831180312-196b9ba8737a // indirect
|
||||||
|
|
4
go.sum
4
go.sum
|
@ -62,8 +62,8 @@ github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJy
|
||||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||||
github.com/tscholl2/siec v0.0.0-20191122224205-8da93652b094 h1:tZWtuLE+LbUwT4OP1oWBSB9zXA8qmQ5qEm4kV9R72oo=
|
github.com/tscholl2/siec v0.0.0-20191122224205-8da93652b094 h1:tZWtuLE+LbUwT4OP1oWBSB9zXA8qmQ5qEm4kV9R72oo=
|
||||||
github.com/tscholl2/siec v0.0.0-20191122224205-8da93652b094/go.mod h1:KL9+ubr1JZdaKjgAaHr+tCytEncXBa1pR6FjbTsOJnw=
|
github.com/tscholl2/siec v0.0.0-20191122224205-8da93652b094/go.mod h1:KL9+ubr1JZdaKjgAaHr+tCytEncXBa1pR6FjbTsOJnw=
|
||||||
github.com/urfave/cli v1.22.4 h1:u7tSpNPPswAFymm8IehJhy4uJMlUuU/GmqSkvJ1InXA=
|
github.com/urfave/cli/v2 v2.2.0 h1:JTTnM6wKzdA0Jqodd966MVj4vWbbquZykeX1sKbe2C4=
|
||||||
github.com/urfave/cli v1.22.4/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
|
github.com/urfave/cli/v2 v2.2.0/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ=
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
golang.org/x/crypto v0.0.0-20200604202706-70a84ac30bf9 h1:vEg9joUBmeBcK9iSJftGNf3coIG4HqZElCPehJsfAYM=
|
golang.org/x/crypto v0.0.0-20200604202706-70a84ac30bf9 h1:vEg9joUBmeBcK9iSJftGNf3coIG4HqZElCPehJsfAYM=
|
||||||
golang.org/x/crypto v0.0.0-20200604202706-70a84ac30bf9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
golang.org/x/crypto v0.0.0-20200604202706-70a84ac30bf9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||||
|
|
|
@ -18,7 +18,7 @@ import (
|
||||||
"github.com/schollz/croc/v8/src/tcp"
|
"github.com/schollz/croc/v8/src/tcp"
|
||||||
"github.com/schollz/croc/v8/src/utils"
|
"github.com/schollz/croc/v8/src/utils"
|
||||||
log "github.com/schollz/logger"
|
log "github.com/schollz/logger"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Version specifies the version
|
// Version specifies the version
|
||||||
|
@ -42,18 +42,18 @@ func Run() (err error) {
|
||||||
|
|
||||||
Send a file with a custom code:
|
Send a file with a custom code:
|
||||||
croc send --code secret-passphrase file.txt`
|
croc send --code secret-passphrase file.txt`
|
||||||
app.Commands = []cli.Command{
|
app.Commands = []*cli.Command{
|
||||||
{
|
{
|
||||||
Name: "send",
|
Name: "send",
|
||||||
Usage: "send a file (see options with croc send -h)",
|
Usage: "send a file (see options with croc send -h)",
|
||||||
Description: "send a file over the relay",
|
Description: "send a file over the relay",
|
||||||
ArgsUsage: "[filename]",
|
ArgsUsage: "[filename]",
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
cli.StringFlag{Name: "code, c", Usage: "codephrase used to connect to relay"},
|
&cli.StringFlag{Name: "code, c", Usage: "codephrase used to connect to relay"},
|
||||||
cli.StringFlag{Name: "text, t", Usage: "send some text"},
|
&cli.StringFlag{Name: "text, t", Usage: "send some text"},
|
||||||
cli.BoolFlag{Name: "no-local", Usage: "disable local relay when sending"},
|
&cli.BoolFlag{Name: "no-local", Usage: "disable local relay when sending"},
|
||||||
cli.BoolFlag{Name: "no-multi", Usage: "disable multiplexing"},
|
&cli.BoolFlag{Name: "no-multi", Usage: "disable multiplexing"},
|
||||||
cli.StringFlag{Name: "ports", Value: "9009,9010,9011,9012,9013", Usage: "ports of the local relay (optional)"},
|
&cli.StringFlag{Name: "ports", Value: "9009,9010,9011,9012,9013", Usage: "ports of the local relay (optional)"},
|
||||||
},
|
},
|
||||||
HelpName: "croc send",
|
HelpName: "croc send",
|
||||||
Action: func(c *cli.Context) error {
|
Action: func(c *cli.Context) error {
|
||||||
|
@ -69,21 +69,21 @@ func Run() (err error) {
|
||||||
return relay(c)
|
return relay(c)
|
||||||
},
|
},
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
cli.StringFlag{Name: "ports", Value: "9009,9010,9011,9012,9013", Usage: "ports of the relay"},
|
&cli.StringFlag{Name: "ports", Value: "9009,9010,9011,9012,9013", Usage: "ports of the relay"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
app.Flags = []cli.Flag{
|
app.Flags = []cli.Flag{
|
||||||
cli.BoolFlag{Name: "remember", Usage: "save these settings to reuse next time"},
|
&cli.BoolFlag{Name: "remember", Usage: "save these settings to reuse next time"},
|
||||||
cli.BoolFlag{Name: "debug", Usage: "toggle debug mode"},
|
&cli.BoolFlag{Name: "debug", Usage: "toggle debug mode"},
|
||||||
cli.BoolFlag{Name: "yes", Usage: "automatically agree to all prompts"},
|
&cli.BoolFlag{Name: "yes", Usage: "automatically agree to all prompts"},
|
||||||
cli.BoolFlag{Name: "stdout", Usage: "redirect file to stdout"},
|
&cli.BoolFlag{Name: "stdout", Usage: "redirect file to stdout"},
|
||||||
cli.BoolFlag{Name: "no-compress", Usage: "disable compression"},
|
&cli.BoolFlag{Name: "no-compress", Usage: "disable compression"},
|
||||||
cli.BoolFlag{Name: "ask", Usage: "make sure sender and recipient are prompted"},
|
&cli.BoolFlag{Name: "ask", Usage: "make sure sender and recipient are prompted"},
|
||||||
cli.StringFlag{Name: "relay", Value: models.DEFAULT_RELAY, Usage: "address of the relay"},
|
&cli.StringFlag{Name: "relay", Value: models.DEFAULT_RELAY, Usage: "address of the relay"},
|
||||||
cli.StringFlag{Name: "relay6", Value: models.DEFAULT_RELAY6, Usage: "ipv6 address of the relay"},
|
&cli.StringFlag{Name: "relay6", Value: models.DEFAULT_RELAY6, Usage: "ipv6 address of the relay"},
|
||||||
cli.StringFlag{Name: "out", Value: ".", Usage: "specify an output folder to receive the file"},
|
&cli.StringFlag{Name: "out", Value: ".", Usage: "specify an output folder to receive the file"},
|
||||||
cli.StringFlag{Name: "pass", Value: "pass123", Usage: "password for the relay"},
|
&cli.StringFlag{Name: "pass", Value: "pass123", Usage: "password for the relay"},
|
||||||
}
|
}
|
||||||
app.EnableBashCompletion = true
|
app.EnableBashCompletion = true
|
||||||
app.HideHelp = false
|
app.HideHelp = false
|
||||||
|
@ -121,7 +121,7 @@ func getConfigDir() (homedir string, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func setDebugLevel(c *cli.Context) {
|
func setDebugLevel(c *cli.Context) {
|
||||||
if c.GlobalBool("debug") {
|
if c.Bool("debug") {
|
||||||
log.SetLevel("debug")
|
log.SetLevel("debug")
|
||||||
log.Debug("debug mode on")
|
log.Debug("debug mode on")
|
||||||
} else {
|
} else {
|
||||||
|
@ -139,7 +139,7 @@ func getConfigFile() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func determinePass(c *cli.Context) (pass string) {
|
func determinePass(c *cli.Context) (pass string) {
|
||||||
pass = c.GlobalString("pass")
|
pass = c.String("pass")
|
||||||
b, err := ioutil.ReadFile(pass)
|
b, err := ioutil.ReadFile(pass)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
pass = strings.TrimSpace(string(b))
|
pass = strings.TrimSpace(string(b))
|
||||||
|
@ -152,18 +152,18 @@ func send(c *cli.Context) (err error) {
|
||||||
crocOptions := croc.Options{
|
crocOptions := croc.Options{
|
||||||
SharedSecret: c.String("code"),
|
SharedSecret: c.String("code"),
|
||||||
IsSender: true,
|
IsSender: true,
|
||||||
Debug: c.GlobalBool("debug"),
|
Debug: c.Bool("debug"),
|
||||||
NoPrompt: c.GlobalBool("yes"),
|
NoPrompt: c.Bool("yes"),
|
||||||
RelayAddress: c.GlobalString("relay"),
|
RelayAddress: c.String("relay"),
|
||||||
RelayAddress6: c.GlobalString("relay6"),
|
RelayAddress6: c.String("relay6"),
|
||||||
Stdout: c.GlobalBool("stdout"),
|
Stdout: c.Bool("stdout"),
|
||||||
DisableLocal: c.Bool("no-local"),
|
DisableLocal: c.Bool("no-local"),
|
||||||
RelayPorts: strings.Split(c.String("ports"), ","),
|
RelayPorts: strings.Split(c.String("ports"), ","),
|
||||||
Ask: c.GlobalBool("ask"),
|
Ask: c.Bool("ask"),
|
||||||
NoMultiplexing: c.Bool("no-multi"),
|
NoMultiplexing: c.Bool("no-multi"),
|
||||||
RelayPassword: determinePass(c),
|
RelayPassword: determinePass(c),
|
||||||
SendingText: c.String("text") != "",
|
SendingText: c.String("text") != "",
|
||||||
NoCompress: c.GlobalBool("no-compress"),
|
NoCompress: c.Bool("no-compress"),
|
||||||
}
|
}
|
||||||
if crocOptions.RelayAddress != models.DEFAULT_RELAY {
|
if crocOptions.RelayAddress != models.DEFAULT_RELAY {
|
||||||
crocOptions.RelayAddress6 = ""
|
crocOptions.RelayAddress6 = ""
|
||||||
|
@ -171,7 +171,7 @@ func send(c *cli.Context) (err error) {
|
||||||
crocOptions.RelayAddress = ""
|
crocOptions.RelayAddress = ""
|
||||||
}
|
}
|
||||||
b, errOpen := ioutil.ReadFile(getConfigFile())
|
b, errOpen := ioutil.ReadFile(getConfigFile())
|
||||||
if errOpen == nil && !c.GlobalBool("remember") {
|
if errOpen == nil && !c.Bool("remember") {
|
||||||
var rememberedOptions croc.Options
|
var rememberedOptions croc.Options
|
||||||
err = json.Unmarshal(b, &rememberedOptions)
|
err = json.Unmarshal(b, &rememberedOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -179,7 +179,7 @@ func send(c *cli.Context) (err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// update anything that isn't explicitly set
|
// update anything that isn't explicitly set
|
||||||
if !c.GlobalIsSet("relay") {
|
if !c.IsSet("relay") {
|
||||||
crocOptions.RelayAddress = rememberedOptions.RelayAddress
|
crocOptions.RelayAddress = rememberedOptions.RelayAddress
|
||||||
}
|
}
|
||||||
if !c.IsSet("no-local") {
|
if !c.IsSet("no-local") {
|
||||||
|
@ -191,7 +191,7 @@ func send(c *cli.Context) (err error) {
|
||||||
if !c.IsSet("code") {
|
if !c.IsSet("code") {
|
||||||
crocOptions.SharedSecret = rememberedOptions.SharedSecret
|
crocOptions.SharedSecret = rememberedOptions.SharedSecret
|
||||||
}
|
}
|
||||||
if !c.GlobalIsSet("pass") {
|
if !c.IsSet("pass") {
|
||||||
crocOptions.RelayPassword = rememberedOptions.RelayPassword
|
crocOptions.RelayPassword = rememberedOptions.RelayPassword
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -323,7 +323,7 @@ func getPaths(fnames []string) (paths []string, haveFolder bool, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func saveConfig(c *cli.Context, crocOptions croc.Options) {
|
func saveConfig(c *cli.Context, crocOptions croc.Options) {
|
||||||
if c.GlobalBool("remember") {
|
if c.Bool("remember") {
|
||||||
configFile := getConfigFile()
|
configFile := getConfigFile()
|
||||||
log.Debug("saving config file")
|
log.Debug("saving config file")
|
||||||
var bConfig []byte
|
var bConfig []byte
|
||||||
|
@ -349,12 +349,12 @@ func receive(c *cli.Context) (err error) {
|
||||||
crocOptions := croc.Options{
|
crocOptions := croc.Options{
|
||||||
SharedSecret: c.String("code"),
|
SharedSecret: c.String("code"),
|
||||||
IsSender: false,
|
IsSender: false,
|
||||||
Debug: c.GlobalBool("debug"),
|
Debug: c.Bool("debug"),
|
||||||
NoPrompt: c.GlobalBool("yes"),
|
NoPrompt: c.Bool("yes"),
|
||||||
RelayAddress: c.GlobalString("relay"),
|
RelayAddress: c.String("relay"),
|
||||||
RelayAddress6: c.GlobalString("relay6"),
|
RelayAddress6: c.String("relay6"),
|
||||||
Stdout: c.GlobalBool("stdout"),
|
Stdout: c.Bool("stdout"),
|
||||||
Ask: c.GlobalBool("ask"),
|
Ask: c.Bool("ask"),
|
||||||
RelayPassword: determinePass(c),
|
RelayPassword: determinePass(c),
|
||||||
}
|
}
|
||||||
if crocOptions.RelayAddress != models.DEFAULT_RELAY {
|
if crocOptions.RelayAddress != models.DEFAULT_RELAY {
|
||||||
|
@ -363,7 +363,7 @@ func receive(c *cli.Context) (err error) {
|
||||||
crocOptions.RelayAddress = ""
|
crocOptions.RelayAddress = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
switch len(c.Args()) {
|
switch c.Args().Len() {
|
||||||
case 1:
|
case 1:
|
||||||
crocOptions.SharedSecret = c.Args().First()
|
crocOptions.SharedSecret = c.Args().First()
|
||||||
case 3:
|
case 3:
|
||||||
|
@ -382,24 +382,24 @@ func receive(c *cli.Context) (err error) {
|
||||||
}
|
}
|
||||||
configFile = path.Join(configFile, "receive.json")
|
configFile = path.Join(configFile, "receive.json")
|
||||||
b, errOpen := ioutil.ReadFile(configFile)
|
b, errOpen := ioutil.ReadFile(configFile)
|
||||||
if errOpen == nil && !c.GlobalBool("remember") {
|
if errOpen == nil && !c.Bool("remember") {
|
||||||
var rememberedOptions croc.Options
|
var rememberedOptions croc.Options
|
||||||
err = json.Unmarshal(b, &rememberedOptions)
|
err = json.Unmarshal(b, &rememberedOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// update anything that isn't explicitly set
|
// update anything that isn't expliciGlobalIsSettly set
|
||||||
if !c.GlobalIsSet("relay") {
|
if !c.IsSet("relay") {
|
||||||
crocOptions.RelayAddress = rememberedOptions.RelayAddress
|
crocOptions.RelayAddress = rememberedOptions.RelayAddress
|
||||||
}
|
}
|
||||||
if !c.GlobalIsSet("yes") {
|
if !c.IsSet("yes") {
|
||||||
crocOptions.NoPrompt = rememberedOptions.NoPrompt
|
crocOptions.NoPrompt = rememberedOptions.NoPrompt
|
||||||
}
|
}
|
||||||
if crocOptions.SharedSecret == "" {
|
if crocOptions.SharedSecret == "" {
|
||||||
crocOptions.SharedSecret = rememberedOptions.SharedSecret
|
crocOptions.SharedSecret = rememberedOptions.SharedSecret
|
||||||
}
|
}
|
||||||
if !c.GlobalIsSet("pass") {
|
if !c.IsSet("pass") {
|
||||||
crocOptions.RelayPassword = rememberedOptions.RelayPassword
|
crocOptions.RelayPassword = rememberedOptions.RelayPassword
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -407,8 +407,8 @@ func receive(c *cli.Context) (err error) {
|
||||||
if crocOptions.SharedSecret == "" {
|
if crocOptions.SharedSecret == "" {
|
||||||
crocOptions.SharedSecret = utils.GetInput("Enter receive code: ")
|
crocOptions.SharedSecret = utils.GetInput("Enter receive code: ")
|
||||||
}
|
}
|
||||||
if c.GlobalString("out") != "" {
|
if c.String("out") != "" {
|
||||||
if err = os.Chdir(c.GlobalString("out")); err != nil {
|
if err = os.Chdir(c.String("out")); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -419,7 +419,7 @@ func receive(c *cli.Context) (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// save the config
|
// save the config
|
||||||
if c.GlobalBool("remember") {
|
if c.Bool("remember") {
|
||||||
log.Debug("saving config file")
|
log.Debug("saving config file")
|
||||||
var bConfig []byte
|
var bConfig []byte
|
||||||
bConfig, err = json.MarshalIndent(crocOptions, "", " ")
|
bConfig, err = json.MarshalIndent(crocOptions, "", " ")
|
||||||
|
@ -442,7 +442,7 @@ func receive(c *cli.Context) (err error) {
|
||||||
func relay(c *cli.Context) (err error) {
|
func relay(c *cli.Context) (err error) {
|
||||||
log.Infof("starting croc relay version %v", Version)
|
log.Infof("starting croc relay version %v", Version)
|
||||||
debugString := "info"
|
debugString := "info"
|
||||||
if c.GlobalBool("debug") {
|
if c.Bool("debug") {
|
||||||
debugString = "debug"
|
debugString = "debug"
|
||||||
}
|
}
|
||||||
ports := strings.Split(c.String("ports"), ",")
|
ports := strings.Split(c.String("ports"), ",")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue