github.com/dahs81/otto@v0.2.1-0.20160126165905-6400716cf085/command/build.go (about) 1 package command 2 3 import ( 4 "fmt" 5 "strings" 6 ) 7 8 // BuildCommand is the command that builds a deployable artifact 9 // for this version of the app. 10 type BuildCommand struct { 11 Meta 12 } 13 14 func (c *BuildCommand) Run(args []string) int { 15 fs := c.FlagSet("build", FlagSetNone) 16 fs.Usage = func() { c.Ui.Error(c.Help()) } 17 18 if err := fs.Parse(args); err != nil { 19 return 1 20 } 21 22 // Show usage if build command was passed any arguments. 23 if len(args) != 0 { 24 fs.Usage() 25 return 1 26 } 27 28 // Load the appfile 29 app, err := c.Appfile() 30 if err != nil { 31 c.Ui.Error(err.Error()) 32 return 1 33 } 34 35 // Get a core 36 core, err := c.Core(app) 37 if err != nil { 38 c.Ui.Error(fmt.Sprintf( 39 "Error loading core: %s", err)) 40 return 1 41 } 42 43 // Build the artifact 44 if err := core.Build(); err != nil { 45 c.Ui.Error(fmt.Sprintf( 46 "Error building app: %s", err)) 47 return 1 48 } 49 50 return 0 51 } 52 53 func (c *BuildCommand) Synopsis() string { 54 return "Build the deployable artifact for the app" 55 } 56 57 func (c *BuildCommand) Help() string { 58 helpText := ` 59 Usage: otto build [options] 60 61 Builds the deployable artifact for the app on the target 62 infrastructure specified during compilation of the Appfile. 63 64 This will build and inventory the artifact that is deployable 65 for the app represented by this Appfile. 66 67 ` 68 69 return strings.TrimSpace(helpText) 70 }