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

Allow multiple targets on command line #160

Merged
merged 4 commits into from
Nov 21, 2024
Merged

Conversation

n-oden
Copy link
Contributor

@n-oden n-oden commented Jul 5, 2024

This addresses #96

  • iterate over the list of remaining arguments treating each as an origin path

  • defer printing deprecation warnings until after all paths are processed

  • print deprecation warnings to stderr, not stdout

@n-oden
Copy link
Contributor Author

n-oden commented Nov 20, 2024

@incu6us I've updated this against current upstream/master and fixed the conflict

Copy link

codecov bot commented Nov 20, 2024

Codecov Report

Attention: Patch coverage is 0% with 99 lines in your changes missing coverage. Please review.

Project coverage is 57.00%. Comparing base (da1c44e) to head (add3bec).
Report is 5 commits behind head on master.

Files with missing lines Patch % Lines
main.go 0.00% 99 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #160      +/-   ##
==========================================
+ Coverage   55.34%   57.00%   +1.66%     
==========================================
  Files          11       11              
  Lines        1104     1177      +73     
==========================================
+ Hits          611      671      +60     
- Misses        470      482      +12     
- Partials       23       24       +1     
Flag Coverage Δ
unittests 57.00% <0.00%> (+1.66%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

@n-oden
Copy link
Contributor Author

n-oden commented Nov 20, 2024

Is the codecov test advisory, or are you asking for test coverage going forward? There's no current test set for main.go, but I suppose we could make one...

main.go Outdated Show resolved Hide resolved
main.go Outdated
Comment on lines 295 to 300
printUsage()
os.Exit(1)

Choose a reason for hiding this comment

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

You are looping on argument to validate them.

Maybe you could report an error for each argument

Then after the loop printusage and exit, when at least an error is found

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, given that validateRequiredParam is currently only checking to see if stdin exists in the cast of originPaths[0] being - I think this entire loop can be removed and the call to validateRequiredParam moved up into the previous block. @incu6us I'm going to make this change but let me know what you think?

Copy link
Owner

Choose a reason for hiding this comment

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

@n-oden yep, agree

@incu6us
Copy link
Owner

incu6us commented Nov 21, 2024

@incu6us I've updated this against current upstream/master and fixed the conflict

@n-oden could you update it once again?

This addresses incu6us#96

- iterate over the list of remaining arguments treating
  each as an origin path

- fully remove support for the -filePath option

- defer printing deprecation warnings until after all paths
  are processed

- print deprecation warnings to stderr, not stdout
@n-oden
Copy link
Contributor Author

n-oden commented Nov 21, 2024

@incu6us @ccoVeille addressed the comments, rebased on current upstream/master, and while I was at it spotted another issue: the call to helper.DetermineProjectName needed to be moved inside the loop over originPaths since different paths might have different project names.

@ccoVeille
Copy link

Great. Let's waif for @incu6us feedbacks then

Copy link

@ccoVeille ccoVeille left a comment

Choose a reason for hiding this comment

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

Some minor remarks, open to debate

main.go Outdated
Comment on lines 297 to 302
if err := validateRequiredParam(originPaths[0]); err != nil {
log.Printf("%s\n\n", err)
printUsage()
os.Exit(1)
}
}

Choose a reason for hiding this comment

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

Shouldn't be this?

Suggested change
if err := validateRequiredParam(originPaths[0]); err != nil {
log.Printf("%s\n\n", err)
printUsage()
os.Exit(1)
}
}
}
if err := validateRequiredParam(originPaths[0]); err != nil {
log.Printf("%s\n\n", err)
printUsage()
os.Exit(1)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I'm possibly misunderstanding something here. validateRequiredParam() will always return nil if the passed argument is anything other than reviser.StandardInput:

func validateRequiredParam(filePath string) error {
	if filePath == reviser.StandardInput {
		stat, _ := os.Stdin.Stat()
		if stat.Mode()&os.ModeNamedPipe == 0 {
			// no data on stdin
			return errors.New("no data on stdin")
		}
	}
	return nil
}

So I think there's no point in calling it unless we know that we're operating on stdin, which would only happen if we find ourselves on the inside of if len(originPaths) == 0 || (len(originPaths) == 1 && originPaths[0] == "-") {

main.go Outdated Show resolved Hide resolved
@incu6us
Copy link
Owner

incu6us commented Nov 21, 2024

thanks @n-oden for your help. I have no any additional comments. agree with @ccoVeille about his comments to make some things more readable and simpler.

if err != nil {
log.Fatalf("%s", err)
}
os.Exit(0)

Choose a reason for hiding this comment

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

Suggested change
os.Exit(0)
os.Exit(1)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that was intentional -- if the error is non-nil, we'll exit with a non-zero exitval via log.Fatalf. If the error is nil, we print usage and exit successfully.

This may admittedly be overthinking it. :)

Copy link

@ccoVeille ccoVeille Nov 21, 2024

Choose a reason for hiding this comment

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

Wow, indeed. Clever

A comment would be appreciated, saying ur will exit with exit 1

@incu6us incu6us merged commit 40541f0 into incu6us:master Nov 21, 2024
9 checks passed
@n-oden n-oden deleted the multiple-argv branch November 21, 2024 21:26
@n-oden
Copy link
Contributor Author

n-oden commented Nov 21, 2024

Thanks to all of you for getting my PRs merged and released!

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.

3 participants