Example #1
0
func createAction(context *cli.Context) {
	if !context.Args().Present() {
		println("You must specify a 'name' for the box you want to create.\nSee 'farmer create --help' for more info.")
		return
	}

	if context.String("repo") == "" {
		println("You must specify a 'repo' (Git repository Url) to clone code on the box.\nSee 'farmer create --help' for more info.")
		return
	}

	if context.String("pathspec") == "" {
		println("Warning: Box will clone 'master' branch of the provided repository.")
		return
	}

	stream := hub.Stream{}
	request := request.CreateRequest{
		Name:     context.Args().First(),
		RepoUrl:  context.String("repo"),
		Pathspec: context.String("pathspec"),
	}

	if err := api.Post("/boxes", &request, &stream); err != nil {
		println(err.Error())
		return
	}

	if err := stream.Consume(); err != nil {
		println("Could not consume the stream from Farmer server.")
		return
	}
}
Example #2
0
func deployAction(context *cli.Context) {
	if !context.Args().Present() {
		println("You must specify a 'name' for the box you want to create.\nSee 'farmer create --help' for more info.")
		return
	}

	if context.String("pathspec") == "" {
		println("You must specify a 'pathspec' (Git branch specifier) to pull the code from.\nSee 'farmer create --help' for more info.")
		return
	}

	stream := hub.Stream{}
	request := request.DeployRequest{
		Pathspec: context.String("pathspec"),
	}

	if err := api.Put("/boxes/"+context.Args().First(), &request, &stream); err != nil {
		println(err.Error())
		return
	}

	if err := stream.Consume(); err != nil {
		println("Could not consume the stream from Farmer server.")
		return
	}
}