This repository has been archived by the owner on Jun 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from EternalQuasar0206/refactor/hard-refactor-u…
…pdates v2.0.0: hard refactor updates and remade features
- Loading branch information
Showing
29 changed files
with
706 additions
and
181 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace Cli.NET.Abstractions.Actions | ||
{ | ||
public interface ICommand | ||
{ | ||
public void Execute(string[] arguments); | ||
} | ||
} |
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,9 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
</Project> |
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,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Cli.NET.Abstractions\Cli.NET.Abstractions.csproj" /> | ||
<ProjectReference Include="..\Cli.NET\Cli.NET.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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,15 @@ | ||
using Cli.NET.Actions; | ||
using Cli.NET.Tools; | ||
|
||
var container = new CommandContainer(); | ||
|
||
container.Register(new() | ||
{ | ||
{ "exit", new ExitCommand() }, | ||
{ "echo", new EchoCommand() }, | ||
{ "sum", new SumCommand() }, | ||
{ "clear", new ClearCommand() }, | ||
{ "cls", new ClearCommand() } | ||
}); | ||
|
||
container.WaitForNextCommand(); |
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 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.1.32210.238 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cli.NET", "Cli.NET\Cli.NET.csproj", "{071AAB32-CFAB-4A02-9203-9E0A1D831DB4}" | ||
EndProject | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cli.NET.Abstractions", "Cli.NET.Abstractions\Cli.NET.Abstractions.csproj", "{4887C5D7-2C3B-4E33-B7A5-DF48571FF08F}" | ||
EndProject | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cli.NET.Console", "Cli.NET.Console\Cli.NET.Console.csproj", "{B57D8554-6089-4093-9251-9CE6A30B7D6C}" | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "RepositoryItems", "RepositoryItems", "{FE91112C-5E7A-4C53-8708-5EEF11074BE7}" | ||
ProjectSection(SolutionItems) = preProject | ||
..\README.MD = ..\README.MD | ||
EndProjectSection | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{071AAB32-CFAB-4A02-9203-9E0A1D831DB4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{071AAB32-CFAB-4A02-9203-9E0A1D831DB4}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{071AAB32-CFAB-4A02-9203-9E0A1D831DB4}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{071AAB32-CFAB-4A02-9203-9E0A1D831DB4}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{4887C5D7-2C3B-4E33-B7A5-DF48571FF08F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{4887C5D7-2C3B-4E33-B7A5-DF48571FF08F}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{4887C5D7-2C3B-4E33-B7A5-DF48571FF08F}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{4887C5D7-2C3B-4E33-B7A5-DF48571FF08F}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{B57D8554-6089-4093-9251-9CE6A30B7D6C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{B57D8554-6089-4093-9251-9CE6A30B7D6C}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{B57D8554-6089-4093-9251-9CE6A30B7D6C}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{B57D8554-6089-4093-9251-9CE6A30B7D6C}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {03167DE2-D179-434A-AE02-A17D4058BBE4} | ||
EndGlobalSection | ||
EndGlobal |
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,19 @@ | ||
using Cli.NET.Abstractions.Actions; | ||
|
||
namespace Cli.NET.Actions | ||
{ | ||
/// <summary> | ||
/// Default example "clear" command to erase the information in the screen | ||
/// and writes new information if given. | ||
/// </summary> | ||
public class ClearCommand : ICommand | ||
{ | ||
public void Execute(string[] arguments) | ||
{ | ||
Console.Clear(); | ||
|
||
if(arguments.Any()) | ||
Console.WriteLine(string.Join("", arguments)); | ||
} | ||
} | ||
} |
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,12 @@ | ||
using Cli.NET.Abstractions.Actions; | ||
|
||
namespace Cli.NET.Actions | ||
{ | ||
/// <summary> | ||
/// Default example "echo" command to display data in the console. | ||
/// </summary> | ||
public class EchoCommand : ICommand | ||
{ | ||
public void Execute(string[] arguments) => Console.WriteLine(string.Join(" ", arguments)); | ||
} | ||
} |
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,17 @@ | ||
using Cli.NET.Abstractions.Actions; | ||
|
||
namespace Cli.NET.Actions | ||
{ | ||
public class ExitCommand : ICommand | ||
{ | ||
/// <summary> | ||
/// Default example "exit" command with a given exit code. | ||
/// </summary> | ||
/// <param name="args"></param> | ||
public void Execute(string[] args) | ||
{ | ||
try { Environment.Exit(int.Parse(args[0])); } | ||
catch { Environment.Exit(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,13 @@ | ||
using Cli.NET.Abstractions.Actions; | ||
|
||
namespace Cli.NET.Actions | ||
{ | ||
public class SumCommand : ICommand | ||
{ | ||
public void Execute(string[] arguments) | ||
{ | ||
try { Console.WriteLine(long.Parse(arguments[0]) + long.Parse(arguments[1])); } | ||
catch { Console.WriteLine("NaN"); } | ||
} | ||
} | ||
} |
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,13 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Cli.NET.Abstractions\Cli.NET.Abstractions.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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,31 @@ | ||
namespace Cli.NET.Extensions | ||
{ | ||
public static class ParameterExtensions | ||
{ | ||
public static IDictionary<string, string> GetArguments(this string[] parameters) | ||
{ | ||
Dictionary<string, string> arguments = new(); | ||
|
||
var targets = parameters.Skip(1); | ||
var argumentHeader = string.Empty; | ||
var argumentInformation = string.Empty; | ||
|
||
int currentHeaderIndex = -1; | ||
foreach (var target in targets) | ||
{ | ||
if (target.StartsWith("-")) | ||
{ | ||
currentHeaderIndex++; | ||
argumentHeader = target; | ||
} | ||
else | ||
{ | ||
argumentInformation += target; | ||
arguments.Add(argumentHeader, argumentInformation); | ||
} | ||
} | ||
|
||
return arguments; | ||
} | ||
} | ||
} |
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,4 @@ | ||
using Cli.NET.Abstractions.Actions; | ||
|
||
namespace Cli.NET.Models; | ||
public class CommandList : Dictionary<string, ICommand> {} |
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,19 @@ | ||
namespace Cli.NET.Models | ||
{ | ||
public class Output | ||
{ | ||
/// <summary> | ||
/// Output default model to manage console responses. | ||
/// </summary> | ||
/// <param name="message"></param> | ||
/// <param name="type"></param> | ||
public Output(string message, OutputType type) | ||
{ | ||
Message = message; | ||
Type = type; | ||
} | ||
|
||
public OutputType Type { get; set; } | ||
public string Message { 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,9 @@ | ||
namespace Cli.NET.Models | ||
{ | ||
public enum OutputType | ||
{ | ||
Message, | ||
Warning, | ||
Error | ||
} | ||
} |
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,2 @@ | ||
namespace Cli.NET.Models; | ||
public class OutputList : Dictionary<DateTime, Output> { } |
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,55 @@ | ||
namespace Cli.NET.Tools | ||
{ | ||
public static class CLNConsole | ||
{ | ||
public static void WriteLine(string message) => Console.WriteLine(message); | ||
public static void WriteLine(string message, string color) => WriteLine(message, Enum.Parse<ConsoleColor>(color)); | ||
public static void WriteLine(string message, int color) => WriteLine(message, (ConsoleColor)color); | ||
public static void WriteLine(string message, ConsoleColor color) | ||
{ | ||
Console.ForegroundColor = color; | ||
Console.WriteLine(message); | ||
Console.ResetColor(); | ||
} | ||
|
||
public static void Write(string message) => Console.Write(message); | ||
public static void Write(string message, string color) => Write(message, Enum.Parse<ConsoleColor>(color)); | ||
public static void Write(string message, int color) => Write(message, (ConsoleColor)color); | ||
public static void Write(string message, ConsoleColor color) | ||
{ | ||
Console.ForegroundColor = color; | ||
Console.Write(message); | ||
Console.ResetColor(); | ||
} | ||
|
||
public static string ReadText() => Console.ReadLine() ?? string.Empty; | ||
public static string? ReadText(uint minLength = 0, uint maxLength = int.MaxValue) | ||
{ | ||
string input = ReadText(); | ||
|
||
if (input.Length > maxLength || input.Length < minLength) | ||
return null; | ||
|
||
return input; | ||
} | ||
|
||
public static string? DataQuestion(string message) | ||
{ | ||
WriteLine(message); | ||
return ReadText(); | ||
} | ||
public static string? DataQuestion(string message, string color, uint minLength = 0, uint maxLength = int.MaxValue) | ||
{ | ||
return DataQuestion(message, Enum.Parse<ConsoleColor>(color), minLength, maxLength); | ||
} | ||
public static string? DataQuestion(string message, int color, uint minLength = 0, uint maxLength = int.MaxValue) | ||
{ | ||
return DataQuestion(message, (ConsoleColor)color, minLength, maxLength); | ||
} | ||
public static string? DataQuestion(string message, ConsoleColor color, uint minLength = 0, uint maxLength = int.MaxValue) | ||
{ | ||
WriteLine(message, color); | ||
return ReadText(minLength, maxLength); | ||
} | ||
} | ||
} |
Oops, something went wrong.