Skip to content

Commit

Permalink
Improving #2 by using BaseDynamicCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
timheuer committed Dec 2, 2023
1 parent d22b127 commit 0b392fb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
31 changes: 25 additions & 6 deletions src/Commands/ManifestGen.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
using AspireManifestGen.Options;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;

namespace AspireManifestGen;

[Command(PackageIds.MyCommand)]
internal sealed class ManifestGen : BaseCommand<ManifestGen>
internal sealed class ManifestGen : BaseDynamicCommand<ManifestGen, Project>
{
protected override async Task ExecuteAsync(OleMenuCmdEventArgs e)
protected override void BeforeQueryStatus(OleMenuCommand menuItem, EventArgs e, Project item)
{
var project = await VS.Solutions.GetActiveProjectAsync();
menuItem.Supported = item.IsCapabilityMatch("Aspire");
}

protected override async Task ExecuteAsync(OleMenuCmdEventArgs e, Project project)
{
//var project = await VS.Solutions.GetActiveProjectAsync();
var projectPath = Path.GetDirectoryName(project.FullPath);

var options = await General.GetLiveInstanceAsync();
Expand Down Expand Up @@ -44,13 +51,25 @@ protected override async Task ExecuteAsync(OleMenuCmdEventArgs e)
// TODO: Need better error handling, issue #3
if (process.ExitCode != 0)
{
Debug.WriteLine($"Error: {process.ExitCode}");
return;
var errorString = await process.StandardError.ReadToEndAsync();
Debug.WriteLine($"Error: {errorString}");
goto Cleanup;
}

await VS.Documents.OpenAsync(manifestPath);

Cleanup:
await VS.StatusBar.EndAnimationAsync(StatusAnimation.Build);
await VS.StatusBar.ShowProgressAsync("Generating Aspire Manifest", 2, 2);
return;
}

await VS.Documents.OpenAsync(manifestPath);
protected override IReadOnlyList<Project> GetItems()
{
return ThreadHelper.JoinableTaskFactory.Run(async () =>
{
List<Project> items = [await VS.Solutions.GetActiveProjectAsync()];
return items;
});
}
}
1 change: 1 addition & 0 deletions src/VSCommandTable.vsct
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<Icon guid="ImageCatalogGuid" id="JSONScript" />
<CommandFlag>IconIsMoniker</CommandFlag>
<CommandFlag>DynamicVisibility</CommandFlag>
<CommandFlag>DefaultInvisible</CommandFlag>
<Strings>
<ButtonText>Generate .NET Aspire manifest</ButtonText>
<LocCanonicalName>.AspireManifestGen.MyCommand</LocCanonicalName>
Expand Down

0 comments on commit 0b392fb

Please sign in to comment.