sharkdp / pastel

A command-line tool to generate, analyze, convert and manipulate colors
Apache License 2.0
5.08k stars 102 forks source link

Default value does not work #93

Closed in-in closed 5 years ago

in-in commented 5 years ago

Help says (pastel help format) that the type parameter has a default value of hex. But if I run format subcommand and omit the type option, it causes an error:

pastel format teal
error: 'teal' isn't a valid value for '<type>'

This command works without explicitly typing the type parameter

pastel color teal | pastel format
#008080
pastel --version  
pastel 0.5.3
sharkdp commented 5 years ago

This really only works if you completely omit the arguments, as in the pastel color teal | pastel format example.

The help text also shows the USAGE section:

    pastel format <type> [color]...

which implies that <type> is a required argument if you want to specify the optional [color]... arguments as well.

I think it is understandable that pastel format teal does not work. I think it would also be a bad design if this would work, as there could be name clashes between the formatting type and color names.

in-in commented 5 years ago

Thanks for the explanation If I understand correctly, then angle brackets <type> mean - required and square brackets - [color] optional

In the same time command pastel help sort-by shows:

USAGE:
    pastel sort-by [OPTIONS] [sort-order] [color]...

But this code doesn't work without the [sort-order] argument

pastel sort-by teal plum   
error: 'teal' isn't a valid value for '<sort-order>'
sharkdp commented 5 years ago

If I understand correctly, then angle brackets <type> mean - required and square brackets - [color] optional

yes.

In the same time command pastel help sort-by shows:

USAGE:
    pastel sort-by [OPTIONS] [sort-order] [color]...

That's unfortunate. I think I'll take your advise and change the help text for pastel format to also show pastel format [type] [color], because type is optional in some sense... it can be omitted because there is a default argument for it.

pastel sort-by teal plum   
error: 'teal' isn't a valid value for '<sort-order>'

Even if an argument is optional, you can never omit it if you want to specify arguments after them. I don't think this something that we do differently than most other command line programs. I can see how this takes some getting used to, but I don't really want pastel sort-by teal plum to work, simply because pastel sort-by hue plum is valid.

sharkdp commented 5 years ago

Actually, I think it's better to change sort-by to show

pastel sort-by [OPTIONS] <sort-order> [color]...

That seems more natural to me. The sort order is required, but there is a default sort order.

sharkdp commented 5 years ago

Should be fixed in bc0ec98f1e32798f9eb0654956bab081cd6fdb74

in-in commented 5 years ago

For me, too. And again, thank you for your time and for explaining the concept of angle/ square brackets.