refactoring
This commit is contained in:
parent
f4708458a0
commit
7f0c8d2cb1
58
main.go
58
main.go
|
@ -468,6 +468,37 @@ func selectFiles(files []File, input string) []File {
|
|||
return result
|
||||
}
|
||||
|
||||
func runCmds(cmds []*exec.Cmd) {
|
||||
for _, cmd := range cmds {
|
||||
fmt.Printf("<----->\nCommand: %s\n<----->\n", cmd)
|
||||
|
||||
stdout, _ := cmd.StdoutPipe()
|
||||
scanner := bufio.NewScanner(stdout)
|
||||
|
||||
err := cmd.Start()
|
||||
if err != nil {
|
||||
fmt.Printf("%+v\n", err)
|
||||
}
|
||||
|
||||
for scanner.Scan() {
|
||||
out := fmt.Sprintf("%q", scanner.Text())
|
||||
out = strings.Trim(out, "\"")
|
||||
out = strings.ReplaceAll(out, `\u00a0`, " ")
|
||||
|
||||
if out != "" {
|
||||
fmt.Print("\r")
|
||||
fmt.Print(out)
|
||||
} else {
|
||||
fmt.Print("\n")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for _, cmd := range cmds {
|
||||
cmd.Wait()
|
||||
}
|
||||
}
|
||||
|
||||
func runShell(ctx *cli.Context, action string) error {
|
||||
directory := strings.TrimSuffix(ctx.String(flagDirectory), "/")
|
||||
name := ctx.String(flagName)
|
||||
|
@ -499,32 +530,7 @@ func runShell(ctx *cli.Context, action string) error {
|
|||
cmds = generateDownloadCmds(result, directory)
|
||||
}
|
||||
|
||||
for _, cmd := range cmds {
|
||||
stdout, _ := cmd.StdoutPipe()
|
||||
scanner := bufio.NewScanner(stdout)
|
||||
|
||||
err := cmd.Start()
|
||||
if err != nil {
|
||||
fmt.Printf("%+v\n", err)
|
||||
}
|
||||
|
||||
for scanner.Scan() {
|
||||
out := fmt.Sprintf("%q", scanner.Text())
|
||||
out = strings.Trim(out, "\"")
|
||||
out = strings.ReplaceAll(out, `\u00a0`, " ")
|
||||
|
||||
if out != "" {
|
||||
fmt.Print("\r")
|
||||
fmt.Print(out)
|
||||
} else {
|
||||
fmt.Print("\n")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for _, cmd := range cmds {
|
||||
cmd.Wait()
|
||||
}
|
||||
runCmds(cmds)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue