-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat: add basic ignore directive, allowing the user to tell anchor to ignore certain packages #38
Conversation
… ignore certain packages
t.Errorf("Expected no error but got %v", err) | ||
} | ||
if image != "golang:1.22-bookworm" { | ||
t.Errorf("Expected golang:1.22-bookworm but got %v", image) |
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.
Wouldn't this be a %s
, since image
is a sting?
t.Errorf("Expected golang:1.22-bookworm but got %v", image) | |
t.Errorf("Expected golang:1.22-bookworm but got %s", image) |
nodes := Parse(input) | ||
image, err := processFromCommand(&nodes[0]) | ||
if err != nil { | ||
t.Errorf("Expected no error but got %v", err) |
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.
t.Errorf("Expected no error but got %v", err) | |
t.Errorf("Expected no error but got %w", err) |
@@ -82,12 +94,55 @@ func processRunCommand(ctx context.Context, node *Node, architecture string, ima | |||
return nil | |||
} | |||
|
|||
func parseComment(entry Entry) ([]string, bool) { |
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.
Got GPT-4o to "refactor" this and what it claims (I don't know about readability compared to what you have though)—I'll leave it up to you:
Changes Made:
1. Replaced strings.TrimLeft with strings.TrimSpace and strings.TrimPrefix for clarity and correctness.
2. Used strings.Fields to split the command into parts more cleanly.
3. Simplified the condition checks to enhance readability.
4. Removed redundant TrimSpace calls in certain places where they were unnecessary.
func parseComment(entry Entry) ([]string, bool) {
ignoredPackages := []string{}
if entry.Type != EntryComment {
return ignoredPackages, false
}
command := strings.TrimSpace(strings.TrimPrefix(entry.Value, "#"))
parts := strings.Fields(command)
if len(parts) < 2 || parts[0] != "anchor" {
return ignoredPackages, false
}
keyValue := strings.SplitN(parts[1], "=", 2)
if len(keyValue) < 2 {
if strings.TrimSpace(keyValue[0]) == "ignore" {
return ignoredPackages, true
}
return ignoredPackages, false
}
if keyValue[0] != "ignore" {
return ignoredPackages, false
}
for _, pkg := range strings.Split(keyValue[1], ",") {
ignoredPackages = append(ignoredPackages, strings.TrimSpace(pkg))
}
return ignoredPackages, false
}
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.
Turns out this was just wrong lol but thanks chatgpt
First pass is just adding it for the apt packages, will do the docker images next and playing around with how it feels.