Skip to content

Commit 1f405f6

Browse files
authored
Merge pull request #38 from microsoft/alzollin/fixNodeOutput
Fixed error output and node output.
2 parents 7cd0626 + ffa5779 commit 1f405f6

File tree

4 files changed

+46
-33
lines changed

4 files changed

+46
-33
lines changed

src/winsdk-CLI/Winsdk.Cli/Helpers/TextWriterLogger.cs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,33 @@ public void Log<TState>(LogLevel logLevel, EventId eventId, TState state,
6262
var writer = logLevel >= LogLevel.Error ? _stderr : _stdout;
6363

6464
var sb = new StringBuilder(256);
65-
if (logLevel != LogLevel.Information)
65+
66+
// Message
67+
var message = formatter(state, exception);
68+
69+
bool firstCharIsEmojiOrOpenBracket = false;
70+
if (message.Length > 0)
6671
{
67-
var lvl = logLevel.ToString().ToUpperInvariant();
72+
var firstChar = message[0];
73+
firstCharIsEmojiOrOpenBracket = char.IsSurrogate(firstChar)
74+
|| char.GetUnicodeCategory(firstChar) == System.Globalization.UnicodeCategory.OtherSymbol
75+
|| firstChar == '[';
76+
}
6877

69-
sb.Append('[').Append(lvl).Append("] - ");
78+
if (logLevel != LogLevel.Information && !firstCharIsEmojiOrOpenBracket)
79+
{
80+
if (logLevel == LogLevel.Debug)
81+
{
82+
sb.Append(UiSymbols.Verbose).Append(' ');
83+
}
84+
else
85+
{
86+
var lvl = logLevel.ToString().ToUpperInvariant();
87+
88+
sb.Append('[').Append(lvl).Append("] - ");
89+
}
7090
}
7191

72-
// Message
73-
var message = formatter(state, exception);
7492
sb.Append(message);
7593

7694
// Scopes (if any)

src/winsdk-CLI/Winsdk.Cli/Helpers/UiSymbols.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ private static bool Compute()
3232
public static string Wrench => UseEmoji ? "🔧" : "[TOOL]";
3333
public static string Package => UseEmoji ? "📦" : "[PKG]";
3434
public static string Bullet => UseEmoji ? "•" : "-";
35-
public static string Skip => UseEmoji ? "⏭" : "SKIP";
35+
public static string Skip => UseEmoji ? "⏭" : "[SKIP]";
3636
public static string Tools => UseEmoji ? "🛠️" : "[TOOL]";
3737
public static string Files => UseEmoji ? "📁" : "[COPY]";
3838
public static string Check => UseEmoji ? "✅" : "[OK]";
@@ -51,4 +51,5 @@ private static bool Compute()
5151
public static string User => UseEmoji ? "👤" : "[USER]";
5252
public static string Id => UseEmoji ? "🆔" : "[ID]";
5353
public static string Clipboard => UseEmoji ? "📋" : "[CLIP]";
54+
public static string Verbose => UseEmoji ? "🔍" : "[VERBOSE]";
5455
}

src/winsdk-CLI/Winsdk.Cli/Telemetry/Events/CommandInvokedEvent.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,15 @@ internal CommandInvokedEvent(CommandResult commandResult, DateTime startedTime)
3636
StartedTime = startedTime;
3737
}
3838

39-
private string? GetValue(OptionResult o) => GetValue(o.Option.ValueType, o.Implicit, o.GetValueOrDefault<object?>());
40-
private string? GetValue(ArgumentResult a) => GetValue(a.Argument.ValueType, a.Implicit, a.GetValueOrDefault<object?>());
39+
private string? GetValue(OptionResult o)
40+
{
41+
return !o.Errors.Any() ? GetValue(o.Option.ValueType, o.Implicit, o.GetValueOrDefault<object?>()) : "[error]";
42+
}
43+
44+
private string? GetValue(ArgumentResult a)
45+
{
46+
return !a.Errors.Any() ? GetValue(a.Argument.ValueType, a.Implicit, a.GetValueOrDefault<object?>()) : "[error]";
47+
}
4148

4249
private static string? GetValue(Type valueType, bool isImplicit, object? value)
4350
{

src/winsdk-npm/winsdk-cli-utils.js

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -33,42 +33,29 @@ async function callWinsdkCli(args, options = {}) {
3333
const winsdkCliPath = getWinsdkCliPath();
3434

3535
return new Promise((resolve, reject) => {
36-
let stdout = '';
3736
let stderr = '';
3837

3938
const child = spawn(winsdkCliPath, args, {
40-
stdio: verbose ? ['inherit', 'pipe', 'pipe'] : 'pipe',
39+
stdio: verbose ? 'inherit' : 'pipe',
4140
shell: false
4241
});
4342

44-
child.stdout.on('data', (data) => {
45-
const output = data.toString();
46-
stdout += output;
47-
if (verbose) {
48-
process.stdout.write(output);
49-
}
50-
});
51-
52-
child.stderr.on('data', (data) => {
53-
const output = data.toString();
54-
stderr += output;
55-
if (verbose) {
56-
process.stderr.write(output);
57-
}
58-
});
43+
// Only capture stderr when not using inherit mode (needed for error messages)
44+
if (!verbose) {
45+
child.stderr.on('data', (data) => {
46+
stderr += data.toString();
47+
});
48+
}
5949

6050
child.on('close', (code) => {
61-
const result = {
62-
exitCode: code,
63-
stdout: stdout.trim(),
64-
stderr: stderr.trim()
65-
};
66-
6751
if (code === 0) {
68-
resolve(result);
52+
resolve({ exitCode: code });
6953
} else {
7054
if (exitOnError) {
71-
console.error(`winsdk-cli failed: ${stderr}`);
55+
// Print stderr only if not verbose, as it would have been printed already
56+
if (!verbose) {
57+
console.error(`winsdk-cli failed: ${stderr}`);
58+
}
7259
process.exit(code);
7360
} else {
7461
reject(new Error(`winsdk-cli exited with code ${code}: ${stderr}`));

0 commit comments

Comments
 (0)