-
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
2898 lakectl annotate output has superfluous spaces and blank lines #3007
2898 lakectl annotate output has superfluous spaces and blank lines #3007
Conversation
nessie/lakectl_util.go
Outdated
@@ -122,6 +122,7 @@ func sanitize(output string, vars map[string]string) string { | |||
s = normalizeRandomObjectKey(s, vars["STORAGE"]) | |||
s = normalizeCommitID(s) | |||
s = normalizeChecksum(s) | |||
s = normalizeShortCommitID(s) | |||
return strings.ReplaceAll(s, "\r\n", "\n") |
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.
general note - if we do this one first, there is no need to keep the regexp patterns \r?\n
compatible
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.
@nopcoder - not sure I understand this one. Can you please specify what is 'this' in '... this one first'?
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.
replace new lines before running all the regexp patterns
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.
Done
nessie/lakectl_test.go
Outdated
} | ||
|
||
// create fresh repo with 'main' branch | ||
RunCmdAndVerifySuccessWithFile(t, Lakectl()+" repo create lakefs://"+repoName+" "+storage, false, "lakectl_repo_create", vars) |
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.
Suggestion to use the table driven format - it will structure the following code and will report each one as a test:
tests := []struct {
Name string
Cmd string
Golden string
Vars map[string]string
}{
{
Name: "log not found",
Cmd: "log lakefs://" + repoName + "/" + mainBranch,
Golden: "lakectl_log_404",
Vars: map[string]string{"REPO": repoName, "STORAGE": storage, "BRANCH": mainBranch},
},
}
for _, tt := range tests {
t.Run(tt.Name, func(t *testing.T) {
RunCmdAndVerifyFailureWithFile(t, Lakectl()+" "+tt.Cmd, false, tt.Golden, vars)
})
}
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.
@nopcoder - I like the idea, but I think it is too large of a change to be included with this bug fix.
How about I create an issue for that?
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.
Opened #3021 to handle this
nessie/lakectl_util.go
Outdated
@@ -199,6 +201,11 @@ func normalizeCommitID(output string) string { | |||
return string(s) | |||
} | |||
|
|||
func normalizeShortCommitID(output string) string { | |||
s := shortCommitIDRegExp.ReplaceAll([]byte(output), []byte("<COMMIT_ID_16>")) |
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.
Relevant for other places, Go supply the 'string' variant - use: ReplaceAllString
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.
Same as for the previous one - Let's have it as a different PR, along with the refactoring to table-driven. Something like 'Lakectl Test Refactoring'. WDYT?
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.
Done
cmd/lakectl/cmd/annotate.go
Outdated
client := getClient() | ||
pfx := api.PaginationPrefix(*pathURI.Path) | ||
context := cmd.Context() | ||
resp, err := client.ListObjectsWithResponse(context, pathURI.Repository, pathURI.Ref, &api.ListObjectsParams{Prefix: &pfx}) | ||
DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusOK) | ||
const delimiter = "/" |
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.
Is this necessary?
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.
Not really necessary, but it is also used the same way in other commands (lakectl fs
)
I refactored it to be a const in common_helpers
cmd/lakectl/cmd/annotate.go
Outdated
@@ -29,23 +28,36 @@ var annotateCmd = &cobra.Command{ | |||
Args: cobra.ExactArgs(1), | |||
Run: func(cmd *cobra.Command, args []string) { | |||
pathURI := MustParsePathURI("path", args[0]) | |||
recursive, _ := cmd.Flags().GetBool("recursive") |
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.
can make "recursive" const as being used for command registration (line 97) and value retrieval.
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.
It will "break" the way we register other flags, including "recursive" in lakectl fs
commands. If we change it in all places it interfere with the readability of the commands regsitration, so I think it is better to leave it like that.
@Jonathan-Rosenberg - WDYT?
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.
Interesting... I did see that we use string literals and not variables when defining flags and retrieving their values, but is it a good practice?
Anyway it's not a deal breaker so we can leave it that way.
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.
Noice
Co-authored-by: Idan Novogroder <43949240+idanovo@users.noreply.github.com>
Co-authored-by: talSofer <tal.sofer@treeverse.io>
Co-authored-by: shimi9276 <71839784+shimi9276@users.noreply.github.com>
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.
lgtm
@@ -32,6 +32,11 @@ var ErrInvalidValueInList = errors.New("empty string in list") | |||
|
|||
var accessKeyRegexp = regexp.MustCompile(`^AKIA[I|J][A-Z0-9]{14}Q$`) | |||
|
|||
// const values used by lakectl commands |
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.
Can remove this one - we are in common_helpers under lakectl
@@ -32,6 +32,11 @@ var ErrInvalidValueInList = errors.New("empty string in list") | |||
|
|||
var accessKeyRegexp = regexp.MustCompile(`^AKIA[I|J][A-Z0-9]{14}Q$`) | |||
|
|||
// const values used by lakectl commands | |||
const ( |
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.
general note - not actionable to this pr - but it looks like we have a lot of 'const' blocks here
…us-spaces-and-blank-lines
lakectl annotate output:
Removed line break at the beginning of output line
Removed padding from commit message field