Skip to content

Commit

Permalink
Adds --short option to outdated command (microsoft#664)
Browse files Browse the repository at this point in the history
  • Loading branch information
garrytrinder authored Apr 19, 2024
1 parent b65ac23 commit dfa1584
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
27 changes: 24 additions & 3 deletions dev-proxy/OutdatedCommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,33 @@ namespace Microsoft.DevProxy;

public static class OutdatedCommandHandler
{
public static async Task CheckVersion(ILogger logger)
public static async Task CheckVersion(bool versionOnly, ILogger logger)
{
var releaseInfo = await UpdateNotification.CheckForNewVersion(ProxyCommandHandler.Configuration.NewVersionNotification);
if (releaseInfo != null)

if (releaseInfo is not null && releaseInfo.Version is not null)
{
var isBeta = releaseInfo.Version.Contains("-beta");

if (versionOnly)
{
logger.LogInformation(releaseInfo.Version);
}
else
{
var notesLink = isBeta ? "https://aka.ms/devproxy/notes" : "https://aka.ms/devproxy/beta/notes";
logger.LogInformation(
"New Dev Proxy version {version} is available.{newLine}Release notes: {link}{newLine}Docs: https://aka.ms/devproxy/upgrade",
releaseInfo.Version,
Environment.NewLine,
notesLink,
Environment.NewLine
);
}
}
else if (!versionOnly)
{
logger.LogInformation(releaseInfo.Version);
logger.LogInformation("You are using the latest version of Dev Proxy.");
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions dev-proxy/ProxyHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,10 @@ public RootCommand GetRootCommand(IProxyLogger logger)
command.Add(presetCommand);

var outdatedCommand = new Command("outdated", "Check for new version");

outdatedCommand.SetHandler(async () => await OutdatedCommandHandler.CheckVersion(logger));
var outdatedShortOption = new Option<bool>("--short", "Return version only");
outdatedCommand.AddOption(outdatedShortOption);
outdatedCommand.SetHandler(async versionOnly => await OutdatedCommandHandler.CheckVersion(versionOnly, logger), outdatedShortOption);

command.Add(outdatedCommand);

return command;
Expand Down

0 comments on commit dfa1584

Please sign in to comment.