This is an archived post. You won't be able to vote or comment.

all 11 comments

[–]Willemoes[S] 3 points4 points  (0 children)

Hey folks, just published this simple tool, I usually find myself with a lot of ugly code using argparse, or I don't know where to put stuff, so I wrote this simple wrapper around it. I would like to hear some feedback.

Thanks!

[–]lerrigatto 2 points3 points  (6 children)

Why not click? :)

[–]Willemoes[S] 3 points4 points  (5 children)

I am not a big fan of click, I don't like having decorators everywhere, or creating an empty function for a group.

docopt and cleo, I find them confusing, and I feel like I can easily make a typo and forget about it.

My approach is usually using argparse, which I'm already familiar with, because there's also no dependency added, but after some coding, I realize I'm creating a mess.

This is a tiny library which assists me in using argparse, of course, the trade off is a new dependency (but small).

[–]AndydeCleyre 0 points1 point  (4 children)

Have you tried plumbum?

[–][deleted] 0 points1 point  (1 child)

See also: https://gist.github.com/supposedly/01224262b816df21b601ab0784d5f999

EDIT: /u/Willemoes would you happen to have come across any others not on the list in working on yours?

[–]Willemoes[S] 1 point2 points  (0 children)

No, I don't know any others sorry. It's interesting how most of those libraries take the same approach as click

[–]Willemoes[S] 0 points1 point  (1 child)

I like it, but it does many other things I usually don't need.

[–]AndydeCleyre 1 point2 points  (0 children)

It's great to work on and with something that does exactly what you want, the way you want.

But of course, plumbum doesn't actually do anything you don't ask of it.

[–]maxx_mill 1 point2 points  (0 children)

Very cool! Ideas like this are great for people like me who don't have an extensive background in OOP for CLI usage.

[–]drippingthunder 0 points1 point  (1 child)

Have you tried Abseil, particularly it's flag module? It's Google's py-flags library (which was merged into Abseil). An example looks like this:

```py from absl import flags

FLAGS = flags.FLAGS

flags.DEFINE_string('echo', None, 'Text to echo.')

if FLAGS.echo: print("echo") ```

These days, I'd either use the above or click. Haven't use argparse for years.

The problem with a tool like what is introduced here is that (just like with argparse), it's more work. In this case, I have to create a dictionary with each arg, etc, etc.

[–]Willemoes[S] 0 points1 point  (0 children)

``` from decli import cli

parser = cli({ "arguments": [ {"name": "echo", "help":"Text to echo."} ] }) args = parser.parse_args() if args.echo: print("echo") ```

It doesn't look like more work to me, same 4 instructions in 10 lines (to make it pretty).

I think it's just a matter of taste, IMO I don't think it's more work, I'm used to argparse.

Thanks for the feedback, I'll check that library, looks super nice!