Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Build Projects

on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch:

jobs:
test:
runs-on: windows-latest
name: Unit Test
permissions:
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@master
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
8.x
10.x
- name: Run unit tests
run: |
dotnet test
build:
runs-on: windows-latest
name: Build Project
permissions:
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@master
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
8.x
10.x
- name: Build (debug)
run: |
dotnet build -c Debug
- name: Clean
run: |
dotnet clean
- name: Build (release)
run: |
dotnet build -c Release
17 changes: 17 additions & 0 deletions .github/workflows/publish-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,23 @@ on:
workflow_dispatch:

jobs:
test:
runs-on: windows-latest
name: Unit Test
permissions:
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@master
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
8.x
10.x
- name: Run unit tests
run: |
dotnet test
build:
runs-on: windows-latest
strategy:
Expand Down
17 changes: 17 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,23 @@ on:
workflow_dispatch:

jobs:
test:
runs-on: windows-latest
name: Unit Test
permissions:
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@master
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
8.x
10.x
- name: Run unit tests
run: |
dotnet test
build:
runs-on: windows-latest
strategy:
Expand Down
29 changes: 29 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Run Unit Tests

on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch:

jobs:
test:
runs-on: windows-latest
name: Unit Test
permissions:
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@master
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
8.x
10.x
- name: Run unit tests
run: |
dotnet test
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -349,3 +349,6 @@ MigrationBackup/
# Ionide (cross platform F# VS Code tools) working folder
.ionide/
publish.ps1

# IntelliJ
.idea
14 changes: 14 additions & 0 deletions kate.shared.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "kate.shared.CommandLine", "
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "kate.shared.EtoForms", "src\kate.shared.EtoForms\kate.shared.EtoForms.csproj", "{E6403316-5C2D-4C9B-BC92-380A8C3CD4C4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "kate.shared.CommandLine.Test", "src\kate.shared.CommandLine.Test\kate.shared.CommandLine.Test.csproj", "{8A46A5DC-8A11-4728-9A8E-ABD2C9BA0540}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -55,6 +57,18 @@ Global
{E6403316-5C2D-4C9B-BC92-380A8C3CD4C4}.Release|x64.Build.0 = Release|Any CPU
{E6403316-5C2D-4C9B-BC92-380A8C3CD4C4}.Release|x86.ActiveCfg = Release|Any CPU
{E6403316-5C2D-4C9B-BC92-380A8C3CD4C4}.Release|x86.Build.0 = Release|Any CPU
{8A46A5DC-8A11-4728-9A8E-ABD2C9BA0540}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8A46A5DC-8A11-4728-9A8E-ABD2C9BA0540}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8A46A5DC-8A11-4728-9A8E-ABD2C9BA0540}.Debug|x64.ActiveCfg = Debug|Any CPU
{8A46A5DC-8A11-4728-9A8E-ABD2C9BA0540}.Debug|x64.Build.0 = Debug|Any CPU
{8A46A5DC-8A11-4728-9A8E-ABD2C9BA0540}.Debug|x86.ActiveCfg = Debug|Any CPU
{8A46A5DC-8A11-4728-9A8E-ABD2C9BA0540}.Debug|x86.Build.0 = Debug|Any CPU
{8A46A5DC-8A11-4728-9A8E-ABD2C9BA0540}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8A46A5DC-8A11-4728-9A8E-ABD2C9BA0540}.Release|Any CPU.Build.0 = Release|Any CPU
{8A46A5DC-8A11-4728-9A8E-ABD2C9BA0540}.Release|x64.ActiveCfg = Release|Any CPU
{8A46A5DC-8A11-4728-9A8E-ABD2C9BA0540}.Release|x64.Build.0 = Release|Any CPU
{8A46A5DC-8A11-4728-9A8E-ABD2C9BA0540}.Release|x86.ActiveCfg = Release|Any CPU
{8A46A5DC-8A11-4728-9A8E-ABD2C9BA0540}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
127 changes: 127 additions & 0 deletions src/kate.shared.CommandLine.Test/SimpleCommandTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/*
Copyright 2022-2026 Kate Ward <kate@dariox.club>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
using System.CommandLine;
using JetBrains.Annotations;

namespace kate.shared.CommandLine.Test;

public class Tests
{
[Test]
public void SimpleCommandImplicit()
{
var c = CommandLineHelper.GenerateCommand<TestAction1.Options, TestAction1>();
var r = new RootCommand()
{
c
};
var e = r.Parse(["test"]).Invoke();
Assert.That(e, Is.EqualTo(0));
}

[Test]
public void SimpleCommandExplicit()
{
var c = CommandLineHelper.GenerateCommandExplicit<TestAction2.Options, TestAction2>();

var r = new RootCommand()
{
c
};
var e = r.Parse(["test"]).Invoke();
Assert.That(e, Is.EqualTo(0));
}

[Test]
public void SimpleCommandExplicitMultiToken()
{
var c = CommandLineHelper.GenerateCommandExplicit<TestActionMulti3.Options, TestActionMulti3>();

var r = new RootCommand()
{
c
};
var e = r.Parse([
"test",
"--array", "bweh1",
"--array", "test2",
"--array", "ur mom",
"--array", "HAHAHA X3!!!"]).Invoke();
Assert.That(e, Is.EqualTo(0));
}

[UsedImplicitly]
[CommandAction("test", typeof(Options))]
public class TestAction1 : IAction
{
[UsedImplicitly]
public Task RunAsync(object options)
{
if (options is not Options)
throw new InvalidOperationException("Test failure - invalid type: " + options?.GetType());
Console.WriteLine("Log from inside TestAction1");
return Task.CompletedTask;
}

[UsedImplicitly]
public class Options
{
}
}

[UsedImplicitly]
[CommandAction("test", typeof(Options))]
public class TestAction2 : IAction<TestAction2.Options>
{
[UsedImplicitly]
public Task RunAsync(Options options)
{
Console.WriteLine("Log from inside TestAction2");
return Task.CompletedTask;
}

[UsedImplicitly]
public class Options
{
}
}

[UsedImplicitly]
[CommandAction("test", typeof(Options))]
public class TestActionMulti3 : IAction<TestActionMulti3.Options>
{
[UsedImplicitly]
public Task RunAsync(Options options)
{
Console.WriteLine("Log from inside TestActionMulti3");
Assert.That(options, Is.Not.Null);
Assert.That(options.ArrayValue, Is.Not.Null);
Assert.That(options.ArrayValue, Has.Length.EqualTo(4));
Assert.That(options.ArrayValue[0], Is.EqualTo("bweh1"));
Assert.That(options.ArrayValue[1], Is.EqualTo("test2"));
Assert.That(options.ArrayValue[2], Is.EqualTo("ur mom"));
Assert.That(options.ArrayValue[3], Is.EqualTo("HAHAHA X3!!!"));
return Task.CompletedTask;
}

[UsedImplicitly]
public class Options
{
[ActionParameter("array", "Array", AllowMultipleArgumentsPerToken = true)]
public string[] ArrayValue { get; set; } = Array.Empty<string>();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.4"/>
<PackageReference Include="JetBrains.Annotations" Version="2026.2.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.0"/>
<PackageReference Include="NUnit" Version="4.3.2"/>
<PackageReference Include="NUnit.Analyzers" Version="4.7.0"/>
<PackageReference Include="NUnit3TestAdapter" Version="5.0.0"/>
</ItemGroup>

<ItemGroup>
<Using Include="NUnit.Framework"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\kate.shared.CommandLine\kate.shared.CommandLine.csproj" />
</ItemGroup>

</Project>
12 changes: 11 additions & 1 deletion src/kate.shared.CommandLine/ActionParameterAliasAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022-2025 Kate Ward <kate@dariox.club>
Copyright 2022-2026 Kate Ward <kate@dariox.club>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -15,17 +15,22 @@ limitations under the License.
*/

using System;
using System.ComponentModel;
using JetBrains.Annotations;

namespace kate.shared.CommandLine
{
/// <summary>
/// Define multiple aliases for <see cref="ActionParameterAttribute"/>.
/// </summary>
[PublicAPI]
[AttributeUsage(AttributeTargets.Property, AllowMultiple = true, Inherited = false)]
public class ActionParameterAliasAttribute : Attribute
{
public ActionParameterAliasAttribute(string alias, ActionParameterAliasKind kind)
{
if (string.IsNullOrWhiteSpace(alias))
throw new ArgumentException("Value cannot be null or whitespace", nameof(alias));
Alias = alias;
CustomPrefix = null;
Kind = kind;
Expand All @@ -36,8 +41,13 @@ public ActionParameterAliasAttribute(string alias)
{
}

[NotNull]
public string Alias { get; set; }

[CanBeNull]
public string CustomPrefix { get; set; }

[DefaultValue(ActionParameterAliasKind.DoubleDash)]
public ActionParameterAliasKind Kind { get; set; }
}
}
5 changes: 4 additions & 1 deletion src/kate.shared.CommandLine/ActionParameterAliasKind.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022-2025 Kate Ward <kate@dariox.club>
Copyright 2022-2026 Kate Ward <kate@dariox.club>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -14,11 +14,14 @@ You may obtain a copy of the License at
limitations under the License.
*/

using JetBrains.Annotations;

namespace kate.shared.CommandLine
{
/// <summary>
/// Kind of alias for <see cref="ActionParameterAliasAttribute"/>
/// </summary>
[PublicAPI]
public enum ActionParameterAliasKind
{
/// <summary>
Expand Down
Loading
Loading