Skip to content

Commit

Permalink
Fixing package name and adding some more options
Browse files Browse the repository at this point in the history
  • Loading branch information
tsharp committed Dec 5, 2024
1 parent a11d461 commit b4e2cb1
Show file tree
Hide file tree
Showing 24 changed files with 278 additions and 39 deletions.
4 changes: 4 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@

<!-- Don't expose experimental features -->
<ExposeExperimentalFeatures Condition="'$(ExposeExperimentalFeatures)' == ''">false</ExposeExperimentalFeatures>

<!-- Use Lock File for Restores -->
<!-- https://devblogs.microsoft.com/nuget/enable-repeatable-package-restores-using-a-lock-file/ -->
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
</PropertyGroup>

<!-- Build Versioning -->
Expand Down
13 changes: 13 additions & 0 deletions packages.lock.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": 2,
"dependencies": {
".NETFramework,Version=v4.5": {
"Microsoft.Build.Artifacts": {
"type": "Direct",
"requested": "[6.1.10, )",
"resolved": "6.1.10",
"contentHash": "7B6h7yAZ6RD4osQSaIUnmMZ96RXPHUzyCrK/kAYQjyTO2i71LjOAdR0HjSus7HRwYhi94f2iZ+f0qMO9b2ykkQ=="
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using XArch.PlatformManagement.CommandLine;
using XArch.CommandLine;

namespace XArch.PlatformManagement.CommandLine.Sample.Modules.Test
namespace XArch.CommandLine.Sample.Modules.Test
{
[RegisterCommand(command: "hello")]
internal class HelloWorldCommand : CommandBase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

using Microsoft.Extensions.DependencyInjection;

using XArch.PlatformManagement.CommandLine;

namespace XArch.PlatformManagement.CommandLine.Sample
namespace XArch.CommandLine.Sample
{
internal class Program
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\XArch.PlatformManagement.CommandLine\XArch.PlatformManagement.CommandLine.csproj" />
<ProjectReference Include="..\XArch.CommandLine\XArch.CommandLine.csproj" />
</ItemGroup>

</Project>
54 changes: 54 additions & 0 deletions src/XArch.CommandLine.Sample/packages.lock.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"version": 2,
"dependencies": {
"net8.0": {
"Microsoft.Build.Artifacts": {
"type": "Direct",
"requested": "[6.1.10, )",
"resolved": "6.1.10",
"contentHash": "7B6h7yAZ6RD4osQSaIUnmMZ96RXPHUzyCrK/kAYQjyTO2i71LjOAdR0HjSus7HRwYhi94f2iZ+f0qMO9b2ykkQ=="
},
"Microsoft.Extensions.DependencyInjection": {
"type": "Direct",
"requested": "[8.0.0, )",
"resolved": "8.0.0",
"contentHash": "V8S3bsm50ig6JSyrbcJJ8bW2b9QLGouz+G1miK3UTaOWmMtFwNNNzUf4AleyDWUmTrWMLNnFSLEQtxmxgNQnNQ==",
"dependencies": {
"Microsoft.Extensions.DependencyInjection.Abstractions": "8.0.0"
}
},
"System.CommandLine": {
"type": "Direct",
"requested": "[2.0.0-beta4.22272.1, )",
"resolved": "2.0.0-beta4.22272.1",
"contentHash": "1uqED/q2H0kKoLJ4+hI2iPSBSEdTuhfCYADeJrAqERmiGQ2NNacYKRNEQ+gFbU4glgVyK8rxI+ZOe1onEtr/Pg=="
},
"YamlDotNet": {
"type": "Direct",
"requested": "[16.2.1, )",
"resolved": "16.2.1",
"contentHash": "im6zTVgesjcfTRfuMpnx51Rg2svWenp/3q5XBfcIzgj8PNIkkSD2xEl9HWcVi2SaJPP9XcXUdzed9gSDEuf1TA=="
},
"Microsoft.Extensions.DependencyInjection.Abstractions": {
"type": "Transitive",
"resolved": "8.0.0",
"contentHash": "cjWrLkJXK0rs4zofsK4bSdg+jhDLTaxrkXu4gS6Y7MAlCvRyNNgwY/lJi5RDlQOnSZweHqoyvgvbdvQsRIW+hg=="
},
"xarch.commandline": {
"type": "Project",
"dependencies": {
"Microsoft.Extensions.DependencyInjection": "[8.0.0, )",
"System.CommandLine": "[2.0.0-beta4.22272.1, )",
"System.Text.Json": "[8.0.5, )",
"YamlDotNet": "[16.2.1, )"
}
},
"System.Text.Json": {
"type": "CentralTransitive",
"requested": "[8.0.5, )",
"resolved": "8.0.5",
"contentHash": "0f1B50Ss7rqxXiaBJyzUu9bWFOO2/zSlifZ/UNMdiIpDYe4cY4LQQicP4nirK1OS31I43rn062UIJ1Q9bpmHpg=="
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

using Microsoft.Extensions.DependencyInjection;

namespace XArch.PlatformManagement.CommandLine
namespace XArch.CommandLine
{
public abstract class CommandBase
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.IO;

namespace XArch.PlatformManagement.CommandLine
namespace XArch.CommandLine
{
internal sealed class CommandContextDataProvider : ICommandContextDataProvider
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.CommandLine.Invocation;

namespace XArch.PlatformManagement.CommandLine
namespace XArch.CommandLine
{
public class CommandExecutionContext : IDisposable
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.CommandLine.Parsing;
using System.Threading.Tasks;

namespace XArch.PlatformManagement.CommandLine
namespace XArch.CommandLine
{
internal sealed class CommandRuntime : ICommandRuntime
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

using Microsoft.Extensions.DependencyInjection;

namespace XArch.PlatformManagement.CommandLine
namespace XArch.CommandLine
{
public sealed class CommandRuntimeBuilder
{
Expand Down Expand Up @@ -140,7 +140,7 @@ private void GenerateAssemblyCommands(RootCommand rootCommand, Assembly assembly
private void RegisterCommandHandlers()
{
// Services and configure commands now ...
this.serviceProvider = serviceDescriptors.BuildServiceProvider();
serviceProvider = serviceDescriptors.BuildServiceProvider();

foreach (var commandDescriptor in commandDescriptors)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace XArch.PlatformManagement.CommandLine
namespace XArch.CommandLine
{
public abstract class ContextData
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace XArch.PlatformManagement.CommandLine
namespace XArch.CommandLine
{
public interface ICommandContextDataProvider
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Threading.Tasks;

namespace XArch.PlatformManagement.CommandLine
namespace XArch.CommandLine
{
public interface ICommandRuntime
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace XArch.PlatformManagement.CommandLine
namespace XArch.CommandLine
{
internal class NamespaceContextData
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;

namespace XArch.PlatformManagement.CommandLine
namespace XArch.CommandLine
{
internal sealed class NestedServiceProvider : IServiceProvider
{
Expand All @@ -15,8 +15,8 @@ public NestedServiceProvider(IServiceProvider parentServiceProvider, IServicePro

public object GetService(Type serviceType)
{
return this.serviceProvider.GetService(serviceType) ??
this.parentServiceProvider.GetService(serviceType);
return serviceProvider.GetService(serviceType) ??
parentServiceProvider.GetService(serviceType);
}
}
}
31 changes: 31 additions & 0 deletions src/XArch.CommandLine/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# XArch.CommandLine

XArch.CommandLine is a library that provides a basic framework for building command-line applications. It is built on top of the `System.CommandLine` library and provides a more structured way to build command-line applications.

## Features
- Dependency injection
- Module-based architecture
- REPL support
- Command-line parsing and completion support from `System.CommandLine`
- Context-aware commands and ability to save state between commands

## Example
```CSharp
internal class Program
{
static async Task Main(string[] args)
{
await CommandRuntimeBuilder
.Create()
.ConfigureServices(ConfigureServices)
.RegisterModuleAssembly(Assembly.GetExecutingAssembly())
.UseRepl()
.Build()
.RunAsync(args);
}

private static void ConfigureServices(IServiceCollection services)
{
}
}
```
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Text.RegularExpressions;

namespace XArch.PlatformManagement.CommandLine
namespace XArch.CommandLine
{

[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.NamingConventions;

namespace XArch.PlatformManagement.CommandLine
namespace XArch.CommandLine
{
internal static class Serialization
{
Expand Down
38 changes: 38 additions & 0 deletions src/XArch.CommandLine/XArch.CommandLine.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<PropertyGroup>
<PackageId>XArch.CommandLine</PackageId>
<PackageReadmeFile>README.md</PackageReadmeFile>
<Authors>Travis Sharp</Authors>
<EnablePackageValidation>true</EnablePackageValidation>
<ApiCompatRespectInternals>true</ApiCompatRespectInternals>
<!--<PackRelease>true</PackRelease>-->
<!--<CopyDocumentationFilesFromPackages>true</CopyDocumentationFilesFromPackages>-->
</PropertyGroup>

<PropertyGroup Condition="'$(GITHUB_ACTIONS)' == 'true'">
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
</PropertyGroup>

<PropertyGroup Condition="'$(TF_BUILD)' == 'true'">
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
</PropertyGroup>

<ItemGroup>
<None Include="README.md" Pack="true" PackagePath="\"/>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" />
<PackageReference Include="YamlDotNet" />
<PackageReference Include="System.Text.Json" />
<PackageReference Include="System.CommandLine" />
</ItemGroup>

</Project>
Loading

0 comments on commit b4e2cb1

Please sign in to comment.