github.com/axw/juju@v0.0.0-20161005053422-4bd6544d08d4/cmd/plugins/juju-metadata/metadata.go (about) 1 // Copyright 2012, 2013 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package main 5 6 import ( 7 "fmt" 8 "os" 9 10 "github.com/juju/cmd" 11 "github.com/juju/loggo" 12 "github.com/juju/utils/featureflag" 13 14 "github.com/juju/juju/feature" 15 "github.com/juju/juju/juju" 16 "github.com/juju/juju/juju/osenv" 17 _ "github.com/juju/juju/provider/all" 18 ) 19 20 var logger = loggo.GetLogger("juju.plugins.metadata") 21 22 var metadataDoc = ` 23 Juju metadata is used to find the correct image and tools when bootstrapping a 24 Juju model. 25 ` 26 27 // Main registers subcommands for the juju-metadata executable, and hands over control 28 // to the cmd package. This function is not redundant with main, because it 29 // provides an entry point for testing with arbitrary command line arguments. 30 func Main(args []string) { 31 ctx, err := cmd.DefaultContext() 32 if err != nil { 33 fmt.Fprintf(os.Stderr, "error: %v\n", err) 34 os.Exit(2) 35 } 36 if err := juju.InitJujuXDGDataHome(); err != nil { 37 fmt.Fprintf(os.Stderr, "error: %s\n", err) 38 os.Exit(2) 39 } 40 os.Exit(cmd.Main(NewSuperCommand(), ctx, args[1:])) 41 } 42 43 // NewSuperCommand creates the metadata plugin supercommand and registers the 44 // subcommands that it supports. 45 func NewSuperCommand() cmd.Command { 46 metadatacmd := cmd.NewSuperCommand(cmd.SuperCommandParams{ 47 Name: "metadata", 48 UsagePrefix: "juju", 49 Doc: metadataDoc, 50 Purpose: "tools for generating and validating image and tools metadata", 51 Log: &cmd.Log{}}) 52 53 metadatacmd.Register(newValidateImageMetadataCommand()) 54 metadatacmd.Register(newImageMetadataCommand()) 55 metadatacmd.Register(newToolsMetadataCommand()) 56 metadatacmd.Register(newValidateToolsMetadataCommand()) 57 metadatacmd.Register(newSignMetadataCommand()) 58 if featureflag.Enabled(feature.ImageMetadata) { 59 metadatacmd.Register(newListImagesCommand()) 60 metadatacmd.Register(newAddImageMetadataCommand()) 61 metadatacmd.Register(newDeleteImageMetadataCommand()) 62 } 63 return metadatacmd 64 } 65 66 func init() { 67 featureflag.SetFlagsFromEnvironment(osenv.JujuFeatureFlagEnvKey) 68 } 69 70 func main() { 71 Main(os.Args) 72 }