diff --git a/cmd/lakectl/cmd/repo_create.go b/cmd/lakectl/cmd/repo_create.go index c8c5c998527..ad7b859407c 100644 --- a/cmd/lakectl/cmd/repo_create.go +++ b/cmd/lakectl/cmd/repo_create.go @@ -11,6 +11,8 @@ import ( const ( DefaultBranch = "main" + SampleDataFlag = "sample-data" + repoCreateCmdArgs = 2 ) @@ -25,29 +27,34 @@ var repoCreateCmd = &cobra.Command{ clt := getClient() u := MustParseRepoURI("repository URI", args[0]) fmt.Println("Repository:", u) - defaultBranch, err := cmd.Flags().GetString("default-branch") - if err != nil { - DieErr(err) - } + defaultBranch := Must(cmd.Flags().GetString("default-branch")) + sampleData := Must(cmd.Flags().GetBool(SampleDataFlag)) + resp, err := clt.CreateRepositoryWithResponse(cmd.Context(), &apigen.CreateRepositoryParams{}, apigen.CreateRepositoryJSONRequestBody{ Name: u.Repository, StorageNamespace: args[1], DefaultBranch: &defaultBranch, + SampleData: &sampleData, }) 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) + fmt.Printf("Repository '%s' created:\nstorage namespace: %s\ndefault branch: %s\ntimestamp: %d\n", + repo.Id, repo.StorageNamespace, repo.DefaultBranch, repo.CreationDate) + if sampleData { + fmt.Printf("sample data included\n") + } }, } //nolint:gochecknoinits func init() { repoCreateCmd.Flags().StringP("default-branch", "d", DefaultBranch, "the default branch of this repository") + repoCreateCmd.Flags().Bool(SampleDataFlag, false, "create sample data in the repository") repoCmd.AddCommand(repoCreateCmd) } diff --git a/docs/reference/cli.md b/docs/reference/cli.md index 8e5cf108b68..d1f852bc5a3 100644 --- a/docs/reference/cli.md +++ b/docs/reference/cli.md @@ -2626,6 +2626,7 @@ lakectl repo create lakefs://my-repo s3://my-bucket ``` -d, --default-branch string the default branch of this repository (default "main") -h, --help help for create + --sample-data create sample data in the repository ``` diff --git a/esti/golden/lakectl_repo_create.golden b/esti/golden/lakectl_repo_create.golden index 979c8048082..31c11300734 100644 --- a/esti/golden/lakectl_repo_create.golden +++ b/esti/golden/lakectl_repo_create.golden @@ -2,4 +2,4 @@ Repository: lakefs://${REPO} Repository '${REPO}' created: storage namespace: ${STORAGE} default branch: ${BRANCH} -timestamp: \ No newline at end of file +timestamp: diff --git a/esti/golden/lakectl_repo_create_sample.golden b/esti/golden/lakectl_repo_create_sample.golden new file mode 100644 index 00000000000..3b1b0540c36 --- /dev/null +++ b/esti/golden/lakectl_repo_create_sample.golden @@ -0,0 +1,6 @@ +Repository: lakefs://${REPO} +Repository '${REPO}' created: +storage namespace: ${STORAGE} +default branch: ${BRANCH} +timestamp: +sample data included diff --git a/esti/lakectl_test.go b/esti/lakectl_test.go index 7f8198457b5..2d3f67e90c1 100644 --- a/esti/lakectl_test.go +++ b/esti/lakectl_test.go @@ -101,6 +101,16 @@ func TestLakectlBasicRepoActions(t *testing.T) { // Trying to delete again RunCmdAndVerifyFailureWithFile(t, Lakectl()+" repo delete lakefs://"+repoName2+" -y", false, "lakectl_repo_delete_not_found", vars) + + // Create repository with sample data + repoName3 := generateUniqueRepositoryName() + storage3 := generateUniqueStorageNamespace(repoName3) + vars = map[string]string{ + "REPO": repoName3, + "STORAGE": storage3, + "BRANCH": mainBranch, + } + RunCmdAndVerifySuccessWithFile(t, Lakectl()+" repo create lakefs://"+repoName3+" "+storage3+" --sample-data", false, "lakectl_repo_create_sample", vars) } func TestLakectlPreSignUpload(t *testing.T) { @@ -428,7 +438,6 @@ func TestLakectlLogNoMergesWithCommitsAndMerges(t *testing.T) { // log the commits without merges RunCmdAndVerifySuccessWithFile(t, Lakectl()+" log lakefs://"+repoName+"/"+mainBranch+" --no-merges", false, "lakectl_log_no_merges", vars) - } func TestLakectlLogNoMergesAndAmount(t *testing.T) { @@ -480,8 +489,8 @@ func TestLakectlLogNoMergesAndAmount(t *testing.T) { // log the commits without merges RunCmdAndVerifySuccessWithFile(t, Lakectl()+" log lakefs://"+repoName+"/"+mainBranch+" --no-merges --amount=2", false, "lakectl_log_no_merges_amount", vars) - } + func TestLakectlAnnotate(t *testing.T) { repoName := generateUniqueRepositoryName() storage := generateUniqueStorageNamespace(repoName) @@ -577,7 +586,6 @@ func TestLakectlAuthUsers(t *testing.T) { // testing without user email for now, since it is a pain to config esti with a mail func TestLakectlIdentity(t *testing.T) { - userId := "mike" vars := map[string]string{ "ID": userId, @@ -690,7 +698,6 @@ func TestLakectlFsUpload(t *testing.T) { t.Run("single_file_with_recursive", func(t *testing.T) { vars["FILE_PATH"] = "data/ro/ro_1k.0" RunCmdAndVerifySuccessWithFile(t, Lakectl()+" fs upload --recursive -s files/ro_1k lakefs://"+repoName+"/"+mainBranch+"/"+vars["FILE_PATH"]+" -s files/ro_1k", false, "lakectl_fs_upload", vars) - }) t.Run("dir", func(t *testing.T) { vars["FILE_PATH"] = "data/ro/" diff --git a/esti/lakectl_util.go b/esti/lakectl_util.go index ef2fa55273e..8bdc7a7757e 100644 --- a/esti/lakectl_util.go +++ b/esti/lakectl_util.go @@ -25,7 +25,7 @@ var ( ) var ( - reTimestamp = regexp.MustCompile(`timestamp: \d+\n`) + reTimestamp = regexp.MustCompile(`timestamp: \d+`) reTime = regexp.MustCompile(`\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} [-+]\d{4} \w{1,4}`) reCommitID = regexp.MustCompile(`[\d|a-f]{64}`) reShortCommitID = regexp.MustCompile(`[\d|a-f]{16}`)