-
Notifications
You must be signed in to change notification settings - Fork 249
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
Conversation
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.
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.
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 |
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.
lol, that's the opposite direction to the TODO! (It's okay)
return url.String() | ||
case "github": | ||
if f.Owner == "" || f.Repo == "" { | ||
return "" |
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 this be an error?
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.
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 { |
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.
The Opaque word confused me. How about buildEscapedPath
or buildURLSafePath
?
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.
Sounds good. I'm going to rename it in another PR just so I don't have to rebase/merge all the other PRs.
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.