These are chat archives for kbknapp/clap-rs

Mar 2019
Mar 28 00:06
My app's core logic will make use of coloured output, if the terminal supports it, but it will disable coloured output if a '--no-color' flag (or the NO_COLOR environment variable) is set. This works fine, but it would be nice to have Clap obey this flag as well. I realize that I can 1) build clap without the 'color' feature or 2) disable colour in clap by using clap::AppSettings, but I'm wondering if there is a solution by which I can ask clap to obey one of the flags it parses? I realize this seems like a chicken-and-egg problem, but perhaps it is possible to update clap's AppSettings after clap finishes parsing arguments, but before it renders any output which might involve colour? (Please note: So far my workaround ideas for this would be either a) to disable colour for clap itself in all cases (because if it unable to react to the presence of a colour-disabling command line argument, then it shouldn't use any colours at all) or b) to pre-scan the command line args using a different non-clap mechanism solely for this particular argument before setting up the main clap object to actually parse all the arguments properly (this workaround seems like overkill, compared to [a], but it would as least give me the most correct behaviour. Thanks!