-
Notifications
You must be signed in to change notification settings - Fork 0
chore: add projects for CLI introspection #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Flash0ver
wants to merge
13
commits into
main
Choose a base branch
from
chore/code-cli-introspection
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
5f8dc40
chore: add projects for CLI introspection
Flash0ver cfd6ced
chore: add C# sample app
Flash0ver d23e192
chore: add Visual Basic sample app
Flash0ver ecb05d3
chore: add F# sample app
Flash0ver c29c2cd
style: align format of sample apps
Flash0ver 649f0dc
style: change names of local constants from camelCase to PascalCase
Flash0ver 58373ea
chore: add repo alias to repository command
Flash0ver bb84ee1
feat: emit trimming and AOT-compatibility metadata
Flash0ver 0087109
style: remove BOM from UTF-8 encoding
Flash0ver c11e284
build: explicit IsPackable property
Flash0ver cb3d9c6
chore: update packages
Flash0ver e1e804a
chore: rename packable projects
Flash0ver 3045e39
chore: move root namespace
Flash0ver File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,4 @@ | ||
| is_global = true | ||
|
|
||
| # CA2007: Consider calling ConfigureAwait on the awaited task | ||
| dotnet_diagnostic.CA2007.severity = none |
This file contains hidden or 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,16 @@ | ||
| <Project> | ||
|
|
||
| <Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" | ||
| Condition="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../')) != ''" /> | ||
|
|
||
| <PropertyGroup> | ||
| <IsPackable>false</IsPackable> | ||
| </PropertyGroup> | ||
|
|
||
| <PropertyGroup> | ||
| <PublishTrimmed>true</PublishTrimmed> | ||
| <PublishAot>true</PublishAot> | ||
| <InvariantGlobalization>true</InvariantGlobalization> | ||
| </PropertyGroup> | ||
|
|
||
| </Project> |
25 changes: 25 additions & 0 deletions
25
...amples/FlashOWare.CommandLine.Example.CSharp/FlashOWare.CommandLine.Example.CSharp.csproj
This file contains hidden or 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,25 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>net10.0</TargetFramework> | ||
| <AssemblyName>FlashOWare.CommandLine.Example.CSharp</AssemblyName> | ||
| <RootNamespace>FlashOWare.CommandLine.Example</RootNamespace> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Octokit" /> | ||
| <PackageReference Include="System.CommandLine" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\..\lib\FlashOWare.CommandLine.CliSchema\FlashOWare.CommandLine.CliSchema.csproj" /> | ||
| <ProjectReference Include="..\..\lib\FlashOWare.CommandLine.OpenCli\FlashOWare.CommandLine.OpenCli.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <TrimmerRootAssembly Include="FlashOWare.CommandLine.CliSchema" /> | ||
| <TrimmerRootAssembly Include="FlashOWare.CommandLine.OpenCli" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
111 changes: 111 additions & 0 deletions
111
source/examples/FlashOWare.CommandLine.Example.CSharp/Program.cs
This file contains hidden or 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,111 @@ | ||
| using System.CommandLine; | ||
| using System.CommandLine.Invocation; | ||
| using System.CommandLine.Parsing; | ||
| using System.Reflection; | ||
| using Octokit; | ||
|
|
||
| RootCommand rootCommand = new("C# sample app."); | ||
|
|
||
| Option<bool> option = new("--language", ["-l", "--lang"]) | ||
| { | ||
| Description = "Display the .NET language in use.", | ||
| Arity = ArgumentArity.Zero, | ||
| Action = new LanguageCommandLineAction(), | ||
| }; | ||
| rootCommand.Options.Add(option); | ||
|
|
||
| Command command = new("repository", "Display GitHub repository information."); | ||
| command.Aliases.Add("repo"); | ||
| Argument<string> argument = new("FULL-NAME") | ||
| { | ||
| Description = """The full name of the repository in the form of "owner/repo".""", | ||
| Arity = ArgumentArity.ZeroOrOne, | ||
| DefaultValueFactory = static string (ArgumentResult argumentResult) => "FlashOWare/command-line-interfaces", | ||
| }; | ||
| argument.Validators.Add(void (ArgumentResult argumentResult) => | ||
| { | ||
| string value = argumentResult.GetRequiredValue(argument); | ||
|
|
||
| int index = value.IndexOf('/'); | ||
| if (index == -1 || index != value.LastIndexOf('/') || index == 0 || index + 1 == value.Length) | ||
| { | ||
| argumentResult.AddError("""The full name of the repository must be in the form of "owner/repo"."""); | ||
| } | ||
| }); | ||
| command.Arguments.Add(argument); | ||
| command.SetAction(async Task<int> (ParseResult parseResult, CancellationToken cancellationToken) => | ||
| { | ||
| string fullName = parseResult.GetRequiredValue(argument); | ||
| int index = fullName.IndexOf('/'); | ||
| string owner = fullName[..index]; | ||
| string repo = fullName[(index + 1)..]; | ||
|
|
||
| AssemblyName name = typeof(Program).Assembly.GetName(); | ||
| GitHubClient client = new(new ProductHeaderValue(name.Name, name.Version?.ToString())); | ||
| Repository repository = await client.Repository.Get(owner, repo); | ||
| RateLimit rateLimit = client.GetLastApiInfo().RateLimit; | ||
|
|
||
| const string TabString = " "; | ||
| TextWriter output = parseResult.InvocationConfiguration.Output; | ||
|
|
||
| await output.WriteLineAsync($""" | ||
| Repository | ||
| {TabString}Full Name: {repository.FullName} | ||
| {TabString}Stargazers: {repository.StargazersCount} | ||
| {TabString}Watchers: {repository.SubscribersCount} | ||
| {TabString}Forks: {repository.ForksCount} | ||
| {TabString}Open Issues: {repository.OpenIssuesCount} | ||
| """); | ||
| await output.WriteLineAsync($""" | ||
| Rate Limiting | ||
| {TabString}Requests per hour: {rateLimit.Limit - rateLimit.Remaining} / {rateLimit.Limit} | ||
| {TabString}Window resets at: {rateLimit.Reset.LocalDateTime:yyyy-MM-dd HH:mm:ss.fffffff} | ||
| """); | ||
|
|
||
| return 0; | ||
| }); | ||
| rootCommand.Subcommands.Add(command); | ||
|
|
||
| Directive directive = new("config") | ||
| { | ||
| Description = "Show the command-line configuration that would have been used if the given command line were run.", | ||
| Action = new ConfigCommandLineAction(), | ||
| }; | ||
| rootCommand.Directives.Add(directive); | ||
|
|
||
| ParseResult parseResult = rootCommand.Parse(args); | ||
| return await parseResult.InvokeAsync(); | ||
|
|
||
| internal sealed class LanguageCommandLineAction : SynchronousCommandLineAction | ||
| { | ||
| public override int Invoke(ParseResult parseResult) | ||
| { | ||
| TextWriter output = parseResult.InvocationConfiguration.Output; | ||
| output.WriteLine("C#"); | ||
| return 0; | ||
| } | ||
| } | ||
|
|
||
| internal sealed class ConfigCommandLineAction : SynchronousCommandLineAction | ||
| { | ||
| public override int Invoke(ParseResult parseResult) | ||
| { | ||
| const string TabString = " "; | ||
| TextWriter output = parseResult.InvocationConfiguration.Output; | ||
|
|
||
| output.WriteLine($""" | ||
| Configuration | ||
| {TabString}EnablePosixBundling: {parseResult.Configuration.EnablePosixBundling} | ||
| """); | ||
|
|
||
| output.WriteLine($""" | ||
| Invocation | ||
| {TabString}EnableDefaultExceptionHandler: {parseResult.InvocationConfiguration.EnableDefaultExceptionHandler} | ||
| {TabString}ProcessTerminationTimeout: {(parseResult.InvocationConfiguration.ProcessTerminationTimeout is { } timeout ? timeout.ToString("c") : "<null>")} | ||
| {TabString}Output: {parseResult.InvocationConfiguration.Output} | ||
| {TabString}Error: {parseResult.InvocationConfiguration.Error} | ||
| """); | ||
|
|
||
| return 0; | ||
| } | ||
| } |
3 changes: 3 additions & 0 deletions
3
source/examples/FlashOWare.CommandLine.Example.CSharp/Properties/AssemblyInfo.cs
This file contains hidden or 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,3 @@ | ||
| using System.Reflection; | ||
|
|
||
| [assembly: AssemblyCopyright("Copyright © FlashOWare 2026")] |
30 changes: 30 additions & 0 deletions
30
...amples/FlashOWare.CommandLine.Example.FSharp/FlashOWare.CommandLine.Example.FSharp.fsproj
This file contains hidden or 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,30 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>net10.0</TargetFramework> | ||
| <AssemblyName>FlashOWare.CommandLine.Example.FSharp</AssemblyName> | ||
| <RootNamespace>FlashOWare.CommandLine.Example</RootNamespace> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Compile Include="Program.fs" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="FSharp.Core" /> | ||
| <PackageReference Include="Octokit" /> | ||
| <PackageReference Include="System.CommandLine" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\..\lib\FlashOWare.CommandLine.CliSchema\FlashOWare.CommandLine.CliSchema.csproj" /> | ||
| <ProjectReference Include="..\..\lib\FlashOWare.CommandLine.OpenCli\FlashOWare.CommandLine.OpenCli.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <TrimmerRootAssembly Include="FlashOWare.CommandLine.CliSchema" /> | ||
| <TrimmerRootAssembly Include="FlashOWare.CommandLine.OpenCli" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
99 changes: 99 additions & 0 deletions
99
source/examples/FlashOWare.CommandLine.Example.FSharp/Program.fs
This file contains hidden or 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,99 @@ | ||
| open System | ||
| open System.CommandLine | ||
| open System.CommandLine.Invocation | ||
| open System.CommandLine.Parsing | ||
| open System.Reflection | ||
| open System.Threading | ||
| open System.Threading.Tasks | ||
| open Octokit | ||
|
|
||
| [<Sealed>] | ||
| type private LanguageCommandLineAction() = | ||
| inherit SynchronousCommandLineAction() | ||
|
|
||
| override this.Invoke(parseResult: ParseResult) : int = | ||
| let output = parseResult.InvocationConfiguration.Output | ||
| output.WriteLine("F#") | ||
| 0 | ||
|
|
||
| [<Sealed>] | ||
| type private ConfigCommandLineAction() = | ||
| inherit SynchronousCommandLineAction() | ||
|
|
||
| override this.Invoke(parseResult: ParseResult) : int = | ||
| let tabString = " " | ||
| let output = parseResult.InvocationConfiguration.Output | ||
|
|
||
| output.WriteLine("Configuration") | ||
| output.WriteLine($"{tabString}EnablePosixBundling: %b{parseResult.Configuration.EnablePosixBundling}") | ||
|
|
||
| output.WriteLine("Invocation") | ||
| output.WriteLine($"{tabString}EnableDefaultExceptionHandler: %b{parseResult.InvocationConfiguration.EnableDefaultExceptionHandler}") | ||
| output.WriteLine($"""{tabString}ProcessTerminationTimeout: {(if parseResult.InvocationConfiguration.ProcessTerminationTimeout.HasValue then parseResult.InvocationConfiguration.ProcessTerminationTimeout.Value.ToString("c") else "<null>")}""") | ||
| output.WriteLine($"{tabString}Output: {parseResult.InvocationConfiguration.Output}") | ||
| output.WriteLine($"{tabString}Error: {parseResult.InvocationConfiguration.Error}") | ||
|
|
||
| 0 | ||
|
|
||
| let rootCommand = RootCommand("F# sample app.") | ||
|
|
||
| let option = Option<bool>("--language", [| "-l"; "--lang" |], | ||
| Description = "Display the .NET language in use.", | ||
| Arity = ArgumentArity.Zero, | ||
| Action = LanguageCommandLineAction() | ||
| ) | ||
| rootCommand.Options.Add(option) | ||
|
|
||
| let command = Command("repository", "Display GitHub repository information.") | ||
| command.Aliases.Add("repo") | ||
| let argument = Argument<string>("FULL-NAME", | ||
| Description = """The full name of the repository in the form of "owner/repo".""", | ||
| Arity = ArgumentArity.ZeroOrOne, | ||
| DefaultValueFactory = fun (argumentResult: ArgumentResult) -> "FlashOWare/command-line-interfaces" | ||
| ) | ||
| argument.Validators.Add(fun (argumentResult : ArgumentResult) -> | ||
| let value = argumentResult.GetRequiredValue(argument) | ||
|
|
||
| let index = value.IndexOf('/') | ||
| if index = -1 || index <> value.LastIndexOf('/') || index = 0 || index + 1 = value.Length then | ||
| argumentResult.AddError("""The full name of the repository must be in the form of "owner/repo".""") | ||
| ) | ||
| command.Arguments.Add(argument) | ||
| command.SetAction(fun (parseResult: ParseResult) (cancellationToken: CancellationToken) -> (task { | ||
| let fullName = parseResult.GetRequiredValue(argument) | ||
| let index = fullName.IndexOf('/') | ||
| let owner = fullName.Substring(0, index) | ||
| let repo = fullName.Substring(index + 1) | ||
|
|
||
| let name = Assembly.GetExecutingAssembly().GetName() | ||
| let client = GitHubClient(ProductHeaderValue(name.Name, match name.Version with | null -> null | version -> version.ToString())) | ||
| let! repository = client.Repository.Get(owner, repo) | ||
| let rateLimit = client.GetLastApiInfo().RateLimit | ||
|
|
||
| let tabString = " " | ||
| let output = parseResult.InvocationConfiguration.Output | ||
|
|
||
| do! output.WriteLineAsync("Repository") | ||
| do! output.WriteLineAsync($"{tabString}Full Name: {repository.FullName}") | ||
| do! output.WriteLineAsync($"{tabString}Stargazers: {repository.StargazersCount}") | ||
| do! output.WriteLineAsync($"{tabString}Watchers: {repository.SubscribersCount}") | ||
| do! output.WriteLineAsync($"{tabString}Forks: {repository.ForksCount}") | ||
| do! output.WriteLineAsync($"{tabString}Open Issues: {repository.OpenIssuesCount}") | ||
|
|
||
| do! output.WriteLineAsync("Rate Limiting") | ||
| do! output.WriteLineAsync($"{tabString}Requests per hour: {rateLimit.Limit - rateLimit.Remaining} / {rateLimit.Limit}") | ||
| do! output.WriteLineAsync($"""{tabString}Window resets at: {rateLimit.Reset.LocalDateTime.ToString("yyyy-MM-dd HH:mm:ss.fffffff")}""") | ||
|
|
||
| return 0 | ||
| } : Task<int>)) | ||
| rootCommand.Subcommands.Add(command) | ||
|
|
||
| let directive = Directive("config", | ||
| Description = "Show the command-line configuration that would have been used if the given command line were run.", | ||
| Action = ConfigCommandLineAction() | ||
| ) | ||
| rootCommand.Directives.Add(directive) | ||
|
|
||
| let parseResult = rootCommand.Parse(Environment.GetCommandLineArgs() |> Array.skip 1) | ||
| let exitCode = parseResult.Invoke() | ||
| exit exitCode |
25 changes: 25 additions & 0 deletions
25
...shOWare.CommandLine.Example.VisualBasic/FlashOWare.CommandLine.Example.VisualBasic.vbproj
This file contains hidden or 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,25 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>net10.0</TargetFramework> | ||
| <AssemblyName>FlashOWare.CommandLine.Example.VisualBasic</AssemblyName> | ||
| <RootNamespace>FlashOWare.CommandLine.Example</RootNamespace> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Octokit" /> | ||
| <PackageReference Include="System.CommandLine" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\..\lib\FlashOWare.CommandLine.CliSchema\FlashOWare.CommandLine.CliSchema.csproj" /> | ||
| <ProjectReference Include="..\..\lib\FlashOWare.CommandLine.OpenCli\FlashOWare.CommandLine.OpenCli.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <TrimmerRootAssembly Include="FlashOWare.CommandLine.CliSchema" /> | ||
| <TrimmerRootAssembly Include="FlashOWare.CommandLine.OpenCli" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rejected!
This is preparing for
Unsafe evolution, starting with the upcoming C# 15, planned to be releases with C# 16. See: