Skip to content

Commit 6e4b782

Browse files
Add project files.
1 parent 7fe434f commit 6e4b782

File tree

9 files changed

+639
-0
lines changed

9 files changed

+639
-0
lines changed

CLIConsole/App.config

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
5+
</startup>
6+
</configuration>

CLIConsole/CLIConsole.csproj

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{C2D56CA2-0A2F-45D2-B2E2-076AC696CCEE}</ProjectGuid>
8+
<OutputType>Exe</OutputType>
9+
<RootNamespace>CLIConsole</RootNamespace>
10+
<AssemblyName>CLIConsole</AssemblyName>
11+
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
12+
<FileAlignment>512</FileAlignment>
13+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
14+
<Deterministic>true</Deterministic>
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17+
<PlatformTarget>AnyCPU</PlatformTarget>
18+
<DebugSymbols>true</DebugSymbols>
19+
<DebugType>full</DebugType>
20+
<Optimize>false</Optimize>
21+
<OutputPath>bin\Debug\</OutputPath>
22+
<DefineConstants>DEBUG;TRACE</DefineConstants>
23+
<ErrorReport>prompt</ErrorReport>
24+
<WarningLevel>4</WarningLevel>
25+
</PropertyGroup>
26+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
27+
<PlatformTarget>AnyCPU</PlatformTarget>
28+
<DebugType>pdbonly</DebugType>
29+
<Optimize>true</Optimize>
30+
<OutputPath>bin\Release\</OutputPath>
31+
<DefineConstants>TRACE</DefineConstants>
32+
<ErrorReport>prompt</ErrorReport>
33+
<WarningLevel>4</WarningLevel>
34+
</PropertyGroup>
35+
<ItemGroup>
36+
<Reference Include="System" />
37+
</ItemGroup>
38+
<ItemGroup>
39+
<Compile Include="Program.cs" />
40+
<Compile Include="Properties\AssemblyInfo.cs" />
41+
</ItemGroup>
42+
<ItemGroup>
43+
<None Include="App.config" />
44+
</ItemGroup>
45+
<ItemGroup>
46+
<ProjectReference Include="..\CLIHelper\CLIHelper.csproj">
47+
<Project>{6db941b7-44ec-44d5-b236-6ef563b46e27}</Project>
48+
<Name>CLIHelper</Name>
49+
</ProjectReference>
50+
</ItemGroup>
51+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
52+
</Project>

CLIConsole/Program.cs

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
using CLIHelper;
5+
6+
namespace CLIConsole
7+
{
8+
internal class Program
9+
{
10+
private enum MyType
11+
{ bt, xv }
12+
13+
[Switch("arg1", typeof(MyType), SwitchType.Hyphen, 1)]
14+
static void Main()
15+
{
16+
Console.Title = "CLIHelper Debug Console";
17+
18+
try
19+
{
20+
Dictionary<string, CLI.Value> args = CLI.GetArguments();
21+
22+
if (args != null) Console.WriteLine(string.Join(", ", args));
23+
}
24+
catch (Exception ex) { Console.WriteLine("{0}: {1}", ex.GetType(), ex.Message); }
25+
26+
Console.ReadKey();
27+
}
28+
}
29+
}

CLIConsole/Properties/AssemblyInfo.cs

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("CLIConsole")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("CLIConsole")]
13+
[assembly: AssemblyCopyright("Copyright © 2024")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("c2d56ca2-0a2f-45d2-b2e2-076ac696ccee")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]

CLIHelper.sln

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.9.34723.18
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CLIHelper", "CLIHelper\CLIHelper.csproj", "{6DB941B7-44EC-44D5-B236-6EF563B46E27}"
7+
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CLIConsole", "CLIConsole\CLIConsole.csproj", "{C2D56CA2-0A2F-45D2-B2E2-076AC696CCEE}"
9+
EndProject
10+
Global
11+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
12+
Debug|Any CPU = Debug|Any CPU
13+
Release|Any CPU = Release|Any CPU
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{6DB941B7-44EC-44D5-B236-6EF563B46E27}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17+
{6DB941B7-44EC-44D5-B236-6EF563B46E27}.Debug|Any CPU.Build.0 = Debug|Any CPU
18+
{6DB941B7-44EC-44D5-B236-6EF563B46E27}.Release|Any CPU.ActiveCfg = Release|Any CPU
19+
{6DB941B7-44EC-44D5-B236-6EF563B46E27}.Release|Any CPU.Build.0 = Release|Any CPU
20+
{C2D56CA2-0A2F-45D2-B2E2-076AC696CCEE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{C2D56CA2-0A2F-45D2-B2E2-076AC696CCEE}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{C2D56CA2-0A2F-45D2-B2E2-076AC696CCEE}.Release|Any CPU.ActiveCfg = Release|Any CPU
23+
{C2D56CA2-0A2F-45D2-B2E2-076AC696CCEE}.Release|Any CPU.Build.0 = Release|Any CPU
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
GlobalSection(ExtensibilityGlobals) = postSolution
29+
SolutionGuid = {798F953A-5C5C-415A-85E8-A135ED76C18E}
30+
EndGlobalSection
31+
EndGlobal

CLIHelper/Attributes.cs

+204
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
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

Comments
 (0)