@@ -17,13 +17,14 @@ limitations under the License.
1717package cmd
1818
1919import (
20- "context "
20+ "errors "
2121 goflag "flag"
2222 "fmt"
2323 "sort"
2424 "strings"
2525
2626 "github.com/GoogleCloudPlatform/container-diff/differs"
27+ pkgutil "github.com/GoogleCloudPlatform/container-diff/pkg/util"
2728 "github.com/GoogleCloudPlatform/container-diff/util"
2829 "github.com/docker/docker/client"
2930 "github.com/golang/glog"
@@ -37,20 +38,22 @@ var types string
3738
3839type validatefxn func (args []string ) error
3940
41+ const (
42+ DaemonPrefix = "daemon://"
43+ RemotePrefix = "remote://"
44+ )
45+
4046var RootCmd = & cobra.Command {
4147 Use : "container-diff" ,
4248 Short : "container-diff is a tool for analyzing and comparing container images" ,
43- Long : `container-diff is a CLI tool for analyzing and comparing container images.` ,
44- }
49+ Long : `container-diff is a CLI tool for analyzing and comparing container images.
4550
46- func NewClient () (* client.Client , error ) {
47- cli , err := client .NewEnvClient ()
48- if err != nil {
49- return nil , fmt .Errorf ("Error getting docker client: %s" , err )
50- }
51- cli .NegotiateAPIVersion (context .Background ())
51+ Images can be specified from either a local Docker daemon, or from a remote registry.
52+ To specify a local image, prefix the image ID with 'daemon://', e.g. 'daemon://gcr.io/foo/bar'.
53+ To specify a remote image, prefix the image ID with 'remote://', e.g. 'remote://gcr.io/foo/bar'.
54+ If no prefix is specified, the local daemon will be checked first.
5255
53- return cli , nil
56+ Tarballs can also be specified by simply providing the path to the .tar, .tar.gz, or .tgz file.` ,
5457}
5558
5659func outputResults (resultMap map [string ]util.Result ) {
@@ -92,7 +95,7 @@ func validateArgs(args []string, validatefxns ...validatefxn) error {
9295
9396func checkIfValidAnalyzer (flagtypes string ) error {
9497 if flagtypes == "" {
95- return nil
98+ return errors . New ( "Please provide at least one analyzer to run" )
9699 }
97100 analyzers := strings .Split (flagtypes , "," )
98101 for _ , name := range analyzers {
@@ -103,6 +106,30 @@ func checkIfValidAnalyzer(flagtypes string) error {
103106 return nil
104107}
105108
109+ func getPrepperForImage (image string ) (pkgutil.Prepper , error ) {
110+ cli , err := client .NewEnvClient ()
111+ if err != nil {
112+ return nil , err
113+ }
114+ if pkgutil .IsTar (image ) {
115+ return pkgutil.TarPrepper {
116+ Source : image ,
117+ Client : cli ,
118+ }, nil
119+
120+ } else if strings .HasPrefix (image , DaemonPrefix ) {
121+ return pkgutil.DaemonPrepper {
122+ Source : strings .Replace (image , DaemonPrefix , "" , - 1 ),
123+ Client : cli ,
124+ }, nil
125+ }
126+ // either has remote prefix or has no prefix, in which case we force remote
127+ return pkgutil.CloudPrepper {
128+ Source : strings .Replace (image , RemotePrefix , "" , - 1 ),
129+ Client : cli ,
130+ }, nil
131+ }
132+
106133func init () {
107134 pflag .CommandLine .AddGoFlagSet (goflag .CommandLine )
108135}
0 commit comments