Skip to content

Commit f2d9092

Browse files
authoredMay 9, 2024··
Merge pull request #5 from Xcaciv/rc1
Rc1
2 parents 9feab36 + 44ddfc2 commit f2d9092

27 files changed

+639
-339
lines changed
 

‎README.md

+7-5
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ Commands are .NET class libraries that contain implementations of the `Xc.Comman
1414

1515
## Roadmap
1616

17-
[X] Threaded piplineing
18-
[ ] Internal commands `SAY` and `REGIF`
19-
[ ] External commands `HEAD` and `SITECERT` (start of web util package)
20-
[ ] Binary package installer
21-
[ ] Source package installer
17+
- [X] Threaded piplineing
18+
- [ ] Internal commands `SAY` and `REGIF`
19+
- [ ] External commands `HEAD` and `SITECERT` (start of web util package)
20+
- [ ] Binary package installer
21+
- [ ] Cupcake shell platform
22+
- [ ] Source package installer
23+
- [ ] dotnet tool installer

‎Xcaciv.Command.sln

+8-8
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Xcaciv.Command.FileLoader",
1010
EndProject
1111
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Xcaciv.Command.FileLoaderTests", "src\Xcaciv.Command.FileLoaderTests\Xcaciv.Command.FileLoaderTests.csproj", "{9B087B2C-5852-4B56-B213-727CB6048784}"
1212
EndProject
13-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Xcaciv.CommandTests", "src\Xcaciv.CommandTests\Xcaciv.CommandTests.csproj", "{B517F2E2-DFEF-4C9E-9C5E-DBCF7873AAA9}"
14-
EndProject
1513
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{6FEF8306-B2C7-489D-9ECC-23BCC8B53C41}"
1614
EndProject
1715
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{B6212A8E-CCFE-492A-95E3-2AAD25970292}"
@@ -22,7 +20,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
2220
EndProject
2321
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "zTestCommandPackage", "src\zTestCommandPackage\zTestCommandPackage.csproj", "{B062C312-8C65-45E6-AF49-0692502DA605}"
2422
EndProject
25-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "zTestCommandPackage.Tests", "src\zTestCommandPackage.Tests\zTestCommandPackage.Tests.csproj", "{59AB8C54-097B-48E9-B42F-37E4252B81D9}"
23+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "zTestCommandPackage.Tests", "src\zTestCommandPackage.Tests\zTestCommandPackage.Tests.csproj", "{59AB8C54-097B-48E9-B42F-37E4252B81D9}"
24+
EndProject
25+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Xcaciv.Command.Tests", "src\Xcaciv.Command.Tests\Xcaciv.Command.Tests.csproj", "{1AA7D848-7F82-4190-8CB8-FDE32B74B0E7}"
2626
EndProject
2727
Global
2828
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -46,10 +46,6 @@ Global
4646
{9B087B2C-5852-4B56-B213-727CB6048784}.Debug|Any CPU.Build.0 = Debug|Any CPU
4747
{9B087B2C-5852-4B56-B213-727CB6048784}.Release|Any CPU.ActiveCfg = Release|Any CPU
4848
{9B087B2C-5852-4B56-B213-727CB6048784}.Release|Any CPU.Build.0 = Release|Any CPU
49-
{B517F2E2-DFEF-4C9E-9C5E-DBCF7873AAA9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
50-
{B517F2E2-DFEF-4C9E-9C5E-DBCF7873AAA9}.Debug|Any CPU.Build.0 = Debug|Any CPU
51-
{B517F2E2-DFEF-4C9E-9C5E-DBCF7873AAA9}.Release|Any CPU.ActiveCfg = Release|Any CPU
52-
{B517F2E2-DFEF-4C9E-9C5E-DBCF7873AAA9}.Release|Any CPU.Build.0 = Release|Any CPU
5349
{B062C312-8C65-45E6-AF49-0692502DA605}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
5450
{B062C312-8C65-45E6-AF49-0692502DA605}.Debug|Any CPU.Build.0 = Debug|Any CPU
5551
{B062C312-8C65-45E6-AF49-0692502DA605}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -58,15 +54,19 @@ Global
5854
{59AB8C54-097B-48E9-B42F-37E4252B81D9}.Debug|Any CPU.Build.0 = Debug|Any CPU
5955
{59AB8C54-097B-48E9-B42F-37E4252B81D9}.Release|Any CPU.ActiveCfg = Release|Any CPU
6056
{59AB8C54-097B-48E9-B42F-37E4252B81D9}.Release|Any CPU.Build.0 = Release|Any CPU
57+
{1AA7D848-7F82-4190-8CB8-FDE32B74B0E7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
58+
{1AA7D848-7F82-4190-8CB8-FDE32B74B0E7}.Debug|Any CPU.Build.0 = Debug|Any CPU
59+
{1AA7D848-7F82-4190-8CB8-FDE32B74B0E7}.Release|Any CPU.ActiveCfg = Release|Any CPU
60+
{1AA7D848-7F82-4190-8CB8-FDE32B74B0E7}.Release|Any CPU.Build.0 = Release|Any CPU
6161
EndGlobalSection
6262
GlobalSection(SolutionProperties) = preSolution
6363
HideSolutionNode = FALSE
6464
EndGlobalSection
6565
GlobalSection(NestedProjects) = preSolution
6666
{9B087B2C-5852-4B56-B213-727CB6048784} = {6FEF8306-B2C7-489D-9ECC-23BCC8B53C41}
67-
{B517F2E2-DFEF-4C9E-9C5E-DBCF7873AAA9} = {6FEF8306-B2C7-489D-9ECC-23BCC8B53C41}
6867
{B062C312-8C65-45E6-AF49-0692502DA605} = {6FEF8306-B2C7-489D-9ECC-23BCC8B53C41}
6968
{59AB8C54-097B-48E9-B42F-37E4252B81D9} = {6FEF8306-B2C7-489D-9ECC-23BCC8B53C41}
69+
{1AA7D848-7F82-4190-8CB8-FDE32B74B0E7} = {6FEF8306-B2C7-489D-9ECC-23BCC8B53C41}
7070
EndGlobalSection
7171
GlobalSection(ExtensibilityGlobals) = postSolution
7272
SolutionGuid = {2C5022E1-F2BA-4FD4-8841-D4B32BD6A7E8}

‎src/Directory.Packages.props

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<!-- Applicaiton Versions -->
66
<ItemGroup>
77
<PackageVersion Include="System.IO.Abstractions" Version="21.0.2" />
8-
<PackageVersion Include="Xcaciv.Loader" Version="1.0.2.11" />
8+
<PackageVersion Include="Xcaciv.Loader" Version="1.0.2.15" />
99
</ItemGroup>
1010
<!-- Unit Test Versions -->
1111
<ItemGroup>

‎src/Xcaciv.Command.FileLoader/Crawler.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public IDictionary<string, PackageDescription> LoadPackageDescriptions(string ba
6262
var commands = new Dictionary<string, CommandDescription>();
6363
packagDesc.Version = context.GetVersion();
6464

65-
foreach (var command in context.GetAllInstances<ICommand>())
65+
foreach (var command in context.GetAllInstances<ICommandDelegate>())
6666
{
6767
commands[command.BaseCommand] = new CommandDescription()
6868
{

‎src/Xcaciv.Command.FileLoaderTests/Xcaciv.Command.FileLoaderTests.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<TargetFramework>net8.0</TargetFramework>
44
<Nullable>enable</Nullable>
55
<IsPackable>false</IsPackable>
6+
<IsTestProject>true</IsTestProject>
67
<AssemblyName>Xcaciv.Command.FileLoaderTests</AssemblyName>
78
<RootNamespace>Xcaciv.Command.FileLoaderTests</RootNamespace>
89
</PropertyGroup>

‎src/Xcaciv.Command.Interface/CommandDescription.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ public class CommandDescription
1515
/// regex for clensing command
1616
/// no exceptions
1717
/// </summary>
18-
public static Regex InvalidCommandChars = new Regex(@"[^-_\da-zA-Z ""]+");
18+
public static Regex InvalidCommandChars = new Regex(@"[^-_\da-zA-Z ]+");
19+
/// <summary>
20+
/// regex for clensing parameters
21+
/// no exceptions
22+
/// </summary>
23+
public static Regex InvalidParameterChars = new Regex(@"[^-_\da-zA-Z .*?\[\]|""~!@#$%^&*\(\)]+");
1924
/// <summary>
2025
/// text command
2126
/// </summary>

‎src/Xcaciv.Command.Interface/DeligateCommand.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace Xcaciv.Command.Interface
88
{
9-
public class DeligateCommand : ICommand
9+
public class DeligateCommand : ICommandDelegate
1010
{
1111
public DeligateCommand(string command, Func<IInputContext, IAsyncEnumerable<string>> commandFunction)
1212
{
@@ -31,7 +31,7 @@ public ValueTask DisposeAsync()
3131
/// <param name="parameters"></param>
3232
/// <param name="messageContext"></param>
3333
/// <returns></returns>
34-
async IAsyncEnumerable<string> ICommand.Main(IInputContext input, IStatusContext statusContext)
34+
async IAsyncEnumerable<string> ICommandDelegate.Main(IInputContext input, IStatusContext statusContext)
3535
{
3636
if (this.commandFunction != null)
3737
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+

2+
namespace Xcaciv.Command.Interface
3+
{
4+
public interface ICommandController
5+
{
6+
void AddPackageDirectory(string directory);
7+
void LoadCommands(string subDirectory = "bin");
8+
Task Run(string commandLine, ITextIoContext output);
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
6-
7-
namespace Xcaciv.Command.Interface
8-
{
9-
/// <summary>
10-
/// interface for commands that can be issued from a shell
11-
/// </summary>
12-
public interface ICommand : IAsyncDisposable
13-
{
14-
/// <summary>
15-
/// unique typed command - alphanumeric with dash or underscore
16-
/// </summary>
17-
string BaseCommand { get; }
18-
/// <summary>
19-
/// Display name - may contain special characters
20-
/// </summary>
21-
string FriendlyName { get; }
22-
/// <summary>
23-
/// primary command execution method
24-
/// </summary>
25-
/// <param name="parameters"></param>
26-
/// <param name="messageContext">used for progress and status messages</param>
27-
/// <returns></returns>
28-
IAsyncEnumerable<string> Main(IInputContext input, IStatusContext statusContext);
29-
/// <summary>
30-
/// output usage instructions via message context
31-
/// </summary>
32-
/// <param name="messageContext"></param>
33-
/// <returns></returns>
34-
Task Help(ITextIoContext messageContext);
35-
}
36-
}
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace Xcaciv.Command.Interface
8+
{
9+
/// <summary>
10+
/// interface for commands that can be issued from a shell
11+
/// </summary>
12+
public interface ICommandDelegate : IAsyncDisposable
13+
{
14+
/// <summary>
15+
/// unique typed command - alphanumeric with dash or underscore
16+
/// </summary>
17+
string BaseCommand { get; }
18+
/// <summary>
19+
/// Display name - may contain special characters
20+
/// </summary>
21+
string FriendlyName { get; }
22+
/// <summary>
23+
/// primary command execution method
24+
/// </summary>
25+
/// <param name="parameters"></param>
26+
/// <param name="messageContext">used for progress and status messages</param>
27+
/// <returns></returns>
28+
IAsyncEnumerable<string> Main(IInputContext input, IStatusContext statusContext);
29+
/// <summary>
30+
/// output usage instructions via message context
31+
/// </summary>
32+
/// <param name="messageContext"></param>
33+
/// <returns></returns>
34+
Task Help(ITextIoContext messageContext);
35+
}
36+
}
3737

‎src/Xcaciv.Command.Interface/ICommandFactory.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ public interface ICommandFactory
1515
/// new up a instance of a particular command and box it
1616
/// </summary>
1717
/// <returns></returns>
18-
ICommand CreateCommandInstance();
18+
ICommandDelegate CreateCommandInstance();
1919
}
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,60 @@
1-
using Xunit;
2-
using Xcaciv.Command;
3-
using System;
4-
using System.Collections.Generic;
5-
using System.Linq;
6-
using System.Text;
7-
using System.Threading.Tasks;
8-
using Xunit.Abstractions;
9-
using System.IO.Abstractions;
10-
using Xcaciv.Command.FileLoader;
11-
12-
namespace Xcaciv.CommandTests
13-
{
14-
public class CommandControllerTests
15-
{
16-
private ITestOutputHelper _testOutput;
17-
private string commandPackageDir = @"..\..\..\..\zTestCommandPackage\bin\{1}\";
18-
public CommandControllerTests(ITestOutputHelper output)
19-
{
20-
_testOutput = output;
21-
#if DEBUG
22-
_testOutput.WriteLine("Tests in Debug mode");
23-
commandPackageDir = commandPackageDir.Replace("{1}", "Debug");
24-
#else
25-
this._testOutput.WriteLine("Tests in Release mode??");
26-
this.commandPackageDir = commandPackageDir.Replace("{1}", "Release");
27-
#endif
28-
}
29-
[Fact()]
30-
public async Task RunCommandsTestAsync()
31-
{
32-
var commands = new CommandController(new Crawler(), @"..\..\..\..\..\");
33-
commands.AddPackageDirectory(commandPackageDir);
34-
35-
commands.LoadCommands(string.Empty);
36-
var textio = new TestImpementations.TestTextIo();
37-
// simulate user input
38-
await commands.Run("echo what is up", textio);
39-
40-
// verify the output of the first run
41-
// by looking at the output of the second output line
42-
Assert.Equal("> what", textio.Children.First().Output[1]);
43-
}
44-
[Fact()]
45-
public async Task PipeCommandsTestAsync()
46-
{
47-
var commands = new CommandController(new Crawler(), @"..\..\..\..\..\");
48-
commands.AddPackageDirectory(commandPackageDir);
49-
50-
commands.LoadCommands(string.Empty);
51-
var textio = new TestImpementations.TestTextIo();
52-
// simulate user input
53-
await commands.Run("echo what is up | echo2 | echoe ", textio);
54-
55-
// verify the output of the first run
56-
// by looking at the output of the second output line
57-
Assert.Equal("> :d2hhdC13aGF0:-:d2hhdC13aGF0:-> :aXMtaXM=:-:aXMtaXM=:-> :dXAtdXA=:-:dXAtdXA=:", textio.ToString());
58-
}
59-
}
1+
using Xunit;
2+
using Xcaciv.Command;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
using Xunit.Abstractions;
9+
using System.IO.Abstractions;
10+
using Xcaciv.Command.FileLoader;
11+
12+
namespace Xcaciv.Command.Tests
13+
{
14+
public class CommandControllerTests
15+
{
16+
private ITestOutputHelper _testOutput;
17+
private string commandPackageDir = @"..\..\..\..\zTestCommandPackage\bin\{1}\";
18+
public CommandControllerTests(ITestOutputHelper output)
19+
{
20+
_testOutput = output;
21+
#if DEBUG
22+
_testOutput.WriteLine("Tests in Debug mode");
23+
commandPackageDir = commandPackageDir.Replace("{1}", "Debug");
24+
#else
25+
this._testOutput.WriteLine("Tests in Release mode??");
26+
this.commandPackageDir = commandPackageDir.Replace("{1}", "Release");
27+
#endif
28+
}
29+
[Fact()]
30+
public async Task RunCommandsTestAsync()
31+
{
32+
var commands = new CommandController(new Crawler(), @"..\..\..\..\..\");
33+
commands.AddPackageDirectory(commandPackageDir);
34+
35+
commands.LoadCommands(string.Empty);
36+
var textio = new TestImpementations.TestTextIo();
37+
// simulate user input
38+
await commands.Run("echo what is up", textio);
39+
40+
// verify the output of the first run
41+
// by looking at the output of the second output line
42+
Assert.Equal("> what", textio.Children.First().Output[1]);
43+
}
44+
[Fact()]
45+
public async Task PipeCommandsTestAsync()
46+
{
47+
var commands = new CommandController(new Crawler(), @"..\..\..\..\..\");
48+
commands.AddPackageDirectory(commandPackageDir);
49+
50+
commands.LoadCommands(string.Empty);
51+
var textio = new TestImpementations.TestTextIo();
52+
// simulate user input
53+
await commands.Run("echo what is up | echo2 | echoe ", textio);
54+
55+
// verify the output of the first run
56+
// by looking at the output of the second output line
57+
Assert.Equal("> :d2hhdC13aGF0:-:d2hhdC13aGF0:-> :aXMtaXM=:-:aXMtaXM=:-> :dXAtdXA=:-:dXAtdXA=:", textio.ToString());
58+
}
59+
}
6060
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using Xunit;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using Xcaciv.Command.FileLoader;
8+
using Xunit.Abstractions;
9+
10+
namespace Xcaciv.Command.Tests.Commands
11+
{
12+
public class RegifCommandTests
13+
{
14+
private ITestOutputHelper _testOutput;
15+
private string commandPackageDir = @"..\..\..\..\zTestCommandPackage\bin\{1}\";
16+
public RegifCommandTests(ITestOutputHelper output)
17+
{
18+
_testOutput = output;
19+
#if DEBUG
20+
_testOutput.WriteLine("Tests in Debug mode");
21+
commandPackageDir = commandPackageDir.Replace("{1}", "Debug");
22+
#else
23+
this._testOutput.WriteLine("Tests in Release mode??");
24+
this.commandPackageDir = commandPackageDir.Replace("{1}", "Release");
25+
#endif
26+
}
27+
28+
[Fact()]
29+
public async Task HandleExecutionTestAsync()
30+
{
31+
var commands = new CommandController(new Crawler(), @"..\..\..\..\..\");
32+
commands.AddPackageDirectory(commandPackageDir);
33+
commands.LoadDefaultCommands();
34+
commands.LoadCommands(string.Empty);
35+
36+
37+
var textio = new TestImpementations.TestTextIo();
38+
// simulate user input
39+
await commands.Run("echo what is up | regif is", textio);
40+
41+
// verify the output of the first run
42+
// by looking at the output of the second output line
43+
Assert.Equal("> --> is-is-> -", textio.ToString());
44+
}
45+
}
46+
}

0 commit comments

Comments
 (0)
Please sign in to comment.