migrate to go mod

This commit is contained in:
Evrins Hu 2020-07-13 14:18:10 +08:00
parent 029cc6bee4
commit 5532b49f7e
47 changed files with 126 additions and 69 deletions

View file

@ -1,7 +1,7 @@
#goadb #goadb
[![Build Status](https://travis-ci.org/zach-klippenstein/goadb.svg?branch=master)](https://travis-ci.org/zach-klippenstein/goadb) [![Build Status](https://travis-ci.org/zach-klippenstein/goadb.svg?branch=master)](https://travis-ci.org/zach-klippenstein/goadb)
[![GoDoc](https://godoc.org/github.com/zach-klippenstein/goadb?status.svg)](https://godoc.org/github.com/zach-klippenstein/goadb) [![GoDoc](https://godoc.org/goadb?status.svg)](https://godoc.org/goadb)
A Golang library for interacting with the Android Debug Bridge (adb). A Golang library for interacting with the Android Debug Bridge (adb).

View file

@ -3,15 +3,15 @@ package adb
import ( import (
"strconv" "strconv"
"github.com/zach-klippenstein/goadb/internal/errors" "goadb/internal/errors"
"github.com/zach-klippenstein/goadb/wire" "goadb/wire"
) )
/* /*
Adb communicates with host services on the adb server. Adb communicates with host services on the adb server.
Eg. Eg.
client := adb.New() client := New()
client.ListDevices() client.ListDevices()
See list of services at https://android.googlesource.com/platform/system/core/+/master/adb/SERVICES.TXT. See list of services at https://android.googlesource.com/platform/system/core/+/master/adb/SERVICES.TXT.

View file

@ -3,8 +3,9 @@ package adb
import ( import (
"testing" "testing"
"goadb/wire"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/zach-klippenstein/goadb/wire"
) )
func TestGetServerVersion(t *testing.T) { func TestGetServerVersion(t *testing.T) {

View file

@ -7,8 +7,8 @@ import (
"strings" "strings"
"time" "time"
"github.com/zach-klippenstein/goadb/internal/errors" "goadb/internal/errors"
"github.com/zach-klippenstein/goadb/wire" "goadb/wire"
) )
// MtimeOfClose should be passed to OpenWrite to set the file modification time to the time the Close // MtimeOfClose should be passed to OpenWrite to set the file modification time to the time the Close

View file

@ -4,7 +4,7 @@ import (
"bufio" "bufio"
"strings" "strings"
"github.com/zach-klippenstein/goadb/internal/errors" "goadb/internal/errors"
) )
type DeviceInfo struct { type DeviceInfo struct {
@ -66,7 +66,7 @@ func parseDeviceShort(line string) (*DeviceInfo, error) {
func parseDeviceLong(line string) (*DeviceInfo, error) { func parseDeviceLong(line string) (*DeviceInfo, error) {
fields := strings.Fields(line) fields := strings.Fields(line)
if len(fields) < 5 { if len(fields) < 4 {
return nil, errors.Errorf(errors.ParseError, return nil, errors.Errorf(errors.ParseError,
"malformed device line, expected at least 5 fields but found %d", len(fields)) "malformed device line, expected at least 5 fields but found %d", len(fields))
} }

View file

@ -1,6 +1,6 @@
package adb package adb
import "github.com/zach-klippenstein/goadb/internal/errors" import "goadb/internal/errors"
// DeviceState represents one of the 3 possible states adb will report devices. // DeviceState represents one of the 3 possible states adb will report devices.
// A device can be communicated with when it's in StateOnline. // A device can be communicated with when it's in StateOnline.
@ -15,12 +15,14 @@ const (
StateDisconnected StateDisconnected
StateOffline StateOffline
StateOnline StateOnline
StatUnauthorized
) )
var deviceStateStrings = map[string]DeviceState{ var deviceStateStrings = map[string]DeviceState{
"": StateDisconnected, "": StateDisconnected,
"offline": StateOffline, "offline": StateOffline,
"device": StateOnline, "device": StateOnline,
"unauthorized": StatUnauthorized,
} }
func parseDeviceState(str string) (DeviceState, error) { func parseDeviceState(str string) (DeviceState, error) {

View file

@ -3,9 +3,10 @@ package adb
import ( import (
"testing" "testing"
"goadb/internal/errors"
"goadb/wire"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/zach-klippenstein/goadb/internal/errors"
"github.com/zach-klippenstein/goadb/wire"
) )
func TestGetAttribute(t *testing.T) { func TestGetAttribute(t *testing.T) {

View file

@ -8,8 +8,8 @@ import (
"sync/atomic" "sync/atomic"
"time" "time"
"github.com/zach-klippenstein/goadb/internal/errors" "goadb/internal/errors"
"github.com/zach-klippenstein/goadb/wire" "goadb/wire"
) )
/* /*

View file

@ -3,9 +3,10 @@ package adb
import ( import (
"testing" "testing"
"goadb/internal/errors"
"goadb/wire"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/zach-klippenstein/goadb/internal/errors"
"github.com/zach-klippenstein/goadb/wire"
) )
func TestParseDeviceStatesSingle(t *testing.T) { func TestParseDeviceStatesSingle(t *testing.T) {

View file

@ -5,8 +5,8 @@ import (
"net" "net"
"runtime" "runtime"
"github.com/zach-klippenstein/goadb/internal/errors" "goadb/internal/errors"
"github.com/zach-klippenstein/goadb/wire" "goadb/wire"
) )
// Dialer knows how to create connections to an adb server. // Dialer knows how to create connections to an adb server.

View file

@ -5,7 +5,7 @@ import (
"os" "os"
"time" "time"
"github.com/zach-klippenstein/goadb/wire" "goadb/wire"
) )
// DirEntry holds information about a directory entry on a device. // DirEntry holds information about a directory entry on a device.

View file

View file

@ -1,6 +1,6 @@
package adb package adb
import "github.com/zach-klippenstein/goadb/internal/errors" import "goadb/internal/errors"
type ErrCode errors.ErrCode type ErrCode errors.ErrCode

View file

@ -7,8 +7,8 @@ import (
"os/exec" "os/exec"
"strings" "strings"
"github.com/zach-klippenstein/goadb/internal/errors" "goadb/internal/errors"
"github.com/zach-klippenstein/goadb/wire" "goadb/wire"
) )
const ( const (

View file

@ -4,8 +4,8 @@ import (
"io" "io"
"strings" "strings"
"github.com/zach-klippenstein/goadb/internal/errors" "goadb/internal/errors"
"github.com/zach-klippenstein/goadb/wire" "goadb/wire"
) )
// MockServer implements Server, Scanner, and Sender. // MockServer implements Server, Scanner, and Sender.

View file

@ -4,8 +4,9 @@ import (
"fmt" "fmt"
"testing" "testing"
"goadb/wire"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/zach-klippenstein/goadb/wire"
) )
func TestNewServer_ZeroConfig(t *testing.T) { func TestNewServer_ZeroConfig(t *testing.T) {

View file

@ -5,8 +5,8 @@ import (
"os" "os"
"time" "time"
"github.com/zach-klippenstein/goadb/internal/errors" "goadb/internal/errors"
"github.com/zach-klippenstein/goadb/wire" "goadb/wire"
) )
var zeroTime = time.Unix(0, 0).UTC() var zeroTime = time.Unix(0, 0).UTC()

View file

@ -7,10 +7,11 @@ import (
"testing" "testing"
"time" "time"
"goadb/internal/errors"
"goadb/wire"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/zach-klippenstein/goadb/internal/errors"
"github.com/zach-klippenstein/goadb/wire"
) )
var someTime = time.Date(2015, 5, 3, 8, 8, 8, 0, time.UTC) var someTime = time.Date(2015, 5, 3, 8, 8, 8, 0, time.UTC)

View file

@ -3,8 +3,8 @@ package adb
import ( import (
"io" "io"
"github.com/zach-klippenstein/goadb/internal/errors" "goadb/internal/errors"
"github.com/zach-klippenstein/goadb/wire" "goadb/wire"
) )
// syncFileReader wraps a SyncConn that has requested to receive a file. // syncFileReader wraps a SyncConn that has requested to receive a file.

View file

@ -6,8 +6,9 @@ import (
"strings" "strings"
"testing" "testing"
"goadb/wire"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/zach-klippenstein/goadb/wire"
) )
func TestReadNextChunk(t *testing.T) { func TestReadNextChunk(t *testing.T) {

View file

@ -6,8 +6,8 @@ import (
"os" "os"
"time" "time"
"github.com/zach-klippenstein/goadb/internal/errors" "goadb/internal/errors"
"github.com/zach-klippenstein/goadb/wire" "goadb/wire"
) )
// syncFileWriter wraps a SyncConn that has requested to send a file. // syncFileWriter wraps a SyncConn that has requested to send a file.

View file

@ -8,8 +8,9 @@ import (
"encoding/binary" "encoding/binary"
"strings" "strings"
"goadb/wire"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/zach-klippenstein/goadb/wire"
) )
func TestFileWriterWriteSingleChunk(t *testing.T) { func TestFileWriterWriteSingleChunk(t *testing.T) {
@ -48,7 +49,7 @@ func TestFileWriterWriteLargeChunk(t *testing.T) {
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, wire.SyncMaxChunkSize+1, n) assert.Equal(t, wire.SyncMaxChunkSize+1, n)
assert.Equal(t, 8 + 8 + wire.SyncMaxChunkSize+1, buf.Len()) assert.Equal(t, 8+8+wire.SyncMaxChunkSize+1, buf.Len())
// First header. // First header.
chunk := buf.Bytes()[:8+wire.SyncMaxChunkSize] chunk := buf.Bytes()[:8+wire.SyncMaxChunkSize]
@ -58,7 +59,7 @@ func TestFileWriterWriteLargeChunk(t *testing.T) {
assert.Equal(t, data[:wire.SyncMaxChunkSize], chunk[8:]) assert.Equal(t, data[:wire.SyncMaxChunkSize], chunk[8:])
// Second header. // Second header.
chunk = buf.Bytes()[wire.SyncMaxChunkSize+8:wire.SyncMaxChunkSize+8+1] chunk = buf.Bytes()[wire.SyncMaxChunkSize+8 : wire.SyncMaxChunkSize+8+1]
expectedHeader = []byte("DATA\000\000\000\000") expectedHeader = []byte("DATA\000\000\000\000")
binary.LittleEndian.PutUint32(expectedHeader[4:], 1) binary.LittleEndian.PutUint32(expectedHeader[4:], 1)
assert.Equal(t, expectedHeader, chunk[:8]) assert.Equal(t, expectedHeader, chunk[:8])

View file

@ -6,7 +6,7 @@ import (
"regexp" "regexp"
"strings" "strings"
"github.com/zach-klippenstein/goadb/internal/errors" "goadb/internal/errors"
) )
var ( var (

View file

@ -2,14 +2,14 @@ package main
import ( import (
"fmt" "fmt"
"goadb/adb"
"io" "io"
"os" "os"
"path/filepath" "path/filepath"
"syscall" "syscall"
"time" "time"
"github.com/cheggaaa/pb" "github.com/cheggaaa/pb/v3"
"github.com/zach-klippenstein/goadb"
"gopkg.in/alecthomas/kingpin.v2" "gopkg.in/alecthomas/kingpin.v2"
) )
@ -99,7 +99,6 @@ func parseDevice() adb.DeviceDescriptor {
} }
func listDevices(long bool) int { func listDevices(long bool) int {
//client := adb.New(server)
devices, err := client.ListDevices() devices, err := client.ListDevices()
if err != nil { if err != nil {
fmt.Fprintln(os.Stderr, "error:", err) fmt.Fprintln(os.Stderr, "error:", err)
@ -251,24 +250,21 @@ func push(showProgress bool, localPath, remotePath string, device adb.DeviceDesc
// After copying, final stats about the transfer speed and size are shown. // After copying, final stats about the transfer speed and size are shown.
// Progress and stats are printed to stderr. // Progress and stats are printed to stderr.
func copyWithProgressAndStats(dst io.Writer, src io.Reader, size int, showProgress bool) error { func copyWithProgressAndStats(dst io.Writer, src io.Reader, size int, showProgress bool) error {
var progress *pb.ProgressBar var bar *pb.ProgressBar
if showProgress && size > 0 { if showProgress && size > 0 {
progress = pb.New(size) bar = pb.New(size)
// Write to stderr in case dst is stdout. // Write to stderr in case dst is stdout.
progress.Output = os.Stderr bar.SetWriter(os.Stderr)
progress.ShowSpeed = true bar.Set(pb.Bytes, true)
progress.ShowPercent = true bar.Start()
progress.ShowTimeLeft = true dst = bar.NewProxyWriter(dst)
progress.SetUnits(pb.U_BYTES)
progress.Start()
dst = io.MultiWriter(dst, progress)
} }
startTime := time.Now() startTime := time.Now()
copied, err := io.Copy(dst, src) copied, err := io.Copy(dst, src)
if progress != nil { if bar != nil {
progress.Finish() bar.Finish()
} }
if pathErr, ok := err.(*os.PathError); ok { if pathErr, ok := err.(*os.PathError); ok {

View file

@ -4,12 +4,12 @@ package main
import ( import (
"flag" "flag"
"fmt" "fmt"
"goadb/adb"
"io/ioutil" "io/ioutil"
"log" "log"
"time" "time"
adb "github.com/zach-klippenstein/goadb" "goadb/internal/errors"
"github.com/zach-klippenstein/goadb/internal/errors"
) )
var ( var (

View file

@ -5,13 +5,13 @@ import (
"bufio" "bufio"
"flag" "flag"
"fmt" "fmt"
"goadb/adb"
"io" "io"
"log" "log"
"os" "os"
"strings" "strings"
"github.com/zach-klippenstein/goadb" "goadb/wire"
"github.com/zach-klippenstein/goadb/wire"
) )
var port = flag.Int("p", adb.AdbPort, "`port` the adb server is listening on") var port = flag.Int("p", adb.AdbPort, "`port` the adb server is listening on")

12
go.mod Normal file
View file

@ -0,0 +1,12 @@
module goadb
go 1.14
require (
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d // indirect
github.com/cheggaaa/pb/v3 v3.0.4
github.com/stretchr/testify v1.6.1
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae
gopkg.in/alecthomas/kingpin.v2 v2.2.6
)

37
go.sum Normal file
View file

@ -0,0 +1,37 @@
github.com/VividCortex/ewma v1.1.1 h1:MnEK4VOv6n0RSY4vtRe3h11qjxL3+t0B8yOL8iMXdcM=
github.com/VividCortex/ewma v1.1.1/go.mod h1:2Tkkvm3sRDVXaiyucHiACn4cqf7DpdyLvmxzcbUokwA=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafoB+tBA3gMyHYHrpOtNuDiK/uB5uXxq5wM=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d h1:UQZhZ2O0vMHr2cI+DC1Mbh0TJxzA3RcLoMsFw+aXw7E=
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
github.com/cheggaaa/pb/v3 v3.0.4 h1:QZEPYOj2ix6d5oEg63fbHmpolrnNiwjUsk+h74Yt4bM=
github.com/cheggaaa/pb/v3 v3.0.4/go.mod h1:7rgWxLrAUcFMkvJuv09+DYi7mMUYi8nO9iOWcvGJPfw=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/mattn/go-colorable v0.1.2 h1:/bC9yWikZXAL9uJdulbSfyVNIR3n3trXl+v8+1sx8mU=
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.10 h1:qxFzApOv4WsAL965uUPIsXzAKCZxN2p9UqdhFS4ZW10=
github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84=
github.com/mattn/go-runewidth v0.0.7 h1:Ei8KR0497xHyKJPAv59M1dkC+rOZCMBJ+t3fZ+twI54=
github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191128015809-6d18c012aee9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae h1:Ih9Yo4hSPImZOpfGuA4bR/ORKTAbhZo2AbWNRCnevdo=
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View file

@ -1,6 +1,6 @@
package wire package wire
import "github.com/zach-klippenstein/goadb/internal/errors" import "goadb/internal/errors"
const ( const (
// The official implementation of adb imposes an undocumented 255-byte limit // The official implementation of adb imposes an undocumented 255-byte limit

View file

@ -6,7 +6,7 @@ import (
"io/ioutil" "io/ioutil"
"strconv" "strconv"
"github.com/zach-klippenstein/goadb/internal/errors" "goadb/internal/errors"
) )
// TODO(zach): All EOF errors returned from networoking calls should use ConnectionResetError. // TODO(zach): All EOF errors returned from networoking calls should use ConnectionResetError.

View file

@ -7,8 +7,9 @@ import (
"io/ioutil" "io/ioutil"
"testing" "testing"
"goadb/internal/errors"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/zach-klippenstein/goadb/internal/errors"
) )
func TestReadStatusOkay(t *testing.T) { func TestReadStatusOkay(t *testing.T) {

View file

@ -4,7 +4,7 @@ import (
"fmt" "fmt"
"io" "io"
"github.com/zach-klippenstein/goadb/internal/errors" "goadb/internal/errors"
) )
// Sender sends messages to the server. // Sender sends messages to the server.

View file

@ -1,6 +1,6 @@
package wire package wire
import "github.com/zach-klippenstein/goadb/internal/errors" import "goadb/internal/errors"
const ( const (
// Chunks cannot be longer than 64k. // Chunks cannot be longer than 64k.

View file

@ -6,7 +6,7 @@ import (
"os" "os"
"time" "time"
"github.com/zach-klippenstein/goadb/internal/errors" "goadb/internal/errors"
) )
type SyncScanner interface { type SyncScanner interface {

View file

@ -6,7 +6,7 @@ import (
"os" "os"
"time" "time"
"github.com/zach-klippenstein/goadb/internal/errors" "goadb/internal/errors"
) )
type SyncSender interface { type SyncSender interface {

View file

@ -7,8 +7,9 @@ import (
"testing" "testing"
"time" "time"
"goadb/internal/errors"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/zach-klippenstein/goadb/internal/errors"
) )
var ( var (

View file

@ -6,7 +6,7 @@ import (
"regexp" "regexp"
"sync" "sync"
"github.com/zach-klippenstein/goadb/internal/errors" "goadb/internal/errors"
) )
// ErrorResponseDetails is an error message returned by the server for a particular request. // ErrorResponseDetails is an error message returned by the server for a particular request.

View file

@ -3,8 +3,9 @@ package wire
import ( import (
"testing" "testing"
"goadb/internal/errors"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/zach-klippenstein/goadb/internal/errors"
) )
func TestAdbServerError_NoRequest(t *testing.T) { func TestAdbServerError_NoRequest(t *testing.T) {