Skip to content

Commit f282a80

Browse files
authored
Added a banner when a user calls just winapp (#187)
<img width="1734" height="1308" alt="image" src="https://github.com/user-attachments/assets/11e41a90-e541-43ad-8da3-3f32b4f1639e" /> --------- Co-authored-by: Nikola Metulev <[email protected]>
1 parent a3bb78c commit f282a80

File tree

3 files changed

+127
-8
lines changed

3 files changed

+127
-8
lines changed

src/winapp-CLI/WinApp.Cli/Commands/WinAppRootCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public WinAppRootCommand(
2727
GetWinappPathCommand getWinappPathCommand,
2828
CertCommand certCommand,
2929
SignCommand signCommand,
30-
ToolCommand toolCommand) : base("Windows App Development CLI tool")
30+
ToolCommand toolCommand) : base("Setup Windows SDK and Windows App SDK for use in your app, create MSIX packages, generate manifests and certificates, and use build tools.")
3131
{
3232
Subcommands.Add(initCommand);
3333
Subcommands.Add(restoreCommand);
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using System.Reflection;
5+
6+
namespace WinApp.Cli.Helpers;
7+
8+
/// <summary>
9+
/// Provides banner display functionality for the CLI.
10+
/// ASCII art is pre-computed for optimal startup performance.
11+
/// </summary>
12+
internal static class BannerHelper
13+
{
14+
// Stylized "winapp" text in block letters
15+
private static readonly string[] TitleBlockArt =
16+
{
17+
@"▄▄ ▀▀ ",
18+
@" ▀█▄ ██ ██ ██ ████▄ ▀▀█▄ ████▄ ████▄ ",
19+
@" ▄█▀ ██ █ ██ ██ ██ ██ ▄█▀██ ██ ██ ██ ██ ",
20+
@"▄█▀ ██▀██ ██▄ ██ ██ ▀█▄██ ████▀ ████▀ ",
21+
@" ██ ██ ",
22+
@" ▀▀ ▀▀ ",
23+
};
24+
25+
// Simple ASCII fallback for the title
26+
private static readonly string[] TitleAsciiArt =
27+
{
28+
@" _ ",
29+
@" __ _(_)_ __ __ _ _ __ _ __ ",
30+
@" \ \ /\ / / | '_ \ / _` | '_ \| '_ \ ",
31+
@" \ V V /| | | | | (_| | |_) | |_) | ",
32+
@" \_/\_/ |_|_| |_|\__,_| .__/| .__/ ",
33+
@" |_| |_| ",
34+
};
35+
36+
// ANSI color codes for gradient effect (Blue -> Purple, Windows-themed)
37+
private static readonly string[] GradientColors =
38+
{
39+
"\x1b[38;5;39m", // Bright Blue
40+
"\x1b[38;5;33m", // Blue
41+
"\x1b[38;5;63m", // Blue-Purple
42+
"\x1b[38;5;99m", // Purple
43+
"\x1b[38;5;135m", // Light Purple
44+
"\x1b[38;5;141m", // Lavender
45+
};
46+
47+
private const string ResetColor = "\x1b[0m";
48+
49+
/// <summary>
50+
/// Displays the CLI banner with version information.
51+
/// </summary>
52+
public static void DisplayBanner()
53+
{
54+
var useColor = UiSymbols.UseEmoji; // Same check - modern terminals support both
55+
var version = GetVersionString();
56+
57+
Console.WriteLine();
58+
59+
if (useColor)
60+
{
61+
DisplayColorBanner(version);
62+
}
63+
else
64+
{
65+
DisplayPlainBanner(version);
66+
}
67+
68+
Console.WriteLine();
69+
}
70+
71+
private static void DisplayColorBanner(string version)
72+
{
73+
var titleLines = TitleBlockArt;
74+
75+
// Display each line with a gradient color
76+
for (int i = 0; i < titleLines.Length; i++)
77+
{
78+
var color = GradientColors[i % GradientColors.Length];
79+
Console.WriteLine($" {color}{titleLines[i]}{ResetColor}");
80+
}
81+
82+
Console.WriteLine();
83+
Console.WriteLine($" \x1b[90mWindows App Development CLI · Version {version}{ResetColor}");
84+
}
85+
86+
private static void DisplayPlainBanner(string version)
87+
{
88+
foreach (var line in TitleAsciiArt)
89+
{
90+
Console.WriteLine($" {line}");
91+
}
92+
93+
Console.WriteLine();
94+
Console.WriteLine($" Windows App Development CLI - Version {version}");
95+
}
96+
97+
/// <summary>
98+
/// Gets the version string from the assembly.
99+
/// </summary>
100+
private static string GetVersionString()
101+
{
102+
var assembly = Assembly.GetExecutingAssembly();
103+
104+
// Try to get informational version first (includes git info if available)
105+
var infoVersion = assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion;
106+
if (!string.IsNullOrEmpty(infoVersion))
107+
{
108+
// Remove git hash suffix if present (e.g., "0.1.8+abc123" -> "0.1.8")
109+
var plusIndex = infoVersion.IndexOf('+');
110+
return plusIndex >= 0 ? infoVersion[..plusIndex] : infoVersion;
111+
}
112+
113+
// Fall back to assembly version
114+
var version = assembly.GetName().Version;
115+
return version != null ? $"{version.Major}.{version.Minor}.{version.Build}" : "0.0.0";
116+
}
117+
}

src/winapp-CLI/WinApp.Cli/Program.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,15 @@ static async Task<int> Main(string[] args)
6666

6767
var rootCommand = serviceProvider.GetRequiredService<WinAppRootCommand>();
6868

69+
// If no arguments provided, display banner and show help
70+
if (args.Length == 0)
71+
{
72+
BannerHelper.DisplayBanner();
73+
// Show help by invoking with --help
74+
await rootCommand.Parse(["--help"]).InvokeAsync();
75+
return 0;
76+
}
77+
6978
var parseResult = rootCommand.Parse(args);
7079

7180
try
@@ -76,13 +85,6 @@ static async Task<int> Main(string[] args)
7685

7786
CommandCompletedEvent.Log(parseResult.CommandResult, returnCode);
7887

79-
if (args.Length == 0)
80-
{
81-
// Temporary special case: If no arguments are provided, return 0 to indicate success.
82-
// This is because winget's validation currently doesn't like us returning failure here.
83-
returnCode = 0;
84-
}
85-
8688
return returnCode;
8789
}
8890
catch (Exception ex)

0 commit comments

Comments
 (0)