@@ -16,11 +16,13 @@ Usage:
16
16
package main
17
17
18
18
import (
19
+ "errors"
19
20
"fmt"
20
21
"github.com/aws-robotics/aws-robomaker-bundle-support-library/pkg/stream/local"
21
22
"io/ioutil"
22
23
"log"
23
24
"os"
25
+ "path/filepath"
24
26
25
27
"github.com/aws-robotics/aws-robomaker-bundle-support-library/pkg/bundle"
26
28
"github.com/aws-robotics/aws-robomaker-bundle-support-library/pkg/store"
@@ -45,9 +47,27 @@ func main() {
45
47
46
48
app .Action = func (c * cli.Context ) error {
47
49
cachePath := c .String ("cache" )
50
+ if _ , err := os .Stat (cachePath ); os .IsNotExist (err ) {
51
+ err = os .Mkdir (cachePath , os .ModePerm )
52
+ if err != nil {
53
+ fmt .Printf ("Failed to create cache directory: %s" , cachePath )
54
+ log .Fatal (err )
55
+ return err
56
+ }
57
+ }
48
58
bundleStore := store .NewSimpleStore (cachePath )
49
59
50
60
bundlePath := c .String ("bundle" )
61
+ if bundlePath == "" {
62
+ fmt .Println ("Bundle path cannot be empty." )
63
+ return errors .New ("bundle path cannot be empty" )
64
+ }
65
+ absBundlePath , err := filepath .Abs (bundlePath )
66
+ if err != nil {
67
+ fmt .Printf ("Bundle path is invalid: %s" , bundlePath )
68
+ log .Fatal (err )
69
+ return err
70
+ }
51
71
prefixPath := c .String ("prefix" )
52
72
53
73
files , err := ioutil .ReadDir (cachePath )
@@ -69,13 +89,13 @@ func main() {
69
89
}
70
90
71
91
bundleProvider := bundle .NewProvider (bundleStore )
72
- b , err := bundleProvider .GetBundle (bundlePath )
92
+ b , err := bundleProvider .GetBundle (absBundlePath )
73
93
if err != nil {
74
94
log .Fatal (err )
75
95
return err
76
96
}
77
97
for i := 0 ; i < len (b .PosixSourceCommands ()); i ++ {
78
- fmt .Print (b .PosixSourceCommandsUsingLocation (prefixPath )[i ])
98
+ fmt .Println (b .PosixSourceCommandsUsingLocation (prefixPath )[i ])
79
99
}
80
100
81
101
return nil
0 commit comments