Skip to content

Commit 588c5fb

Browse files
murphm8jchionh
authored andcommitted
Mod (#3)
* Add cmd/cli * Fix tests and cli. Add go.mod.
1 parent a875021 commit 588c5fb

18 files changed

+128
-32
lines changed

cmd/cli/main.go

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"io/ioutil"
6+
"log"
7+
"os"
8+
9+
"github.com/aws-robotics/aws-robomaker-bundle-support-library/pkg/bundle"
10+
"github.com/aws-robotics/aws-robomaker-bundle-support-library/pkg/file_system"
11+
"github.com/aws-robotics/aws-robomaker-bundle-support-library/pkg/store"
12+
"github.com/urfave/cli"
13+
)
14+
15+
16+
func main() {
17+
app := cli.NewApp()
18+
app.Name = "Bundle Info"
19+
app.Usage = "Get source command for bundle"
20+
app.Flags = []cli.Flag {
21+
cli.StringFlag{Name: "bundle", Value: "", Usage: "Path to bundle file"},
22+
cli.StringFlag{Name: "prefix", Value: "", Usage: "Prefix to put onto the source command"},
23+
}
24+
app.Action = func(c *cli.Context) error {
25+
fmt.Println("Opening ", c.String("bundle"))
26+
cache_path := "./cache"
27+
bundle_store := store.NewSimpleStore(cache_path, file_system.NewLocalFS())
28+
29+
bundle_path := c.String("bundle")
30+
prefix_path := c.String("prefix")
31+
32+
files, err := ioutil.ReadDir(cache_path)
33+
if err != nil {
34+
log.Fatal(err)
35+
}
36+
37+
var keys []string
38+
for _, file := range files {
39+
if file.IsDir() {
40+
keys = append(keys, file.Name())
41+
}
42+
}
43+
44+
err = bundle_store.Load(keys)
45+
if err != nil {
46+
log.Fatal(err)
47+
return err
48+
}
49+
50+
bundle_provider := bundle.NewBundleProvider(bundle_store)
51+
b, err := bundle_provider.GetBundle(bundle_path)
52+
if err != nil {
53+
log.Fatal(err)
54+
return err
55+
}
56+
for i := 0; i < len(b.PosixSourceCommands()); i++ {
57+
fmt.Print(b.PosixSourceCommandsUsingLocation(prefix_path)[i])
58+
}
59+
60+
return nil
61+
}
62+
app.Run(os.Args)
63+
}
64+
65+
66+

go.mod

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module github.com/aws-robotics/aws-robomaker-bundle-support-library
2+
3+
go 1.12
4+
5+
require (
6+
github.com/aws/aws-sdk-go v1.19.11
7+
github.com/golang/mock v1.2.0
8+
github.com/google/uuid v1.1.1
9+
github.com/stretchr/testify v1.3.0
10+
github.com/urfave/cli v1.20.0
11+
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 // indirect
12+
)

go.sum

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
github.com/aws/aws-sdk-go v1.19.11 h1:tqaTGER6Byw3QvsjGW0p018U2UOqaJPeJuzoaF7jjoQ=
2+
github.com/aws/aws-sdk-go v1.19.11/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
3+
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
4+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
5+
github.com/golang/mock v1.2.0 h1:28o5sBqPkBsMGnC6b4MvE2TzSr5/AT4c/1fLqVGIwlk=
6+
github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
7+
github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
8+
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
9+
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af h1:pmfjZENx5imkbgOkpRUYLnmbU7UEFbjtDA2hxJ1ichM=
10+
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
11+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
12+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
13+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
14+
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
15+
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
16+
github.com/urfave/cli v1.20.0 h1:fDqGv3UG/4jbVl/QkFwEdddtEDjh/5Ov6X+0B/3bPaw=
17+
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
18+
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
19+
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 h1:0GoQqolDA55aaLxZyTzK/Y2ePZzZTUrRacwib7cNsYQ=
20+
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
21+
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
22+
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
23+
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=

pkg/bundle/bundle.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
package bundle
55

6-
//go:generate $MOCKGEN -destination=mock_bundle.go -package=bundle go.amzn.com/robomaker/bundle_support/bundle Bundle
6+
//go:generate mockgen -destination=mock_bundle.go -package=bundle github.com/aws-robotics/aws-robomaker-bundle-support-library/pkg/bundle Bundle
77

88
import (
99
"fmt"

pkg/archive/bundle_archive.go renamed to pkg/bundle/bundle_archive.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
// Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
package archive
4+
package bundle
55

66
import (
77
"archive/tar"
88
"errors"
99
"fmt"
10-
"github.com/aws-robotics/aws-robomaker-bundle-support-library/pkg/bundle"
1110
"github.com/aws-robotics/aws-robomaker-bundle-support-library/pkg/extractors"
1211
"github.com/aws-robotics/aws-robomaker-bundle-support-library/pkg/store"
1312
"io"
@@ -24,7 +23,7 @@ type BundleArchive interface {
2423
Version() string
2524

2625
// Extract everything into the cache
27-
Extract(bundleCache store.BundleStore) (bundle.Bundle, error)
26+
Extract(bundleCache store.BundleStore) (Bundle, error)
2827
}
2928

3029
type bundleArchive struct {
@@ -61,7 +60,7 @@ func (b *bundleArchive) Version() string {
6160
return b.version
6261
}
6362

64-
func (b *bundleArchive) Extract(bundleStore store.BundleStore) (bundle.Bundle, error) {
63+
func (b *bundleArchive) Extract(bundleStore store.BundleStore) (Bundle, error) {
6564
return b.bundleProcessor.Extract(b.inputStream, bundleStore)
6665
}
6766

pkg/archive/bundle_processor.go renamed to pkg/bundle/bundle_processor.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
// Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
package archive
4+
package bundle
55

66
import (
7-
"github.com/aws-robotics/aws-robomaker-bundle-support-library/pkg/bundle"
87
"github.com/aws-robotics/aws-robomaker-bundle-support-library/pkg/store"
98
"io"
109
)
@@ -19,7 +18,7 @@ const (
1918
type BundleProcessor interface {
2019

2120
// Extract takes the bundle bytes and extracts everything into the bundle store
22-
Extract(inputStream io.ReadSeeker, bundleCache store.BundleStore) (bundle.Bundle, error)
21+
Extract(inputStream io.ReadSeeker, bundleCache store.BundleStore) (Bundle, error)
2322
}
2423

2524
func BundleProcessorForVersion(version string) BundleProcessor {

pkg/archive/bundle_processor_test.go renamed to pkg/bundle/bundle_processor_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
package archive
4+
package bundle
55

66
import (
77
"github.com/stretchr/testify/assert"

pkg/archive/bundle_processor_v1.go renamed to pkg/bundle/bundle_processor_v1.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
// Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
package archive
4+
package bundle
55

66
import (
7-
"github.com/aws-robotics/aws-robomaker-bundle-support-library/pkg/bundle"
87
"github.com/aws-robotics/aws-robomaker-bundle-support-library/pkg/extractors"
98
"github.com/aws-robotics/aws-robomaker-bundle-support-library/pkg/store"
109
"github.com/google/uuid"
@@ -18,7 +17,7 @@ func NewBundleProcessorV1() BundleProcessor {
1817
// Bundle v1 simply extracts tar.gz
1918
type bundleProcessorV1 struct{}
2019

21-
func (b *bundleProcessorV1) Extract(inputStream io.ReadSeeker, bundleStore store.BundleStore) (bundle.Bundle, error) {
20+
func (b *bundleProcessorV1) Extract(inputStream io.ReadSeeker, bundleStore store.BundleStore) (Bundle, error) {
2221
// create a bundle extractor that knows how to extract the bundle
2322
bundleExtractor := extractors.NewBundleV1Extractor(inputStream)
2423

@@ -29,5 +28,5 @@ func (b *bundleProcessorV1) Extract(inputStream io.ReadSeeker, bundleStore store
2928
if putErr != nil {
3029
return nil, putErr
3130
}
32-
return bundle.NewBundle(bundleStore, []string{bundleKey}), nil
31+
return NewBundle(bundleStore, []string{bundleKey}), nil
3332
}

pkg/archive/bundle_processor_v1_test.go renamed to pkg/bundle/bundle_processor_v1_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
package archive
4+
package bundle
55

66
import (
77
"fmt"

pkg/archive/bundle_processor_v2.go renamed to pkg/bundle/bundle_processor_v2.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
// Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
package archive
4+
package bundle
55

66
import (
77
"archive/tar"
88
"compress/gzip"
99
"encoding/json"
1010
"fmt"
11-
"github.com/aws-robotics/aws-robomaker-bundle-support-library/pkg/bundle"
1211
"github.com/aws-robotics/aws-robomaker-bundle-support-library/pkg/extractors"
1312
"github.com/aws-robotics/aws-robomaker-bundle-support-library/pkg/store"
1413
"io"
@@ -30,7 +29,7 @@ func NewBundleProcessorV2() BundleProcessor {
3029
type bundleProcessorV2 struct {
3130
}
3231

33-
func (b *bundleProcessorV2) Extract(inputStream io.ReadSeeker, bundleStore store.BundleStore) (bundle.Bundle, error) {
32+
func (b *bundleProcessorV2) Extract(inputStream io.ReadSeeker, bundleStore store.BundleStore) (Bundle, error) {
3433

3534
// obtain the metadata from the bundle bytes
3635
metadataTarReader, metadataErr := getMetadataTarReader(inputStream)
@@ -73,7 +72,7 @@ func (b *bundleProcessorV2) Extract(inputStream io.ReadSeeker, bundleStore store
7372
_, _ = inputStream.Seek(0, io.SeekEnd)
7473

7574
// create a new bundle with item paths
76-
return bundle.NewBundle(bundleStore, itemKeys), nil
75+
return NewBundle(bundleStore, itemKeys), nil
7776
}
7877

7978
// from the input stream get the metadata tar reader

0 commit comments

Comments
 (0)