-
-
Notifications
You must be signed in to change notification settings - Fork 489
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding a nativeAot version of the demo application. While I was in here I fixed a few bugs in the original Demo though.
- Loading branch information
1 parent
24a6cb6
commit c1624e9
Showing
17 changed files
with
387 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using System.ComponentModel; | ||
using DemoAot.Utilities; | ||
using Spectre.Console.Cli; | ||
|
||
namespace DemoAot.Commands.Add; | ||
|
||
[Description("Add a NuGet package reference to the project.")] | ||
public sealed class AddPackageCommand : Command<AddPackageCommand.Settings> | ||
{ | ||
public sealed class Settings : AddSettings | ||
{ | ||
[CommandArgument(0, "<PACKAGENAME>")] | ||
[Description("The package reference to add.")] | ||
public string PackageName { get; set; } | ||
|
||
[CommandOption("-v|--version <VERSION>")] | ||
[Description("The version of the package to add.")] | ||
public string Version { get; set; } | ||
|
||
[CommandOption("-f|--framework <FRAMEWORK>")] | ||
[Description("Add the reference only when targeting a specific framework.")] | ||
public string Framework { get; set; } | ||
|
||
[CommandOption("--no-restore")] | ||
[Description("Add the reference without performing restore preview and compatibility check.")] | ||
public bool NoRestore { get; set; } | ||
|
||
[CommandOption("--source <SOURCE>")] | ||
[Description("The NuGet package source to use during the restore.")] | ||
public string Source { get; set; } | ||
|
||
[CommandOption("--package-directory <PACKAGEDIR>")] | ||
[Description("The directory to restore packages to.")] | ||
public string PackageDirectory { get; set; } | ||
|
||
[CommandOption("--interactive")] | ||
[Description("Allows the command to stop and wait for user input or action (for example to complete authentication).")] | ||
public bool Interactive { get; set; } | ||
} | ||
|
||
public override int Execute(CommandContext context, Settings settings) | ||
{ | ||
SettingsDumper.Dump(settings); | ||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System.ComponentModel; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.IO; | ||
using DemoAot.Utilities; | ||
using Spectre.Console; | ||
using Spectre.Console.Cli; | ||
|
||
namespace DemoAot.Commands.Add; | ||
|
||
public sealed class AddReferenceCommand : Command<AddReferenceCommand.Settings> | ||
{ | ||
public sealed class Settings : AddSettings | ||
{ | ||
[CommandArgument(0, "<PROJECTPATH>")] | ||
[Description("The package reference to add.")] | ||
public DirectoryInfo ProjectPath { get; set; } | ||
|
||
[CommandOption("-f|--framework <FRAMEWORK>")] | ||
[Description("Add the reference only when targeting a specific framework.")] | ||
public string Framework { get; set; } | ||
|
||
[CommandOption("--interactive")] | ||
[Description("Allows the command to stop and wait for user input or action (for example to complete authentication).")] | ||
public bool Interactive { get; set; } | ||
} | ||
|
||
// In non-AOT scenarios, we can dynamically call the constructor to DirectoryInfo via reflection. | ||
// With trimming enabled we need to be explicit about requiring that constructor. | ||
[DynamicDependency(DynamicallyAccessedMemberTypes.PublicConstructors, typeof(DirectoryInfo))] | ||
public override int Execute(CommandContext context, Settings settings) | ||
{ | ||
SettingsDumper.Dump(settings); | ||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System.ComponentModel; | ||
using Spectre.Console.Cli; | ||
|
||
namespace DemoAot.Commands.Add; | ||
|
||
public abstract class AddSettings : CommandSettings | ||
{ | ||
[CommandArgument(0, "<PROJECT>")] | ||
[Description("The project file to operate on. If a file is not specified, the command will search the current directory for one.")] | ||
public string Project { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
using System.ComponentModel; | ||
using DemoAot.Utilities; | ||
using Spectre.Console.Cli; | ||
|
||
namespace DemoAot.Commands.Run; | ||
|
||
[Description("Build and run a .NET project output.")] | ||
public sealed class RunCommand : Command<RunCommand.Settings> | ||
{ | ||
public sealed class Settings : CommandSettings | ||
{ | ||
[CommandOption("-c|--configuration <CONFIGURATION>")] | ||
[Description("The configuration to run for. The default for most projects is '[grey]Debug[/]'.")] | ||
[DefaultValue("Debug")] | ||
public string Configuration { get; set; } | ||
|
||
[CommandOption("-f|--framework <FRAMEWORK>")] | ||
[Description("The target framework to run for. The target framework must also be specified in the project file.")] | ||
public string Framework { get; set; } | ||
|
||
[CommandOption("-r|--runtime <RUNTIMEIDENTIFIER>")] | ||
[Description("The target runtime to run for.")] | ||
public string RuntimeIdentifier { get; set; } | ||
|
||
[CommandOption("-p|--project <PROJECTPATH>")] | ||
[Description("The path to the project file to run (defaults to the current directory if there is only one project).")] | ||
public string ProjectPath { get; set; } | ||
|
||
[CommandOption("--launch-profile <LAUNCHPROFILE>")] | ||
[Description("The name of the launch profile (if any) to use when launching the application.")] | ||
public string LaunchProfile { get; set; } | ||
|
||
[CommandOption("--no-launch-profile")] | ||
[Description("Do not attempt to use [grey]launchSettings.json[/] to configure the application.")] | ||
public bool NoLaunchProfile { get; set; } | ||
|
||
[CommandOption("--no-build")] | ||
[Description("Do not build the project before running. Implies [grey]--no-restore[/].")] | ||
public bool NoBuild { get; set; } | ||
|
||
[CommandOption("--interactive")] | ||
[Description("Allows the command to stop and wait for user input or action (for example to complete authentication).")] | ||
public string Interactive { get; set; } | ||
|
||
[CommandOption("--no-restore")] | ||
[Description("Do not restore the project before building.")] | ||
public bool NoRestore { get; set; } | ||
|
||
[CommandOption("--verbosity <VERBOSITY>")] | ||
[Description("Set the MSBuild verbosity level. Allowed values are q[grey]uiet[/], m[grey]inimal[/], n[grey]ormal[/], d[grey]etailed[/], and diag[grey]nostic[/].")] | ||
[TypeConverter(typeof(VerbosityConverter))] | ||
[DefaultValue(Verbosity.Normal)] | ||
public Verbosity Verbosity { get; set; } | ||
|
||
[CommandOption("--no-dependencies")] | ||
[Description("Do not restore project-to-project references and only restore the specified project.")] | ||
public bool NoDependencies { get; set; } | ||
|
||
[CommandOption("--force")] | ||
[Description("Force all dependencies to be resolved even if the last restore was successful. This is equivalent to deleting [grey]project.assets.json[/].")] | ||
public bool Force { get; set; } | ||
} | ||
|
||
public override int Execute(CommandContext context, Settings settings) | ||
{ | ||
SettingsDumper.Dump(settings); | ||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System; | ||
using System.ComponentModel; | ||
using DemoAot.Utilities; | ||
using Spectre.Console; | ||
using Spectre.Console.Cli; | ||
|
||
namespace DemoAot.Commands.Serve; | ||
|
||
[Description("Launches a web server in the current working directory and serves all files in it.")] | ||
public sealed class ServeCommand : Command<ServeCommand.Settings> | ||
{ | ||
public sealed class Settings : CommandSettings | ||
{ | ||
[CommandOption("-p|--port <PORT>")] | ||
[DefaultValue(8080)] | ||
[Description("Port to use. Defaults to [grey]8080[/]. Use [grey]0[/] for a dynamic port.")] | ||
public int Port { get; set; } | ||
|
||
[CommandOption("-o|--open-browser [BROWSER]")] | ||
[Description("Open a web browser when the server starts. You can also specify which browser to use. If none is specified, the default one will be used.")] | ||
public FlagValue<string> OpenBrowser { get; set; } | ||
} | ||
|
||
public override int Execute(CommandContext context, Settings settings) | ||
{ | ||
if (settings.OpenBrowser.IsSet) | ||
{ | ||
var browser = settings.OpenBrowser.Value; | ||
if (browser != null) | ||
{ | ||
AnsiConsole.WriteLine($"Open in {browser}"); | ||
} | ||
else | ||
{ | ||
AnsiConsole.WriteLine($"Open in default browser."); | ||
} | ||
} | ||
|
||
SettingsDumper.Dump(settings); | ||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<IsPackable>false</IsPackable> | ||
<ExampleName>DemoAot</ExampleName> | ||
<ExampleDescription>Demonstrates the most common use cases of Spectre.Cli, configured for NativeAOT.</ExampleDescription> | ||
<ExampleGroup>Cli</ExampleGroup> | ||
<ExampleVisible>false</ExampleVisible> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<PublishAot>true</PublishAot> | ||
<TrimmerSingleWarn>false</TrimmerSingleWarn> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\..\..\src\Spectre.Console.Cli\Spectre.Console.Cli.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Oops, something went wrong.