-
-
Notifications
You must be signed in to change notification settings - Fork 72
β¨ Add Support for Environment Flags NO_COLOR and FORCE_COLOR
#33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
thx for the PR @aspiers - could you clarify why this change would be necessary for the vast majority of users? I'm generally hesitant to introduce new CLI options unless they provide clear benefits for 99% of users. Even optional features add complexity and require users to consider their implications. Given that this is mission-critical software, I want to avoid feature creep and keep the CLI as streamlined as possible. |
|
Also, I refuse to call this |
|
@pcaversaccio commented on Apr 2, 2025, 3:06 PM GMT+1:
I'm a Brit, so @pcaversaccio commented on Apr 2, 2025, 2:58 PM GMT+1:
Sure. The most obvious use case is piping the output through a pager and/or other filter. For example, I find it extremely useful to filter through the rolod0x CLI, so that human-readable labels are attached to addresses as an extra layer of security. Clearly you already appreciate that colour is an extremely effective way of improving the usability of UIs, otherwise you wouldn't have gone to the effort of supporting colour in the first place. And it's no less useful with the above use cases than any other use case. So I think it doesn't make sense to exclude the benefits of colour from these use cases. BTW I did a quick scan of the man pages on my system and found over 50 CLI programs which support this approach: aha bison rpm-misc csh fluxbox cfdisk fdisk sfdisk diff grep cargo cc c++ gcc git g++ rustc dir ls vdir cal dmesg hexdump parallel tcsh node21 msgconv msgcomm msgcat msgattrib xgettext msguniq msgunfmt msgmerge msginit msggrep msgfilter msgen valac-0.56 valac rg fd bat quilt shellcheck brz pw-config pw
I understand where you're coming from, but the benefits of colour are already well established as per above, and it hardly makes any difference to the complexity of the code. After splitting out the refactoring into a separate commit, the new functionality is only 4 extra lines of actual logic, and 12 extra lines for parsing the new option, all of which are extremely simple and cleanly separated from the rest of the logic. |
--color option for greater control of output formatting--colour option for greater control of output formatting
There is English and American English π!
The use case for this script is to run it on a dedicated device running a secure operating system. Piping, filtering etc. create additional friction points and thus attack vectors that can be manipulated. For simple piping, you can do something like here (convert the output into a simple Also, adding this feature would be a bit more complicated, as I manually colour things (mostly warnings) later in the script, e.g. safe-tx-hashes-util/safe_hashes.sh Lines 380 to 396 in 88e2916
safe-tx-hashes-util/safe_hashes.sh Lines 636 to 645 in 88e2916
safe-tx-hashes-util/safe_hashes.sh Lines 918 to 926 in 88e2916
The primary reason I didn't properly refactor this yet is that it doesn't matter for the use case of this script.
Well, as I explained above, it would require more refactoring for all colourings used. Also, I follow the YAGNI principle for such mission-critical software, so every line of code must be justified for the use case, and it doesn't matter if it's a best practice in other tools. |
|
Firstly, thanks a lot for the continued replies. I do appreciate it. Hopefully you will also gain something useful from this conversation, even if it's not a merged PR π
Indeed!
That's clearly a very valid use case, and I appreciate it's the one you've documented, but it's definitely not my use case, for carefully considered reasons explained below. And if I were a betting man I would put money on there being others who run it on normal operating systems on multi-purpose machines for similar reasons. If this alarms you, it shouldn't! The famous essay "The Cathedral and the Bazaar" states:
The best practices you document in the README are of course excellent advice for higher stakes scenarios, and arguably essential when there is (say) >$1m at risk. But best practices by definition are guidelines not universally applicable rules. Everyone has different security requirements and should be free to choose where they want to sit on the security/convenience trade-off spectrum for any given scenario. For example, only verifying Safe transactions from a dedicated machine could easily be considered overkill if there's less than $1k of funds at risk in an organization which regularly deals with amounts in excess of $10m. (The threshold could of course be higher or lower depending on the size of the organization and many other factors.) Or similarly if the cost of an attack is many orders of magnitude higher than the value to the attacker. Many Safe transactions don't even involve any funds at all. And catering for different security requirements is of course why Safe allows the owner to choose the signing threshold.
Sure, but I trust the script I'm piping it through at least as much as all the other attack surfaces involved, because I wrote that code myself. And anyway, the extra security guarantees offered to me by rolod0x easily outweigh the risks of it being compromised. Or if I piped it through (BTW, a tangential point here is that one of the trust assumptions required by the script is that the local Foundry install is not compromised. Unfortunately, Foundry's officially documented installation procedure is The more general point here is the script cannot possibly know the security context in which it is run, let alone the relevant merits and risks of any other program to which its output may be piped. Therefore it does not make sense for the script to assume any of that context.
Unfortunately that doesn't help me at all, because outputting in JSON (or any other format) is of no use to me.
Hopefully it's clear from the above now? For carefully considered reasons, my security requirements are less stringent than yours in many circumstances. And in those cases I simply want the output of the script to be as human-readable as possible so that I can process a large number of low criticality transactions without undue brain fatigue, which means I need coloured output where addresses are automatically labelled by rolod0x.
Ah yes, good point. Well I could easily address those, if you're willing to reconsider your position here.
Sure, that refactoring definitely wasn't needed until I came along with my use case.
Please consider who the "You" refers to in this principle. Just because you don't need it, it doesn't mean that other users of the script don't need it. I'm one such user saying that I do need it (otherwise I wouldn't have bothered with this PR). And as per esr's quote from the CatB essay above, if your users' needs are evolving beyond your expectations, that means you're doing something right π |
|
Thanks for the insights - while I have to think about my position here, I wanted to ask you what you think about using NO_COLOR=1 ./safe_hashes.sh --network arbitrum --address 0x111CEEee040739fD91D29C34C33E6B3E112F2177 --nonce 234would disable colour by default in the output. I really don't want to overload the CLI options and I already implement an environment variable |
|
I would be totally fine with a solution which uses an environment variable rather than a new CLI option. I only suggested the CLI option because I did consider mentioning That said, while it's perhaps slightly controversial to violate the spec, personally I think it would be a reasonable compromise to write code which treats |
|
Hmm - what about we use |
|
Sure, sounds fine to me! |
This option adheres to the conventions used by several other commands: - https://force-color.org/ - https://no-color.org/ Signed-off-by: Adam Spiers <blockchain@adamspiers.org>
|
New version pushed. |
Signed-off-by: Pascal Marco Caversaccio <pascal.caversaccio@hotmail.ch>
--colour option for greater control of output formattingNO_COLOR and FORCE_COLOR
Signed-off-by: Pascal Marco Caversaccio <pascal.caversaccio@hotmail.ch>
aspiers
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great to me! The replacement of all those tput commands also greatly increases the legibility of the source.
Agreed, it's unclear which should take precedence, but I highly doubt it matters - and if it did then it would be trivial to fix anyway.
I think the current approach is the most sound one. It's like having both a mute button and a volume slider:
|
Signed-off-by: Pascal Marco Caversaccio <pascal.caversaccio@hotmail.ch>
pcaversaccio
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok tested it extensively - works as expected; thx for the PR and the insightful discussion π!
|
Awesome! π Thanks a lot for your time on this! π |
π Changelog
This PR adds support for the environment flags
NO_COLORandFORCE_COLORto control the colour output. Specifically, the colour output is auto-detected and can be controlled with:NO_COLOR=trueβ disables all colours,FORCE_COLOR=trueβ forces colour output.Only the exact value
trueis accepted to avoid accidental activation.If both are set,
NO_COLORtakes precedence and disables all formatting. Otherwise, colour is enabled only if output is to a terminal,tputis available, and the terminal supports at least the 8 standard ANSI colours.