-
Notifications
You must be signed in to change notification settings - Fork 9
/
ensure.go
48 lines (42 loc) · 1.16 KB
/
ensure.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package cliaws
import (
"context"
"fmt"
"os"
"github.com/alexflint/go-arg"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/codecommit"
"github.com/nathants/libaws/lib"
)
func init() {
lib.Commands["codecommit-ensure"] = codeCommitEnsure
lib.Args["codecommit-ensure"] = codeCommitEnsureArgs{}
}
type codeCommitEnsureArgs struct {
Name string `arg:"positional,required"`
Descr string `arg:"-d,--description"`
}
func (codeCommitEnsureArgs) Description() string {
return `
ensure a codecommit repository
`
}
func codeCommitEnsure() {
var args codeCommitEnsureArgs
arg.MustParse(&args)
ctx := context.Background()
createOut, err := lib.CodeCommitClient().CreateRepositoryWithContext(ctx, &codecommit.CreateRepositoryInput{
RepositoryName: aws.String(args.Name),
RepositoryDescription: aws.String(args.Descr),
})
if err == nil {
fmt.Fprintln(os.Stderr, "created:", args.Name)
fmt.Println(lib.Pformat(createOut.RepositoryMetadata))
return
}
aerr, ok := err.(awserr.Error)
if !ok || aerr.Code() != codecommit.ErrCodeRepositoryNameExistsException {
lib.Logger.Fatal("error: ", err)
}
}