Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions src/winsdk-CLI/Winsdk.Cli/Helpers/TextWriterLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,33 @@ public void Log<TState>(LogLevel logLevel, EventId eventId, TState state,
var writer = logLevel >= LogLevel.Error ? _stderr : _stdout;

var sb = new StringBuilder(256);
if (logLevel != LogLevel.Information)

// Message
var message = formatter(state, exception);

bool firstCharIsEmojiOrOpenBracket = false;
if (message.Length > 0)
{
var lvl = logLevel.ToString().ToUpperInvariant();
var firstChar = message[0];
firstCharIsEmojiOrOpenBracket = char.IsSurrogate(firstChar)
|| char.GetUnicodeCategory(firstChar) == System.Globalization.UnicodeCategory.OtherSymbol
|| firstChar == '[';
}

sb.Append('[').Append(lvl).Append("] - ");
if (logLevel != LogLevel.Information && !firstCharIsEmojiOrOpenBracket)
{
if (logLevel == LogLevel.Debug)
{
sb.Append(UiSymbols.Verbose).Append(' ');
}
else
{
var lvl = logLevel.ToString().ToUpperInvariant();

sb.Append('[').Append(lvl).Append("] - ");
}
}

// Message
var message = formatter(state, exception);
sb.Append(message);

// Scopes (if any)
Expand Down
3 changes: 2 additions & 1 deletion src/winsdk-CLI/Winsdk.Cli/Helpers/UiSymbols.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ private static bool Compute()
public static string Wrench => UseEmoji ? "🔧" : "[TOOL]";
public static string Package => UseEmoji ? "📦" : "[PKG]";
public static string Bullet => UseEmoji ? "•" : "-";
public static string Skip => UseEmoji ? "⏭" : "SKIP";
public static string Skip => UseEmoji ? "⏭" : "[SKIP]";
public static string Tools => UseEmoji ? "🛠️" : "[TOOL]";
public static string Files => UseEmoji ? "📁" : "[COPY]";
public static string Check => UseEmoji ? "✅" : "[OK]";
Expand All @@ -51,4 +51,5 @@ private static bool Compute()
public static string User => UseEmoji ? "👤" : "[USER]";
public static string Id => UseEmoji ? "🆔" : "[ID]";
public static string Clipboard => UseEmoji ? "📋" : "[CLIP]";
public static string Verbose => UseEmoji ? "🔍" : "[VERBOSE]";
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,15 @@ internal CommandInvokedEvent(CommandResult commandResult, DateTime startedTime)
StartedTime = startedTime;
}

private string? GetValue(OptionResult o) => GetValue(o.Option.ValueType, o.Implicit, o.GetValueOrDefault<object?>());
private string? GetValue(ArgumentResult a) => GetValue(a.Argument.ValueType, a.Implicit, a.GetValueOrDefault<object?>());
private string? GetValue(OptionResult o)
{
return !o.Errors.Any() ? GetValue(o.Option.ValueType, o.Implicit, o.GetValueOrDefault<object?>()) : "[error]";
}

private string? GetValue(ArgumentResult a)
{
return !a.Errors.Any() ? GetValue(a.Argument.ValueType, a.Implicit, a.GetValueOrDefault<object?>()) : "[error]";
}

private static string? GetValue(Type valueType, bool isImplicit, object? value)
{
Expand Down
37 changes: 12 additions & 25 deletions src/winsdk-npm/winsdk-cli-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,42 +33,29 @@ async function callWinsdkCli(args, options = {}) {
const winsdkCliPath = getWinsdkCliPath();

return new Promise((resolve, reject) => {
let stdout = '';
let stderr = '';

const child = spawn(winsdkCliPath, args, {
stdio: verbose ? ['inherit', 'pipe', 'pipe'] : 'pipe',
stdio: verbose ? 'inherit' : 'pipe',
shell: false
});

child.stdout.on('data', (data) => {
const output = data.toString();
stdout += output;
if (verbose) {
process.stdout.write(output);
}
});

child.stderr.on('data', (data) => {
const output = data.toString();
stderr += output;
if (verbose) {
process.stderr.write(output);
}
});
// Only capture stderr when not using inherit mode (needed for error messages)
if (!verbose) {
child.stderr.on('data', (data) => {
stderr += data.toString();
});
}

child.on('close', (code) => {
const result = {
exitCode: code,
stdout: stdout.trim(),
stderr: stderr.trim()
};

if (code === 0) {
resolve(result);
resolve({ exitCode: code });
} else {
if (exitOnError) {
console.error(`winsdk-cli failed: ${stderr}`);
// Print stderr only if not verbose, as it would have been printed already
if (!verbose) {
console.error(`winsdk-cli failed: ${stderr}`);
}
process.exit(code);
} else {
reject(new Error(`winsdk-cli exited with code ${code}: ${stderr}`));
Expand Down