-
Notifications
You must be signed in to change notification settings - Fork 76
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
Validating CLI arguments #531
Comments
To solve this issue, we need to focus on the arguments part on the
In this way, we prevents unrecognized arguments from being treated as positional arguments and to handle the error we got. |
checkout the existing tests: https://github.com/ploomber/jupysql/blob/master/src/tests/test_magic.py the solution is a bit tricky though (this project is a fork of ipython-sql so we inherited a bunch of legacy code). I forgot to put this relevant link: https://jupysql.ploomber.io/en/latest/intro.html#considerations so for the line magic ( line magic:
cell magic:
|
So we need to deal this problem by line magic and cell magic separately. One way is to write function immediately after
Since in the cell magic, SQL code needs to be at the second line, so we can parse the first line and to check whether we get unrecognized arguments, if we we get unrecognized arguments, we raise UsageError. |
yeah, this makes sense: splitting into two. the root problem is that both the line and cell lines are executing the same function. but the validation logic assumptions are different (see #550) so go ahead with the approach you suggested and we'll see how it goes! |
Sure! I have submitted a PR request. Some tests failed, I am blocked by these tests. Do you have any suggestion for these error? |
i have some ideas now, i will try to fix that |
are you able to run the tests locally? that'll make things easier to debug this will be useful: https://ploomber.io/blog/open-source/ - checkout the |
I am confused with SQL comments and unrecognized arguments. Is that all the arguments should begin with "--" and I notice that "If you try to pass an unsupported argument, like --lutefisk, it will be interpreted as a SQL comment and will not throw an unsupported argument exception" |
we cannot do this in the line magic ( but we can do it in the cell magic ( |
Sure, that makes sense. I have submitted a new pull request. I added a new test, and all the tests pass locally in my computer. |
I noticed that passing random arguments to
%sql
doesn't raise any errors:We should throw an UsageError instead
The text was updated successfully, but these errors were encountered: