Skip to content
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

🐛 exit after showing help #468

Merged
merged 7 commits into from
Mar 4, 2024
Merged

Conversation

Vickysomtee
Copy link
Contributor

@Vickysomtee Vickysomtee commented Jan 18, 2024

Fixes #439

Signed-off-by: vickysomtee <[email protected]>
Copy link
Contributor

@pranavgaikwad pranavgaikwad left a comment

Choose a reason for hiding this comment

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

@Vickysomtee hey thank you for your fix. it should work! But I noticed that when we integrated cobra, we didn't do things quite the "cobra" way. Are you willing to help us refactor that code? The changes I am looking for are -

  1. main() function only calls cmd.Execute() The actual code that runs the analysis is removed from main()
  2. analysis code goes into command's RunE() funcion instead

Here's a good example of using different hooks in a cobra command: https://github.com/konveyor/kantra/blob/20af46fafa3876cd56f5b3be20610c7185673142/cmd/analyze.go#L85-L150

@pranavgaikwad pranavgaikwad changed the title fix: exit after showing help 🐛 exit after showing help Jan 19, 2024
@Vickysomtee
Copy link
Contributor Author

@Vickysomtee hey thank you for your fix. it should work! But I noticed that when we integrated cobra, we didn't do things quite the "cobra" way. Are you willing to help us refactor that code? The changes I am looking for are -

  1. main() function only calls cmd.Execute() The actual code that runs the analysis is removed from main()
  2. analysis code goes into command's RunE() funcion instead

Here's a good example of using different hooks in a cobra command: https://github.com/konveyor/kantra/blob/20af46fafa3876cd56f5b3be20610c7185673142/cmd/analyze.go#L85-L150

@pranavgaikwad Yes, I would love to refactor this. Few questions though

  1. Can I continue this refactor in this same PR?
  2. Can you help highlight the code that handles the analysis so I can go through it and understand it better.
  3. Are we writing tests for this? Additional context will be appreciated

@shawn-hurley
Copy link
Contributor

  1. Can I continue this refactor in this same PR?

Yeah absolutely

  1. Can you help highlight the code that handles the analysis so I can go through it and understand it better.

https://github.com/konveyor/analyzer-lsp/blob/main/cmd/analyzer/main.go#L201

This is where the engine runs the rules, but all the setup is also very important

https://github.com/konveyor/analyzer-lsp/blob/main/cmd/analyzer/main.go#L96-L199

The important parts here are rule parsing and getting and setting up the correct providers.

  1. Are we writing tests for this? Additional context will be appreciated.

No test will be needed for this refactor, our e2e tests will test this!

@Vickysomtee
Copy link
Contributor Author

@shawn-hurley Thank you!

@shawn-hurley
Copy link
Contributor

@Vickysomtee let me know if you want to get on a call to help get the demo testing working, and continue on this!

@Vickysomtee
Copy link
Contributor Author

@shawn-hurley

I think I might need help to get the demo test working but it's not currently the blocker for this PR. I had a little tight schedule but I am free now and I will continue on this. If I still need help on the demo test, I would let you know. Thank you!

@Vickysomtee
Copy link
Contributor Author

I have updated the PR with the refactor @pranavgaikwad @shawn-hurley

@pranavgaikwad
Copy link
Contributor

@Vickysomtee Thank you. Really appreciate you helping out. Is it ready for review?

@Vickysomtee
Copy link
Contributor Author

@Vickysomtee Thank you. Really appreciate you helping out. Is it ready for review?

@pranavgaikwad Yes it is

@Vickysomtee Vickysomtee marked this pull request as ready for review March 4, 2024 12:58
@pranavgaikwad pranavgaikwad self-requested a review March 4, 2024 13:03

func main() {
if err := AnalysisCmd().Execute(); err != nil {
println(err.Error())
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we use os.Exit(1) here?

rootCmd := &cobra.Command{
Use: "analyze",
Short: "Tool for working with analyzer-lsp",
PreRun: func(c *cobra.Command, args []string) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of exiting here, can we use PreRunE function and only return an error?

Copy link
Contributor

@pranavgaikwad pranavgaikwad left a comment

Choose a reason for hiding this comment

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

Requesting minor changes

@Vickysomtee
Copy link
Contributor Author

Vickysomtee commented Mar 4, 2024

Requesting minor changes

@pranavgaikwad I have made the changes

Copy link
Contributor

@pranavgaikwad pranavgaikwad left a comment

Choose a reason for hiding this comment

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

One small request

PreRunE: func(c *cobra.Command, args []string) error {
err := validateFlags()
if err != nil {
errLog.Error(err, "failed to validate flags")
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: can we return err here? and return nil after the if block? just making sure if we make changes in future, it doesn't go unnoticed that err could be non-nil after the if block

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

Copy link
Contributor

@pranavgaikwad pranavgaikwad left a comment

Choose a reason for hiding this comment

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

Thank you @Vickysomtee

Copy link
Contributor

@shawn-hurley shawn-hurley left a comment

Choose a reason for hiding this comment

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

Thank you for the refactor! this is looking really good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] "konveyor-analyzer-dep --help" keeps running instead of showing help and stopping
3 participants