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

Argument handling improvement #2

Merged
merged 3 commits into from
Jul 29, 2024
Merged

Conversation

jonblau
Copy link
Contributor

@jonblau jonblau commented Jul 18, 2024

I first thought I'd post an issue, but since it was pretty simple, I solved it myself.

Despite a long list of conditions, not all cases were previously handled correctly. For example, if the command was just edcre -s 15 without the track bin file, it was interpreting 15 as the track name and complained it couldn't be found.

The "rules" are these:

  • the track should be the last argument
  • -v, -t, or -k should not be the last argument
  • -s should be followed by a minimum of two arguments, not just one
  • there may be up to seven arguments, not just six

So I tried to make to code more efficient and removed some code duplication. Error messages like the one for -s may also be added later for -v, -t, -k.

One downside though: you can not use tracks that are also named -v, -t, or -k...

@alex-free
Copy link
Owner

If we want to be really fancy, we can still allow for tracks named '-v', '-t', or '-k' it's not impossible. The way to do it would be to first seeing if fopen is successful in opening a file named as such, and on failure (silently, no need to tell the user we are trying to open a file named '-v') to then treat it as an improper usage of the argument.

Thanks for the contribution, I definitely forgot that 7 args is now possible with -k being included.

@jonblau
Copy link
Contributor Author

jonblau commented Jul 21, 2024

Ok, I have created a small function with your idea, which now allows to use files that are also named -v -t -k or -s and identify syntax errors at the same time. I think we're good.

@alex-free alex-free merged commit 1d9c498 into alex-free:master Jul 29, 2024
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.

2 participants