-
Notifications
You must be signed in to change notification settings - Fork 5
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
print parameter value if and only if provided via CLI arg or config #464
Conversation
69083a5
to
db130fc
Compare
This comment was marked as outdated.
This comment was marked as outdated.
5e00d24
to
3f1931c
Compare
@@ -0,0 +1,14 @@ | |||
namespace D2L.Bmx; | |||
|
|||
internal record ParameterSource { |
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.
use a record type rather than an enum so it's:
- easy to customize
ToString()
- easy to extend in the future to supply config file path
@@ -0,0 +1,17 @@ | |||
namespace D2L.Bmx; | |||
|
|||
internal interface IConsoleWriter { |
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.
We're reasonably close to a point where some unit tests around our prompting and printing logic would be worthwhile.
I could really use a few when I was writing up #463
Interfaces are handy then.
if( !string.IsNullOrEmpty( account ) && !nonInteractive ) { | ||
consoleWriter.WriteParameter( ParameterDescriptions.Account, account, accountSource ); |
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.
seems reasonable to not print these out when user has explicitly specified --non-interactive
?
Console.ForegroundColor = ConsoleColor.Cyan; | ||
Console.Error.Write( value ); | ||
Console.ForegroundColor = ConsoleColor.DarkGray; | ||
Console.Error.WriteLine( $" (from {source})" ); |
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.
alternatively:
Console.Error.WriteLine( $" (from {source})" ); | |
Console.Error.WriteLine( $" (source: {source})" ); |
🤷
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.
My vote is from
@@ -21,24 +22,32 @@ BmxConfig config | |||
bool nonInteractive, | |||
bool ignoreCache | |||
) { | |||
var orgSource = ParameterSource.CliArg; | |||
if( string.IsNullOrEmpty( org ) && !string.IsNullOrEmpty( config.Org ) ) { |
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.
aside: writing all this overwrite/print/prompt logic really has a fizz buzz feel - it feels like you should be able to consolidate some actions and/or logical branches, but actually you can't...
Why
Follow up to #463
As per Zoom discussion, BMX will always print parameter value & source if and only if it's provided via CLI args or config file.
I also made it colourful for legibility. The line seems too long and crowded without these colours.
![image](https://private-user-images.githubusercontent.com/8552945/351118767-27461fa6-2b9a-48a1-946e-5db92d244235.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkxMTY1NzQsIm5iZiI6MTczOTExNjI3NCwicGF0aCI6Ii84NTUyOTQ1LzM1MTExODc2Ny0yNzQ2MWZhNi0yYjlhLTQ4YTEtOTQ2ZS01ZGI5MmQyNDQyMzUucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIwOSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMDlUMTU1MTE0WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9ZDcxYjg0NGRkOWZlMjI3YjFiNjUwYzc4YzYwNzllODBiZDcwZTZhY2I5ZWJlZmUwYjY1YWFmYmFhNDlkYTUxZCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.PJxvKxNHQ37hzxiM1eQ2pW4o3y0bUITR9WPuno_OA34)
The colours don't work if stdout is redirected, which is typical when using
bmx print
. I know why this is happening. Will try to fix in a separate PR.Ticket
https://desire2learn.atlassian.net/browse/VUL-423