radon-project / radon

The Radon Programming Language
https://radon-project.github.io
GNU General Public License v3.0
23 stars 2 forks source link

Implement a primitive version of the `Argparse` module #131

Closed angelcaru closed 5 months ago

Almas-Ali commented 5 months ago

Is it usable now?

angelcaru commented 5 months ago

Yes, check the example (examples/args_test.rn)

Almas-Ali commented 5 months ago

I can't use it like this examples/args_test.rn --version.

angelcaru commented 5 months ago

That's because the argument list is hardcoded in the example. Change it to sys_args() (or some slice of that that skips the initial Python program args)

angelcaru commented 5 months ago

Oh, wait. The interpreter tries to recognize the arguments passed to the program as its own (and fails). So we can't pass command-line arguments to Radon programs yet.

Almas-Ali commented 5 months ago

Yeah, Python is detecting those arguments and parsing with it's internal Argparse module which is used in radon.py.

angelcaru commented 5 months ago

That means we probably need to stop using it ourselves. The CLI isn't that complex so we should be able to rewrite it without argparse

Almas-Ali commented 5 months ago

Yeah, you can try that.

Almas-Ali commented 5 months ago

Can you implement a basic CLI program for demo with all features included which is implemented till now.

angelcaru commented 5 months ago

ok

angelcaru commented 5 months ago

I made it

Almas-Ali commented 5 months ago

--help it not working

Almas-Ali commented 5 months ago

--max-lines issue

angelcaru commented 5 months ago

Elaborate

Almas-Ali commented 5 months ago

I think we need to handle them from Argparse module side.

angelcaru commented 5 months ago

Yeah but what is the issue?

Almas-Ali commented 5 months ago

Elaborate

Oops, it was my mistake with passing line limit.

Almas-Ali commented 5 months ago

But without a value it is crashing...

Almas-Ali commented 5 months ago

Wrong file name is crashing.

angelcaru commented 5 months ago

I know. This is just a PoC of the Argparse, no need to fix that

Almas-Ali commented 5 months ago

Then we need to move all those crash issue to main module, so any user can use it without any issues.

angelcaru commented 5 months ago

What are you talking about?

angelcaru commented 5 months ago

It's just an example, there's no intent for it to be used as an actual alternative to grep

Almas-Ali commented 5 months ago

It's just an example, there's no intent for it to be used as an actual alternative to grep

Cool down. I am asking to merge crashing issue which we are handling manually in to Argparse. So, it can handle those things it self.

angelcaru commented 5 months ago

What crashing issue? You only mentioned it crashing on non-existent files, which is not a concern of Argparse

Almas-Ali commented 5 months ago

I am not asking that. If no value is passed, it will send warning by it self. Also the argv will be called from inside of Argparse, we just need to call parser.parse(). This will be more abstract.

angelcaru commented 5 months ago

OK, that makes sense now