joshuawprice / user-scripts

A collection of useful scripts I've created over time.
MIT License
0 stars 0 forks source link

Improve parser consuming #6

Open joshuawprice opened 2 years ago

joshuawprice commented 2 years ago

At the moment the parser leaves a lot to be desired with regards to consuming arguments, a few examples of which are:

As for implementing this I believe some of the nargs parameters will need to be removed from the add_arguments calls and the current actions to be modified. This idea came from this note in the argparse documentation:

If the nargs keyword argument is not provided, the number of arguments consumed is determined by the action. Generally this means a single command-line argument will be consumed and a single item (not a list) will be produced.

The above way is much better than the original way I thought, but I shall paste some bullet points below of my original notes in case the above fails:

  • Use append/extend action on files argument
  • Also have to make sure the argument to the uploader is not completely consumed, therefore would have to remove the automatic type conversions for the uploaders
  • Then append/create files attr I also thought of removing the nargs option from the files add_argument call and saving all the files to a separate location if possible.
    • Maybe - If argument ends in / then assume it is not a file and consume

I also think SingleAppendAction's name should be changed to something like UniqueAppendAction or UploadAction. And lastly I think I should improve the init method in SingleAppendConstAction by using **kwargs (see argparse documentation action and Action classes

joshuawprice commented 2 months ago

Also, check length is an option for determining if it as an API (they are 64 chars long). Also maybe parsing it as base 16 or something.

joshuawprice commented 2 months ago

So it turns out optionally consuming arguments is not possible with argparse (at least not without using internal apis). Instead, how about spitting out files from the init function in asgard/catgirls types?

If this doesn't work then I'll leave it alone as I don't think exactly what I want is possible.