Skip to content
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

Merged
merged 2 commits into from
Jul 24, 2024

Conversation

cfbao
Copy link
Member

@cfbao cfbao commented Jul 22, 2024

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

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

@github-actions github-actions bot added language/csharp size/M A medium-sized PR. labels Jul 22, 2024
@cfbao cfbao force-pushed the always-print-params branch 2 times, most recently from 69083a5 to db130fc Compare July 22, 2024 21:31

This comment was marked as outdated.

@cfbao cfbao changed the title print parameter value when provided via CLI arg or config print parameter value if and only if provided via CLI arg or config Jul 22, 2024
@cfbao cfbao force-pushed the always-print-params branch from 5e00d24 to 3f1931c Compare July 22, 2024 21:39
@@ -0,0 +1,14 @@
namespace D2L.Bmx;

internal record ParameterSource {
Copy link
Member Author

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 {
Copy link
Member Author

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.

Comment on lines +39 to +40
if( !string.IsNullOrEmpty( account ) && !nonInteractive ) {
consoleWriter.WriteParameter( ParameterDescriptions.Account, account, accountSource );
Copy link
Member Author

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})" );
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alternatively:

Suggested change
Console.Error.WriteLine( $" (from {source})" );
Console.Error.WriteLine( $" (source: {source})" );

🤷

Copy link
Contributor

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 ) ) {
Copy link
Member Author

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...

@cfbao cfbao marked this pull request as ready for review July 23, 2024 14:31
@cfbao cfbao requested a review from a team as a code owner July 23, 2024 14:31
@cfbao cfbao merged commit 351876b into main Jul 24, 2024
9 checks passed
@cfbao cfbao deleted the always-print-params branch July 24, 2024 13:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
language/csharp size/M A medium-sized PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants