English | 中文
Welcome to Antelcat.Parameterization, a powerful source generator designed to revolutionize the way you create command-line applications. This tool simplifies the process of building CLI applications by automatically generating parsing methods with just attribute marking on classes and methods.
- Attribute-Driven Development: Easily define commands and arguments using attributes.
- Automatic Parsing: Automatically generates methods for parsing command-line arguments.
- Custom Type Converter: Works well with
System.ComponentModel.StringConverter.
The Demo Program implements a simple Docker application to show its features.
-
Pull an Image:
Command:
> pull ubuntuOutput:
Pulling image ubuntu:latest... Successfully Pulled image ubuntu:latest
In this example, a custom
Imageclass is seamlessly converted from astring, thanks to the[TypeConverter(typeof(ImageConverter))]attribute applied toImage. Additionally, for locally use, the[Argument(Converter = typeof(ImageConverter))] Image imageannotation allows the same seamless conversion. -
Run a Container:
Command:
> run ubuntuOutput:
ubuntu:latest ubuntu running
This demonstrates how the default value for the
nameparameter is automatically used when it's not provided in the input. -
Display Container Statistics:
Command:
> psOutput:
CONTAINER_ID IMAGE NAME STATUS 00a57dbe ubuntu:latest ubuntu running
-
Stop a Container and Run a New One:
Commands:
> stop > stop 00a57dbe > run --name "my container" --image kali
Output:
Argument "id" is not specified. Stopping container 00a57dbe... Pulling image kali:latest... Successfully Pulled image kali:latest kali:latest my container runningThis example highlights the use of named switches, allowing argument reordering. Additionally, it showcases how strings enclosed in
""are correctly parsed. -
Display Updated Container Statistics:
Command:
> ps --allOutput:
CONTAINER_ID IMAGE NAME STATUS 00a57dbe ubuntu:latest ubuntu stopped 0419fcea kali:latest my container running
First,
Argument(FullName = "all")replaces the full name of the originalshowAll.Argument(ShortName = "a")meansps -aalso works as same.Second, the effect of
ArgumentAttribute.DefaultValueis evident. When a switch is used without an accompanying value, theArgumentAttribute.DefaultValueis automatically converted and used to fill the argument, regardless of the default parameter value ofbool showAll = false.
-
Via Nuget (✨Recommanded)
Uploaded to Nuget. You can install via nuget CLI or your favorite IDE.
-
Via source code
-
Clone or download zip of the source code.
-
Reference
Antelcat.ParameterizationandAntelcat.Parameterization.SourceGeneratorsas follows.<ItemGroup> <ProjectReference Include="..\Antelcat.Parameterization\Antelcat.Parameterization.csproj"/> <ProjectReference Include="..\Antelcat.Parameterization.SourceGenerators\Antelcat.Parameterization.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false"/> </ItemGroup>
NOTICE that
OutputItemType="Analyzer" ReferenceOutputAssembly="false"is necessary because it is a Source Generator. -
Enjoy.
-
We welcome contributions to this project! Whether it's reporting bugs, suggesting enhancements, or adding new features, your input is valuable to us.
- Nuget package.
- Multiple parameters, use
T[]. - Automatically generate help documents.
- Check for excess parameters.
- Parameter combination, e.g.
-itwill both open-iand-t.