github.com/engineyard/workflow-cli@v2.21.6+incompatible/parser/builds.go (about)

     1  package parser
     2  
     3  import (
     4  	"github.com/teamhephy/workflow-cli/cmd"
     5  	docopt "github.com/docopt/docopt-go"
     6  )
     7  
     8  // Builds routes build commands to their specific function.
     9  func Builds(argv []string, cmdr cmd.Commander) error {
    10  	usage := `
    11  Valid commands for builds:
    12  
    13  builds:list        list build history for an application
    14  builds:create      imports an image and deploys as a new release
    15  
    16  Use 'deis help [command]' to learn more.
    17  `
    18  
    19  	switch argv[0] {
    20  	case "builds:list":
    21  		return buildsList(argv, cmdr)
    22  	case "builds:create":
    23  		return buildsCreate(argv, cmdr)
    24  	default:
    25  		if printHelp(argv, usage) {
    26  			return nil
    27  		}
    28  
    29  		if argv[0] == "builds" {
    30  			argv[0] = "builds:list"
    31  			return buildsList(argv, cmdr)
    32  		}
    33  
    34  		PrintUsage(cmdr)
    35  		return nil
    36  	}
    37  }
    38  
    39  func buildsList(argv []string, cmdr cmd.Commander) error {
    40  	usage := `
    41  Lists build history for an application.
    42  
    43  Usage: deis builds:list [options]
    44  
    45  Options:
    46    -a --app=<app>
    47      the uniquely identifiable name for the application.
    48    -l --limit=<num>
    49      the maximum number of results to display, defaults to config setting
    50  `
    51  
    52  	args, err := docopt.Parse(usage, argv, true, "", false, true)
    53  
    54  	if err != nil {
    55  		return err
    56  	}
    57  
    58  	results, err := responseLimit(safeGetValue(args, "--limit"))
    59  
    60  	if err != nil {
    61  		return err
    62  	}
    63  
    64  	return cmdr.BuildsList(safeGetValue(args, "--app"), results)
    65  }
    66  
    67  func buildsCreate(argv []string, cmdr cmd.Commander) error {
    68  	usage := `
    69  Creates a new build of an application. Imports an <image> and deploys it to Deis
    70  as a new release. 
    71  
    72  Usage: deis builds:create <image> [options]
    73  
    74  Arguments:
    75    <image>
    76      A fully-qualified docker image, either from Docker Hub (e.g. deis/example-go:latest)
    77      or from an in-house registry (e.g. myregistry.example.com:5000/example-go:latest).
    78      This image must include the tag.
    79  
    80  Options:
    81    -a --app=<app>
    82      The uniquely identifiable name for the application.
    83    -p --procfile=<procfile>
    84      A YAML string used to supply a Procfile to the application.
    85  `
    86  
    87  	args, err := docopt.Parse(usage, argv, true, "", false, true)
    88  
    89  	if err != nil {
    90  		return err
    91  	}
    92  
    93  	app := safeGetValue(args, "--app")
    94  	image := safeGetValue(args, "<image>")
    95  	procfile := safeGetValue(args, "--procfile")
    96  
    97  	return cmdr.BuildsCreate(app, image, procfile)
    98  }