rich-click icon indicating copy to clipboard operation
rich-click copied to clipboard

WIP Add configuration option to use STDERR for output

Open alexanderilyin opened this issue 1 year ago • 6 comments

@ewels is adding config.stderr property similar to other settings is the right way to implement this?

alexanderilyin avatar Dec 05 '24 05:12 alexanderilyin

Thanks for this @alexanderilyin!

There's already been some discussion around printing to stderr, see #164. If I understand @dwreeves correctly, Click usually prints to stdout for help messages and stderr for error messages. Rich-click aims to emulate this behaviour.

That said, I'd be happy to make this behaviour configurable as long as the default matches Click. So in other words, add a config option as you suggest and make it opt-in.

Does that sound ok?

ewels avatar Dec 05 '24 06:12 ewels

@ewels sound like a plan. Yep I love that rich-click is Plug & Play but for my CLI app I want all human readable things go to STDERR for now, and STDOUT is reserved for programmatic interactions, in other words I don't want JSON in STDOUT be broken due to any other output, and I do need to control exit codes. Note to self: I can grab STDERR as is and internally merge it with JSON from STDOUT on "client" side.

Thanks in advance, I'll put PR sometime this week, cause I don't want to have a fork and all overhead related to it.

alexanderilyin avatar Dec 05 '24 07:12 alexanderilyin

Yup, the use case sounds valid. Should be simple enough to convert what you have here to something in the config scope, false as default and then you'd just need one line of config in your app to use it.

ewels avatar Dec 05 '24 17:12 ewels

@ewels one more opt-in feature I want to add is help for arguments. Wonder if any work was happening in that direction. I looked quickly around but seems that there is no support for that yet.

P. S. Currently I can put arguments description in command's doc block, but given show_arguments=True, feature it seems that it should be right to allow set help=... for arguments as well.

alexanderilyin avatar Dec 06 '24 01:12 alexanderilyin

Yes I've wondered about that in the past. Again it moves us further from the original click syntax so needs some care, but it may well be worth it. Please create an issue for that so we can track it and discuss that there.

ewels avatar Dec 06 '24 04:12 ewels

Help for arguments is something I'm thinking about for 1.9. I'm personally open to it. If you'd like to take it on then that works.

dwreeves avatar Dec 07 '24 03:12 dwreeves

Hi @alexanderilyin,

Via #255, help_to_stderr can now be set like this:

@click.command(context_settings={"help_to_stderr": True})
def cli() -> None:
    """CLI help text"""

After many internal refactors, it just doesn't really work to have it in help config settings.

Also, @click.argument() now accepts a help= kwarg.

This will all be available in 1.9.0, which should be out in a few weeks, let's say first week of September.

dwreeves avatar Aug 16 '25 03:08 dwreeves