| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 The LUCI Authors. All rights reserved. | |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | |
| 3 // that can be found in the LICENSE file. | |
| 4 | |
| 5 package main | |
| 6 | |
| 7 import ( | |
| 8 "fmt" | |
| 9 "strconv" | |
| 10 | |
| 11 "github.com/maruel/subcommands" | |
| 12 | |
| 13 "github.com/luci/luci-go/common/cli" | |
| 14 "github.com/luci/luci-go/common/logging" | |
| 15 ) | |
| 16 | |
| 17 var cmdCancel = &subcommands.Command{ | |
| 18 UsageLine: `cancel [flags] <build id>`, | |
| 19 ShortDesc: "Cancel a build", | |
| 20 LongDesc: "Attempt to cancel an existing build.", | |
| 21 CommandRun: func() subcommands.CommandRun { | |
| 22 c := &cancelRun{} | |
| 23 c.SetDefaultFlags() | |
| 24 return c | |
| 25 }, | |
| 26 } | |
| 27 | |
| 28 type cancelRun struct { | |
| 29 baseCommandRun | |
| 30 } | |
| 31 | |
| 32 func (r *cancelRun) Run(a subcommands.Application, args []string) int { | |
| 33 ctx := cli.GetContext(a, r) | |
| 34 if len(args) < 1 { | |
| 35 logging.Errorf(ctx, "missing parameter: <Build ID>") | |
| 36 return 1 | |
| 37 } else if len(args) > 1 { | |
| 38 logging.Errorf(ctx, "unexpected arguments: %s", args[1:]) | |
| 39 } | |
| 40 | |
| 41 buildId, err := strconv.ParseInt(args[0], 10, 64) | |
| 42 if err != nil { | |
| 43 logging.Errorf(ctx, "expected a build id (int64): %s", err) | |
| 44 return 1 | |
| 45 } | |
| 46 | |
| 47 service, err := r.makeService(ctx, a) | |
| 48 if err != nil { | |
| 49 return 1 | |
| 50 } | |
| 51 | |
| 52 response, err := service.Cancel(buildId).Do() | |
| 53 if err != nil { | |
| 54 logging.Errorf(ctx, "buildbucket.Cancel failed: %s", err) | |
| 55 return 1 | |
| 56 } | |
| 57 | |
| 58 responseJSON, err := response.MarshalJSON() | |
| 59 if err != nil { | |
| 60 logging.Errorf(ctx, "could not unmarshal response: %s", err) | |
| 61 return 1 | |
| 62 } | |
| 63 | |
| 64 fmt.Println(string(responseJSON)) | |
| 65 return 0 | |
| 66 } | |
| OLD | NEW |