Skip to content

devpkg: use struct field values in FlakeRef.String #1597

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

Merged
merged 1 commit into from
Nov 1, 2023

Conversation

gcurtis
Copy link
Collaborator

@gcurtis gcurtis commented Oct 31, 2023

Improve FlakeRef.String so that it reassembles the flakeref using the current field values instead of returning the original parsed string that it came from. This makes it easier to modify parsed flakerefs or to create new ones from scratch.

The strings are normalized so that when two flakerefs are equal, their strings will also be equal. The docs for FlakeRef.String go into more detail on what the normalized form looks like.

Being able to parse/modify/encode flake references is part of the work to support multiple package outputs. Having a single (well-tested type) for handling flakes should help manage the complexity as another syntax for outputs is added.

Improve FlakeRef.String so that it reassembles the flakeref using the
current field values instead of returning the original parsed string
that it came from. This makes it easier to modify parsed flakerefs or to
create new ones from scratch.

The strings are normalized so that when two flakerefs are equal, their
strings will also be equal. The docs for FlakeRef.String go into more
detail on what the normalized form looks like.

Being able to parse/modify/encode flake references is part of the work
to support multiple package outputs. Having a single (well-tested type)
for handling flakes should help manage the complexity as another syntax
for outputs is added.
@gcurtis gcurtis requested review from mikeland73 and savil November 1, 2023 15:10
Copy link
Collaborator

@savil savil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome!

@@ -41,7 +41,7 @@ linters-settings:
- name: bool-literal-in-expr
- name: cognitive-complexity
arguments:
- 30 # TODO: gradually reduce it
- 32 # TODO: gradually reduce it
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol, that's the opposite direction to the TODO! (It's okay)

return url.String()
case "github":
if f.Owner == "" || f.Repo == "" {
return ""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be an error?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, but I want FlakeRef to be a fmt.Stringer so this function is unable to return an error.

@@ -260,6 +359,33 @@ func isArchive(path string) bool {
strings.HasSuffix(path, ".zip")
}

// buildOpaquePath escapes and joins path elements for a URL flakeref. The
// resulting path is cleaned according to url.JoinPath.
func buildOpaquePath(elem ...string) string {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Opaque word confused me. How about buildEscapedPath or buildURLSafePath?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. I'm going to rename it in another PR just so I don't have to rebase/merge all the other PRs.

@gcurtis gcurtis merged commit 22d11c3 into main Nov 1, 2023
@gcurtis gcurtis deleted the gcurtis/flakeref-string branch November 1, 2023 17:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants