-
Notifications
You must be signed in to change notification settings - Fork 332
/
repo_create.go
53 lines (46 loc) · 1.55 KB
/
repo_create.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
49
50
51
52
53
package cmd
import (
"fmt"
"net/http"
"github.com/spf13/cobra"
"github.com/treeverse/lakefs/pkg/api/apigen"
)
const (
DefaultBranch = "main"
repoCreateCmdArgs = 2
)
// repoCreateCmd represents the create repo command
var repoCreateCmd = &cobra.Command{
Use: "create <repository URI> <storage namespace>",
Short: "Create a new repository",
Example: "lakectl repo create " + myRepoExample + " " + myBucketExample,
Args: cobra.ExactArgs(repoCreateCmdArgs),
ValidArgsFunction: ValidArgsRepository,
Run: func(cmd *cobra.Command, args []string) {
clt := getClient()
u := MustParseRepoURI("repository URI", args[0])
fmt.Println("Repository:", u)
defaultBranch, err := cmd.Flags().GetString("default-branch")
if err != nil {
DieErr(err)
}
resp, err := clt.CreateRepositoryWithResponse(cmd.Context(),
&apigen.CreateRepositoryParams{},
apigen.CreateRepositoryJSONRequestBody{
Name: u.Repository,
StorageNamespace: args[1],
DefaultBranch: &defaultBranch,
})
DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusCreated)
if resp.JSON201 == nil {
Die("Bad response from server", 1)
}
repo := resp.JSON201
fmt.Printf("Repository '%s' created:\nstorage namespace: %s\ndefault branch: %s\ntimestamp: %d\n", repo.Id, repo.StorageNamespace, repo.DefaultBranch, repo.CreationDate)
},
}
//nolint:gochecknoinits
func init() {
repoCreateCmd.Flags().StringP("default-branch", "d", DefaultBranch, "the default branch of this repository")
repoCmd.AddCommand(repoCreateCmd)
}