using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using Microsoft.CodeAnalysis;
using SimpleCommandLib.Extensions;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("SimpleCommandLib")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.1.1.0")]
[assembly: AssemblyInformationalVersion("1.1.1+9ccfe06d083905d8551d571579e1465922175bfc")]
[assembly: AssemblyProduct("SimpleCommandLib")]
[assembly: AssemblyTitle("SimpleCommandLib")]
[assembly: AssemblyVersion("1.1.1.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace SimpleCommandLib
{
public abstract class CommandDispatcher
{
public KeyValuePair<string, ICommandRunner>[] EnumerateCommands => CommandsMap.ToArray();
protected abstract Dictionary<string, ICommandRunner> CommandsMap { get; set; }
public bool TryAddCommand(ICommandRunner command)
{
if (CommandsMap.ContainsKey(command.CommandName))
{
return false;
}
CommandsMap[command.CommandName] = command;
return true;
}
public virtual void OnCommandNotFound(string commandName)
{
throw new CommandFailedException(commandName, GetType(), "Command not Found in CommandsMap");
}
public virtual bool ParseAndRunCommand(string input)
{
string[] array = input.SplitOutsideQuotes(' ');
if (array.Length == 0)
{
return false;
}
string commandName = array[0];
string[] subArray = array[1..];
return RunCommand(commandName, subArray);
}
public virtual bool RunCommand(string commandName, string[] args)
{
if (!CommandsMap.TryGetValue(commandName, out ICommandRunner value))
{
OnCommandNotFound(commandName);
return false;
}
return value.Execute(args);
}
}
public class CommandFailedException : Exception
{
public readonly string CommandName;
public readonly string Sender;
public CommandFailedException(string commandName, Type sender, string? message = null)
{
CommandName = commandName;
Sender = sender.Name;
base..ctor(message);
}
}
public interface ICommandRunner
{
string CommandName { get; }
string CommandUsage { get; }
bool Execute(string[] args);
}
}
namespace SimpleCommandLib.Extensions
{
internal static class SplitStringExtension
{
public static string[] SplitOutsideQuotes(this string source, char separator, bool trimSplits = true, bool ignoreEmptyResults = true, bool preserveEscapeCharInQuotes = true)
{
return source.SplitOutsideQuotes(new char[1] { separator }, trimSplits, ignoreEmptyResults, preserveEscapeCharInQuotes);
}
public static string[] SplitOutsideQuotes(this string source, char[] separators, bool trimSplits = true, bool ignoreEmptyResults = true, bool preserveEscapeCharInQuotes = true)
{
if (source == null)
{
return null;
}
List<string> list = new List<string>();
bool flag = false;
bool flag2 = false;
StringBuilder stringBuilder = new StringBuilder();
foreach (char c in source)
{
if (flag)
{
stringBuilder.Append(c);
flag = false;
continue;
}
if (separators.Contains(c) && !flag2)
{
string text = (trimSplits ? stringBuilder.ToString().Trim() : stringBuilder.ToString());
stringBuilder.Clear();
if (!(string.IsNullOrEmpty(text) && ignoreEmptyResults))
{
list.Add(text);
}
continue;
}
switch (c)
{
default:
stringBuilder.Append(c);
break;
case '\\':
if (flag2 && preserveEscapeCharInQuotes)
{
stringBuilder.Append(c);
}
flag = true;
break;
case '"':
stringBuilder.Append(c);
flag2 = !flag2;
break;
}
}
if (flag)
{
stringBuilder.Append("\\");
}
string text2 = (trimSplits ? stringBuilder.ToString().Trim() : stringBuilder.ToString());
if (!(string.IsNullOrEmpty(text2) && ignoreEmptyResults))
{
list.Add(text2);
}
return list.ToArray();
}
}
}