Skip to content

Commit

Permalink
add fa shell command
Browse files Browse the repository at this point in the history
  • Loading branch information
codeskyblue committed Dec 19, 2018
1 parent d03827e commit b10e662
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 23 deletions.
23 changes: 14 additions & 9 deletions adb.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func (c *AdbClient) DeviceWithSerial(serial string) *AdbDevice {
}
}

func (c *AdbDevice) openCommand(cmd string) (reader io.ReadCloser, err error) {
func (c *AdbDevice) OpenShell(cmd string) (rw io.ReadWriteCloser, err error) {
conn, err := c.newConnection()
if err != nil {
return
Expand All @@ -191,13 +191,18 @@ func (c *AdbDevice) openCommand(cmd string) (reader io.ReadCloser, err error) {
return conn, nil
}

func (c *AdbDevice) OpenShell(args ...string) (reader io.ReadCloser, err error) {
return c.openCommand(shellquote.Join(args...))
// OpenCommand accept list of args return combined output reader
func (c *AdbDevice) OpenCommand(args ...string) (reader io.ReadWriteCloser, err error) {
return c.OpenShell(shellquote.Join(args...))
}

// func (c *AdbDevice) RunShell(args ...string) (exitCode int, err error) {
// reader, err := c.OpenShell(args...)
// if err != nil {
// return
// }
// }
func (c *AdbDevice) RunCommand(args ...string) (exitCode int, err error) {
// TODO
reader, err := c.OpenCommand(args...)
if err != nil {
return
}
defer reader.Close()
_, err = io.Copy(os.Stdout, reader)
return
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module github.com/codeskyblue/fa

require (
github.com/cavaliercoder/grab v2.0.0+incompatible
github.com/fatih/color v1.7.0 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
github.com/kr/pty v1.1.3 // indirect
github.com/manifoldco/promptui v0.3.2
Expand Down
37 changes: 23 additions & 14 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io"
"log"
"os"
"os/exec"
Expand Down Expand Up @@ -279,20 +280,28 @@ func main() {
},
Action: actInstall,
},
// {
// Name: "shell",
// Usage: "run shell command",
// SkipFlagParsing: true,
// Action: func(ctx *cli.Context) error {
// output, exitCode, err := DefaultAdbClient.Shell(ctx.Args()...)
// if err != nil {
// return err
// }
// fmt.Print(output)
// os.Exit(exitCode)
// return nil
// },
// },
{
Name: "shell",
Usage: "run shell command",
SkipFlagParsing: true,
Action: func(ctx *cli.Context) error {
serial, err := chooseOne()
if err != nil {
return err
}
device := DefaultAdbClient.DeviceWithSerial(serial)
rwc, err := device.OpenCommand(ctx.Args()...)
if err != nil {
return err
}
defer rwc.Close()
go io.Copy(rwc, os.Stdin)
io.Copy(os.Stdout, rwc)
// fmt.Print(output)
// os.Exit(exitCode)
return nil
},
},
{
Name: "healthcheck",
Usage: "check device health status",
Expand Down

0 comments on commit b10e662

Please sign in to comment.