mirror of
https://github.com/schollz/croc.git
synced 2025-10-11 13:21:00 +02:00
reduce complexity
This commit is contained in:
parent
9fb54a3952
commit
1fe8ccf3ab
1 changed files with 35 additions and 26 deletions
|
@ -127,9 +127,9 @@ func getConfigFile() string {
|
||||||
}
|
}
|
||||||
return path.Join(configFile, "send.json")
|
return path.Join(configFile, "send.json")
|
||||||
}
|
}
|
||||||
|
|
||||||
func send(c *cli.Context) (err error) {
|
func send(c *cli.Context) (err error) {
|
||||||
setDebugLevel(c)
|
setDebugLevel(c)
|
||||||
|
|
||||||
crocOptions := croc.Options{
|
crocOptions := croc.Options{
|
||||||
SharedSecret: c.String("code"),
|
SharedSecret: c.String("code"),
|
||||||
IsSender: true,
|
IsSender: true,
|
||||||
|
@ -197,31 +197,9 @@ func send(c *cli.Context) (err error) {
|
||||||
crocOptions.SharedSecret = utils.GetRandomName()
|
crocOptions.SharedSecret = utils.GetRandomName()
|
||||||
}
|
}
|
||||||
|
|
||||||
haveFolder := false
|
paths, haveFolder, err := getPaths(fnames)
|
||||||
paths := []string{}
|
if err != nil {
|
||||||
for _, fname := range fnames {
|
return
|
||||||
stat, err := os.Stat(fname)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if stat.IsDir() {
|
|
||||||
haveFolder = true
|
|
||||||
err = filepath.Walk(fname,
|
|
||||||
func(pathName string, info os.FileInfo, err error) error {
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if !info.IsDir() {
|
|
||||||
paths = append(paths, filepath.ToSlash(pathName))
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
paths = append(paths, filepath.ToSlash(fname))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cr, err := croc.New(crocOptions)
|
cr, err := croc.New(crocOptions)
|
||||||
|
@ -240,6 +218,37 @@ func send(c *cli.Context) (err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getPaths(fnames []string) (paths []string, haveFolder bool, err error) {
|
||||||
|
haveFolder = false
|
||||||
|
paths = []string{}
|
||||||
|
for _, fname := range fnames {
|
||||||
|
stat, errStat := os.Stat(fname)
|
||||||
|
if errStat != nil {
|
||||||
|
err = errStat
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if stat.IsDir() {
|
||||||
|
haveFolder = true
|
||||||
|
err = filepath.Walk(fname,
|
||||||
|
func(pathName string, info os.FileInfo, err error) error {
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if !info.IsDir() {
|
||||||
|
paths = append(paths, filepath.ToSlash(pathName))
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
paths = append(paths, filepath.ToSlash(fname))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func saveConfig(c *cli.Context, crocOptions croc.Options) {
|
func saveConfig(c *cli.Context, crocOptions croc.Options) {
|
||||||
if c.GlobalBool("remember") {
|
if c.GlobalBool("remember") {
|
||||||
configFile := getConfigFile()
|
configFile := getConfigFile()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue