@@ -2,6 +2,7 @@ package main
2
2
3
3
import (
4
4
"errors"
5
+ "fmt"
5
6
"log"
6
7
"os"
7
8
@@ -22,14 +23,15 @@ func createApp() (*cli.App, *cmdOptions) {
22
23
app := cli .NewApp ()
23
24
app .EnableBashCompletion = true
24
25
app .Name = "img2lambda"
25
- app .Usage = "Repackages a container image into Lambda layers and publishes them to Lambda"
26
+ app .Usage = "Repackages a container image into AWS Lambda layers and publishes them to Lambda"
26
27
app .Action = func (c * cli.Context ) error {
28
+ validateCliOptions (& opts , c )
27
29
return repackImageAction (& opts )
28
30
}
29
31
app .Flags = []cli.Flag {
30
32
cli.StringFlag {
31
33
Name : "image, i" ,
32
- Usage : "Name of the source container image. For example, 'my-docker-image:latest'" ,
34
+ Usage : "Name of the source container image. For example, 'my-docker-image:latest'. The Docker daemon must be pulled locally already. " ,
33
35
Destination : & opts .image ,
34
36
},
35
37
cli.StringFlag {
@@ -56,9 +58,20 @@ func createApp() (*cli.App, *cmdOptions) {
56
58
Destination : & opts .dryRun ,
57
59
},
58
60
}
61
+
62
+ app .Setup ()
63
+ app .Commands = []cli.Command {}
64
+
59
65
return app , & opts
60
66
}
61
67
68
+ func validateCliOptions (opts * cmdOptions , context * cli.Context ) {
69
+ if opts .image == "" {
70
+ fmt .Println ("ERROR: Image name is required\n " )
71
+ cli .ShowAppHelpAndExit (context , 1 )
72
+ }
73
+ }
74
+
62
75
func repackImageAction (opts * cmdOptions ) error {
63
76
layers , err := RepackImage ("docker-daemon:" + opts .image , opts .outputDir )
64
77
if err != nil {
@@ -84,6 +97,5 @@ func main() {
84
97
err := app .Run (os .Args )
85
98
if err != nil {
86
99
log .Fatal (err )
87
- os .Exit (1 )
88
100
}
89
101
}
0 commit comments