-
Notifications
You must be signed in to change notification settings - Fork 587
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
refactor command package to remove globals and add dependency injection #965
Conversation
Signed-off-by: Christopher Phillips <christopher.phillips@anchore.com>
Signed-off-by: Christopher Phillips <christopher.phillips@anchore.com>
Benchmark Test ResultsBenchmark results from the latest changes vs base branch
|
Signed-off-by: Christopher Phillips <christopher.phillips@anchore.com>
Signed-off-by: Christopher Phillips <christopher.phillips@anchore.com>
Signed-off-by: Christopher Phillips <christopher.phillips@anchore.com>
be445dc
to
b730abc
Compare
Signed-off-by: Christopher Phillips <christopher.phillips@anchore.com>
6120204
to
e191e02
Compare
@@ -147,7 +147,7 @@ lint-fix: ## Auto-format all source code + run golangci lint fixers | |||
|
|||
.PHONY: check-licenses | |||
check-licenses: ## Ensure transitive dependencies are compliant with the current license policy | |||
$(TEMPDIR)/bouncer check | |||
$(TEMPDIR)/bouncer check ./cmd/syft |
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.
@wagoodman if I provide the path to the main package does the bouncer check things at the top level like internal
or syft
?
e191e02
to
f3c36ed
Compare
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.
Self Review Comments
Signed-off-by: Christopher Phillips <christopher.phillips@anchore.com>
f3c36ed
to
dbc17ed
Compare
Signed-off-by: Christopher Phillips <christopher.phillips@anchore.com>
Signed-off-by: Christopher Phillips <christopher.phillips@anchore.com>
Signed-off-by: Christopher Phillips <christopher.phillips@anchore.com>
test/cli/power_user_cmd_test.go
Outdated
assertFailingReturnCode, | ||
}, | ||
}, | ||
//{ |
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.
Because poweruser is being decorated with the packages flags output is now a valid option.
TODO: update the writer
function so poweruser can do multiple formats. This test becomes invalid.
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.
I want to make sure I follow what's happening here... I know we plan to remove the power-user
command in the future. And IMHO it's not so bad if we support -o json
for the command in the meantime (curious for your thoughts on this!).
Should we remove this test case if we don't plan to use it either now or later?
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.
Good callout here as I did not circle back on this comment. The solution here is to just make -o json the ONLY valid format for power-user. We can then remove this test.
It's currently hard coded here:
Lines 76 to 81 in c270ee2
writer, err := sbom.NewWriter( | |
sbom.NewWriterOption( | |
syftjson.Format(), | |
appConfig.File, | |
), | |
) |
Signed-off-by: Christopher Phillips <christopher.phillips@anchore.com>
Signed-off-by: Christopher Phillips <christopher.phillips@anchore.com>
Signed-off-by: Christopher Phillips <christopher.phillips@anchore.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.
This is fantastic @spiffcs — what an upgrade for the code... 🚀
Approving this! ✅
It looks like there's still some follow-up needed here. I asked a couple of questions, and I saw there were a few existing questions/nits that aren't answered yet. But nothing that's left seems like a big lift at this point.
I also have two overall questions re: this PR:
-
Since
main.go
has been moved to another package, this breaks installation for users that build from source usinggo install github.com/anchore/syft@latest
. We don't list this installation method in our README documentation, so no change is needed here. But it is a nice feature of Go 1.16+, and I've used it several times. Could we do a cursory check of uses of this installation method just so we have a heads up on potential broken workflows? (My guess is we're not using this internally.) -
I see some PR comments that have "TODO", and the comments are resolved, and the code hasn't changed. I want to make sure I parse that correctly. Does that mean that no code change is needed at this point? Such as it was just a thing to look into, but you've done that outside of the code?
Signed-off-by: Christopher Phillips <christopher.phillips@anchore.com>
There are some I reconciled outside the code and realized they were not as big of a deal as when I made the comment. I think I responded to each conversation you commented on so we can follow up on those threads. TLDR: you're right and thanks for pointing those out. I think they got resolved accidentally as I was going through some of my previous self review. I also checked and we do not use the command you listed for install. When this merges I think we can update that to be
|
Signed-off-by: Christopher Phillips <christopher.phillips@anchore.com>
Summary
This PR attempts to update the command package so that Syft moves away from global package variables and instead is architected around command constructors with functional options.
Changes
cmd
separated intocli
withcommands.go
organizing cli construction. Individual commands have constructors along with new packages named as command name.EX:
import github.com/anchore/syft/cmd/syft/cli/attest
includesattest.Run
as the execution path.options
built to describe options that can be decorated onto built commandseventloop
given its own packageconfig.Application
structTODO:
Signed-off-by: Christopher Phillips christopher.phillips@anchore.com