-
Notifications
You must be signed in to change notification settings - Fork 367
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add --storage-id flag to Repo Create CLI #8557
Changes from 18 commits
ad9e32c
94a246c
5411788
9a76eac
c7ac2e2
efe5832
44a2706
c5bdb3c
06aac0f
71e445a
3700ede
c6b4cbb
8b7c88d
2049918
4159a45
0e64d9e
9242822
4b19558
382207a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,9 +9,9 @@ import ( | |
) | ||
|
||
const ( | ||
DefaultBranch = "main" | ||
|
||
SampleDataFlag = "sample-data" | ||
defaultBranchFlagName = "default-branch" | ||
defaultBranchFlagValue = "main" | ||
sampleDataFlagName = "sample-data" | ||
|
||
repoCreateCmdArgs = 2 | ||
) | ||
|
@@ -27,13 +27,19 @@ var repoCreateCmd = &cobra.Command{ | |
clt := getClient() | ||
u := MustParseRepoURI("repository URI", args[0]) | ||
fmt.Println("Repository:", u) | ||
defaultBranch := Must(cmd.Flags().GetString("default-branch")) | ||
sampleData := Must(cmd.Flags().GetBool(SampleDataFlag)) | ||
|
||
defaultBranch := Must(cmd.Flags().GetString(defaultBranchFlagName)) | ||
sampleData := Must(cmd.Flags().GetBool(sampleDataFlagName)) | ||
storageID, err := cmd.Flags().GetString(storageIDFlagName) | ||
if err != nil { | ||
DieErr(err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the difference between the Must and this error handling? What is the reason for this change? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's some merges mixed up. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Following a talk with @N-o-Z - |
||
} | ||
|
||
resp, err := clt.CreateRepositoryWithResponse(cmd.Context(), | ||
&apigen.CreateRepositoryParams{}, | ||
apigen.CreateRepositoryJSONRequestBody{ | ||
Name: u.Repository, | ||
StorageId: &storageID, | ||
StorageNamespace: args[1], | ||
DefaultBranch: &defaultBranch, | ||
SampleData: &sampleData, | ||
|
@@ -53,8 +59,9 @@ var repoCreateCmd = &cobra.Command{ | |
|
||
//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") | ||
repoCreateCmd.Flags().StringP(defaultBranchFlagName, "d", defaultBranchFlagValue, "the default branch of this repository") | ||
repoCreateCmd.Flags().Bool(sampleDataFlagName, false, "create sample data in the repository") | ||
withStorageID(repoCreateCmd) | ||
|
||
repoCmd.AddCommand(repoCreateCmd) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,16 +20,18 @@ var repoCreateBareCmd = &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(defaultBranchFlagName)) | ||
storageID, _ := cmd.Flags().GetString(storageIDFlagName) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Must |
||
|
||
bareRepo := true | ||
|
||
resp, err := clt.CreateRepositoryWithResponse(cmd.Context(), &apigen.CreateRepositoryParams{ | ||
Bare: &bareRepo, | ||
}, apigen.CreateRepositoryJSONRequestBody{ | ||
DefaultBranch: &defaultBranch, | ||
Name: u.Repository, | ||
StorageId: &storageID, | ||
StorageNamespace: args[1], | ||
}) | ||
DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusCreated) | ||
|
@@ -43,7 +45,8 @@ var repoCreateBareCmd = &cobra.Command{ | |
|
||
//nolint:gochecknoinits | ||
func init() { | ||
repoCreateBareCmd.Flags().StringP("default-branch", "d", DefaultBranch, "the default branch name of this repository (will not be created)") | ||
repoCreateBareCmd.Flags().StringP(defaultBranchFlagName, "d", defaultBranchFlagValue, "the default branch name of this repository (will not be created)") | ||
withStorageID(repoCreateBareCmd) | ||
|
||
repoCmd.AddCommand(repoCreateBareCmd) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -158,6 +158,7 @@ var ( | |
const ( | ||
recursiveFlagName = "recursive" | ||
recursiveFlagShort = "r" | ||
storageIDFlagName = "storage-id" | ||
presignFlagName = "pre-sign" | ||
parallelismFlagName = "parallelism" | ||
noProgressBarFlagName = "no-progress" | ||
|
@@ -187,6 +188,13 @@ func withRecursiveFlag(cmd *cobra.Command, usage string) { | |
cmd.Flags().BoolP(recursiveFlagName, recursiveFlagShort, false, usage) | ||
} | ||
|
||
func withStorageID(cmd *cobra.Command) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Clean code- add a one line comment explaining what this does There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't clean code about self-explained code? And again, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, hmm I find it takes me a while to read this function and understand what I'm looking at. Maybe a better function name rather than a comment? Maybe it should be addStorageID? withStorageID sounds like it's more of a query checking if the command has this flag than a command that does something There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the convention for global flags in lakectl... |
||
cmd.Flags().String(storageIDFlagName, "", "") | ||
if err := cmd.Flags().MarkHidden(storageIDFlagName); err != nil { | ||
DieErr(err) | ||
} | ||
} | ||
|
||
func withParallelismFlag(cmd *cobra.Command) { | ||
cmd.Flags().IntP(parallelismFlagName, "p", defaultParallelism, | ||
"Max concurrent operations to perform") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Repository: lakefs://${REPO} | ||
storage id: invalid value: validation error | ||
400 Bad Request |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should also be under a Must
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't the --storage flag optional for the OSS?