|
| 1 | +using System; |
| 2 | +using System.Runtime.InteropServices; |
| 3 | + |
| 4 | +namespace CLIHelper |
| 5 | +{ |
| 6 | + /// <summary> |
| 7 | + /// Specifies the type of value for the cli-argument. |
| 8 | + /// </summary> |
| 9 | + public enum CLIType |
| 10 | + { |
| 11 | + /// <summary> |
| 12 | + /// The argument needs a numerical value: <see langword="int"/>, <see langword="float"/>, or <see langword="double"/>. |
| 13 | + /// </summary> |
| 14 | + Number, |
| 15 | + |
| 16 | + /// <summary> |
| 17 | + /// The argument needs a string value. |
| 18 | + /// </summary> |
| 19 | + String |
| 20 | + } |
| 21 | + |
| 22 | + /// <summary> |
| 23 | + /// Specifies the type of character used to identify a switch argument. |
| 24 | + /// </summary> |
| 25 | + public enum SwitchType |
| 26 | + { |
| 27 | + /// <summary> |
| 28 | + /// There must be a hyphen (-) before the switch value. |
| 29 | + /// </summary> |
| 30 | + Hyphen, |
| 31 | + |
| 32 | + /// <summary> |
| 33 | + /// The must be a forward slash (/) before the switch value. |
| 34 | + /// </summary> |
| 35 | + Slash |
| 36 | + } |
| 37 | + |
| 38 | + /// <summary> |
| 39 | + /// Base attribute that represents the metadata for a command-line argument. |
| 40 | + /// </summary> |
| 41 | + public abstract class CLIAttribute : Attribute |
| 42 | + { |
| 43 | + /// <summary> |
| 44 | + /// The name of the argument, used to identify the argument's value in code. |
| 45 | + /// </summary> |
| 46 | + public readonly string Name; |
| 47 | + |
| 48 | + /// <summary> |
| 49 | + /// What the argument is for, or maybe how it's used. |
| 50 | + /// </summary> |
| 51 | + public readonly string Description; |
| 52 | + |
| 53 | + /// <summary> |
| 54 | + /// Creates a new <see cref="CLIAttribute"/>. |
| 55 | + /// </summary> |
| 56 | + /// <param name="Name">The name of the argument, used to identify the argument's value in code.</param> |
| 57 | + /// <param name="Order">Whether this is the first, second, third, etc, argument.</param> |
| 58 | + /// <param name="Description">What the argument is for, or maybe how it's used. |
| 59 | + /// <br/><br/>OPTIONAL: <i>Does not need to be provided.</i></param> |
| 60 | + public CLIAttribute(string Name, [Optional, DefaultParameterValue("")] string Description) |
| 61 | + { |
| 62 | + this.Name = Name; |
| 63 | + this.Description = Description; |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + /// <summary> |
| 68 | + /// Base attribute that represents the metadata for a required command-line argument. |
| 69 | + /// </summary> |
| 70 | + public abstract class RequiredCLIAttribute : CLIAttribute |
| 71 | + { |
| 72 | + /// <summary> |
| 73 | + /// Whether this is the first, second, third, etc, argument. |
| 74 | + /// </summary> |
| 75 | + public readonly int Order; |
| 76 | + |
| 77 | + /// <summary> |
| 78 | + /// Creates a new <see cref="RequiredCLIAttribute"/>. |
| 79 | + /// </summary> |
| 80 | + /// <param name="Name">The name of the argument, used to identify the argument's value in code.</param> |
| 81 | + /// <param name="Order">Whether this is the first, second, third, etc, argument.</param> |
| 82 | + /// <param name="Description">What the argument is for, or maybe how it's used. |
| 83 | + /// <br/><br/>OPTIONAL: <i>Does not need to be provided.</i></param> |
| 84 | + public RequiredCLIAttribute(string Name, int Order, [Optional, DefaultParameterValue("")] string Description) |
| 85 | + : base(Name, Description) => this.Order = Order; |
| 86 | + } |
| 87 | + |
| 88 | + /// <summary> |
| 89 | + /// Base attribute that represents the metadata for an optional command-line argument. |
| 90 | + /// </summary> |
| 91 | + public abstract class OptionalCLIAttribute : CLIAttribute |
| 92 | + { |
| 93 | + /// <summary> |
| 94 | + /// Creates a new <see cref="OptionalCLIAttribute"/>. |
| 95 | + /// </summary> |
| 96 | + /// <param name="Name">The name of the argument, used to identify the argument's value in code.</param> |
| 97 | + /// <param name="Description">What the argument is for, or maybe how it's used. |
| 98 | + /// <br/><br/>OPTIONAL: <i>Does not need to be provided.</i></param> |
| 99 | + public OptionalCLIAttribute(string Name, [Optional, DefaultParameterValue("")] string Description) |
| 100 | + : base(Name, Description) { } |
| 101 | + } |
| 102 | + |
| 103 | + /// <summary> |
| 104 | + /// Represents a command-line argument with a raw value, type specified by <see cref="CLIType"/>. |
| 105 | + /// </summary> |
| 106 | + [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] |
| 107 | + public sealed class ArgumentAttribute : RequiredCLIAttribute |
| 108 | + { |
| 109 | + /// <summary> |
| 110 | + /// The type of value this argument should contain. |
| 111 | + /// </summary> |
| 112 | + public readonly CLIType Type; |
| 113 | + |
| 114 | + /// <summary> |
| 115 | + /// Creates a new <see cref="ArgumentAttribute"/>. |
| 116 | + /// </summary> |
| 117 | + /// <param name="Name">The general name of the argument, used to identify the argument's value in code.</param> |
| 118 | + /// <param name="Type">The type of value this argument should contain.</param> |
| 119 | + /// <param name="Order">Whether this is the first, second, third, etc, argument.</param> |
| 120 | + /// <param name="Description">What the argument is for, or maybe how it's used. |
| 121 | + /// <br/><br/>OPTIONAL: <i>Does not need to be provided.</i></param> |
| 122 | + public ArgumentAttribute(string Name, CLIType Type, int Order, [Optional, DefaultParameterValue("")] string Description) |
| 123 | + : base(Name, Order, Description) => this.Type = Type; |
| 124 | + } |
| 125 | + |
| 126 | + /// <summary> |
| 127 | + /// Represents a command-line argument with specifically accepted values. |
| 128 | + /// </summary> |
| 129 | + [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] |
| 130 | + public sealed class SwitchAttribute : RequiredCLIAttribute |
| 131 | + { |
| 132 | + /// <summary> |
| 133 | + /// The enum used to identify accepted values. |
| 134 | + /// </summary> |
| 135 | + public readonly Type Enum; |
| 136 | + |
| 137 | + /// <summary> |
| 138 | + /// The character used to identify the switch argument. |
| 139 | + /// </summary> |
| 140 | + public readonly SwitchType Identifier; |
| 141 | + |
| 142 | + /// <summary> |
| 143 | + /// Creates a new <see cref="SwitchAttribute"/>. |
| 144 | + /// </summary> |
| 145 | + /// <param name="Name">The general name of the argument, used to identify the argument's value in code.</param> |
| 146 | + /// <param name="Enum">The enum type used to identify the accepted values.</param> |
| 147 | + /// <param name="Identifier">The character used to identify the switch argument.</param> |
| 148 | + /// <param name="Order">Whether this is the first, second, third, etc, argument.</param> |
| 149 | + /// <param name="Description">What the argument is for, or maybe how it's used. |
| 150 | + /// <br/><br/>OPTIONAL: <i>Does not need to be provided.</i></param> |
| 151 | + public SwitchAttribute(string Name, Type Enum, SwitchType Identifier, int Order, [Optional, DefaultParameterValue("")] string Description) |
| 152 | + : base(Name, Order, Description) { this.Enum = Enum; this.Identifier = Identifier; } |
| 153 | + } |
| 154 | + |
| 155 | + /// <summary> |
| 156 | + /// Represents an <b>optional</b> command-line argument with a raw value, type specified by <see cref="CLIType"/>. |
| 157 | + /// </summary> |
| 158 | + [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] |
| 159 | + public sealed class OptionalArgumentAttribute : OptionalCLIAttribute |
| 160 | + { |
| 161 | + /// <summary> |
| 162 | + /// The type of value this argument should contain. |
| 163 | + /// </summary> |
| 164 | + public readonly CLIType Type; |
| 165 | + |
| 166 | + /// <summary> |
| 167 | + /// Creates a new <see cref="OptionalArgumentAttribute"/>. |
| 168 | + /// </summary> |
| 169 | + /// <param name="Name">The name of the argument, used to identify the argument's value in code.</param> |
| 170 | + /// <param name="Type">The type of value this argument should contain.</param> |
| 171 | + /// <param name="Description">What the argument is for, or maybe how it's used. |
| 172 | + /// <br/><br/>OPTIONAL: <i>Does not need to be provided.</i></param> |
| 173 | + public OptionalArgumentAttribute(string Name, CLIType Type, [Optional, DefaultParameterValue("")] string Description) |
| 174 | + : base(Name, Description) => this.Type = Type; |
| 175 | + } |
| 176 | + |
| 177 | + /// <summary> |
| 178 | + /// Represents an <b>optional</b> command-line argument with specifically accepted values. |
| 179 | + /// </summary> |
| 180 | + [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] |
| 181 | + public sealed class OptionalSwitchAttribute : OptionalCLIAttribute |
| 182 | + { |
| 183 | + /// <summary> |
| 184 | + /// The enum used to identify accepted values. |
| 185 | + /// </summary> |
| 186 | + public readonly Type Enum; |
| 187 | + |
| 188 | + /// <summary> |
| 189 | + /// The character used to identify the switch argument. |
| 190 | + /// </summary> |
| 191 | + public readonly SwitchType Identifier; |
| 192 | + |
| 193 | + /// <summary> |
| 194 | + /// Creates a new <see cref="OptionalSwitchAttribute"/>. |
| 195 | + /// </summary> |
| 196 | + /// <param name="Name">The name of the argument, used to identify the argument's value in code.</param> |
| 197 | + /// <param name="Enum">The enum type used to identify the accepted values.</param> |
| 198 | + /// <param name="Identifier">The character used to identify the switch argument.</param> |
| 199 | + /// <param name="Description">What the argument is for, or maybe how it's used. |
| 200 | + /// <br/><br/>OPTIONAL: <i>Does not need to be provided.</i></param> |
| 201 | + public OptionalSwitchAttribute(string Name, Type Enum, SwitchType Identifier, [Optional, DefaultParameterValue("")] string Description) |
| 202 | + : base(Name, Description) { this.Enum = Enum; this.Identifier = Identifier; } |
| 203 | + } |
| 204 | +} |
0 commit comments