Skip to content

Commit 26a8cea

Browse files
committed
Feat: Update Readme
1 parent cee668b commit 26a8cea

23 files changed

+111
-153
lines changed

.editorconfig

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ indent_size = 4
99
# Microsoft .NET properties
1010
csharp_new_line_before_members_in_object_initializers = false
1111
csharp_new_line_before_open_brace = none
12-
csharp_preferred_modifier_order = internal, protected, public, sealed, file, new, private, override, static, required, readonly, abstract, extern, unsafe, volatile, async, virtual:suggestion
12+
csharp_preferred_modifier_order = public, internal, protected, private, async, virtual, file, new, sealed, override, required, abstract, extern, static, volatile, unsafe, readonly:suggestion
1313
csharp_style_prefer_utf8_string_literals = true:suggestion
1414
csharp_style_var_elsewhere = false:none
1515
csharp_style_var_for_built_in_types = false:suggestion
@@ -25,6 +25,12 @@ dotnet_naming_rule.private_instance_fields_rule.resharper_guid = 4a98fdf6-7d98-4
2525
dotnet_naming_rule.private_instance_fields_rule.severity = warning
2626
dotnet_naming_rule.private_instance_fields_rule.style = lower_camel_case_style
2727
dotnet_naming_rule.private_instance_fields_rule.symbols = private_instance_fields_symbols
28+
dotnet_naming_rule.private_instance_fields_rule_1.import_to_resharper = True
29+
dotnet_naming_rule.private_instance_fields_rule_1.resharper_description = Instance fields (private)
30+
dotnet_naming_rule.private_instance_fields_rule_1.resharper_guid = 4a98fdf6-7d98-4f5a-afeb-ea44ad98c70c
31+
dotnet_naming_rule.private_instance_fields_rule_1.severity = warning
32+
dotnet_naming_rule.private_instance_fields_rule_1.style = lower_camel_case_style
33+
dotnet_naming_rule.private_instance_fields_rule_1.symbols = private_instance_fields_symbols_1
2834
dotnet_naming_rule.private_static_fields_rule.import_to_resharper = True
2935
dotnet_naming_rule.private_static_fields_rule.resharper_description = Static fields (private)
3036
dotnet_naming_rule.private_static_fields_rule.resharper_exclusive_prefixes_suffixes = true
@@ -44,6 +50,12 @@ dotnet_naming_rule.unity_serialized_field_rule.resharper_guid = 5f0fdb63-c892-4d
4450
dotnet_naming_rule.unity_serialized_field_rule.severity = warning
4551
dotnet_naming_rule.unity_serialized_field_rule.style = lower_camel_case_style_1
4652
dotnet_naming_rule.unity_serialized_field_rule.symbols = unity_serialized_field_symbols
53+
dotnet_naming_rule.unity_serialized_field_rule_1.import_to_resharper = True
54+
dotnet_naming_rule.unity_serialized_field_rule_1.resharper_description = Unity serialized field
55+
dotnet_naming_rule.unity_serialized_field_rule_1.resharper_guid = 5f0fdb63-c892-4d2c-9324-15c80b22a7ef
56+
dotnet_naming_rule.unity_serialized_field_rule_1.severity = warning
57+
dotnet_naming_rule.unity_serialized_field_rule_1.style = lower_camel_case_style_1
58+
dotnet_naming_rule.unity_serialized_field_rule_1.symbols = unity_serialized_field_symbols_1
4759
dotnet_naming_style.lower_camel_case_style.capitalization = camel_case
4860
dotnet_naming_style.lower_camel_case_style.required_prefix = _
4961
dotnet_naming_style.lower_camel_case_style_1.capitalization = camel_case
@@ -57,6 +69,10 @@ dotnet_naming_symbols.private_instance_fields_symbols.applicable_accessibilities
5769
dotnet_naming_symbols.private_instance_fields_symbols.applicable_kinds = field
5870
dotnet_naming_symbols.private_instance_fields_symbols.resharper_applicable_kinds = field, readonly_field
5971
dotnet_naming_symbols.private_instance_fields_symbols.resharper_required_modifiers = instance
72+
dotnet_naming_symbols.private_instance_fields_symbols_1.applicable_accessibilities = private
73+
dotnet_naming_symbols.private_instance_fields_symbols_1.applicable_kinds = field
74+
dotnet_naming_symbols.private_instance_fields_symbols_1.resharper_applicable_kinds = field,readonly_field
75+
dotnet_naming_symbols.private_instance_fields_symbols_1.resharper_required_modifiers = instance
6076
dotnet_naming_symbols.private_static_fields_symbols.applicable_accessibilities = private
6177
dotnet_naming_symbols.private_static_fields_symbols.applicable_kinds = field
6278
dotnet_naming_symbols.private_static_fields_symbols.required_modifiers = static
@@ -68,9 +84,13 @@ dotnet_naming_symbols.private_static_readonly_symbols.required_modifiers = reado
6884
dotnet_naming_symbols.private_static_readonly_symbols.resharper_applicable_kinds = readonly_field
6985
dotnet_naming_symbols.private_static_readonly_symbols.resharper_required_modifiers = static
7086
dotnet_naming_symbols.unity_serialized_field_symbols.applicable_accessibilities = *
71-
dotnet_naming_symbols.unity_serialized_field_symbols.applicable_kinds =
87+
dotnet_naming_symbols.unity_serialized_field_symbols.applicable_kinds =
7288
dotnet_naming_symbols.unity_serialized_field_symbols.resharper_applicable_kinds = unity_serialised_field
7389
dotnet_naming_symbols.unity_serialized_field_symbols.resharper_required_modifiers = instance
90+
dotnet_naming_symbols.unity_serialized_field_symbols_1.applicable_accessibilities = *
91+
dotnet_naming_symbols.unity_serialized_field_symbols_1.applicable_kinds =
92+
dotnet_naming_symbols.unity_serialized_field_symbols_1.resharper_applicable_kinds = unity_serialised_field
93+
dotnet_naming_symbols.unity_serialized_field_symbols_1.resharper_required_modifiers = instance
7494
dotnet_sort_system_directives_first = false
7595
dotnet_style_parentheses_in_arithmetic_binary_operators = never_if_unnecessary:none
7696
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:none
@@ -89,56 +109,61 @@ resharper_align_multiline_statement_conditions = false
89109
resharper_arguments_anonymous_function = named
90110
resharper_arguments_skip_single = true
91111
resharper_autodetect_indent_settings = true
92-
resharper_blank_lines_after_block_statements = 0
93112
resharper_blank_lines_after_control_transfer_statements = 1
94113
resharper_blank_lines_after_file_scoped_namespace_directive = 0
95114
resharper_blank_lines_after_start_comment = 0
115+
resharper_blank_lines_around_auto_property = 0
96116
resharper_blank_lines_around_block_case_section = 1
97117
resharper_blank_lines_around_property = 0
118+
resharper_braces_for_for = required
98119
resharper_braces_for_foreach = required_for_multiline_statement
99-
resharper_braces_for_ifelse = required_for_multiline_statement
120+
resharper_braces_for_ifelse = not_required
121+
resharper_braces_for_while = required_for_multiline
100122
resharper_braces_redundant = false
123+
resharper_cpp_insert_final_newline = true
124+
resharper_csharp_blank_lines_around_field = 0
125+
resharper_csharp_blank_lines_around_invocable = 0
101126
resharper_csharp_blank_lines_around_region = 0
102127
resharper_csharp_blank_lines_inside_region = 0
103-
resharper_csharp_empty_block_style = together
104128
resharper_csharp_insert_final_newline = true
105-
resharper_csharp_max_line_length = 1445
129+
resharper_csharp_keep_blank_lines_in_declarations = 100
130+
resharper_csharp_max_line_length = 505
106131
resharper_csharp_remove_blank_lines_near_braces_in_code = false
107132
resharper_csharp_remove_blank_lines_near_braces_in_declarations = false
108133
resharper_csharp_space_around_alias_eq = false
134+
resharper_csharp_space_before_trailing_comment = false
109135
resharper_csharp_stick_comment = false
110-
resharper_csharp_wrap_arguments_style = chop_if_long
136+
resharper_csharp_wrap_after_declaration_lpar = true
111137
resharper_csharp_wrap_before_binary_opsign = true
138+
resharper_csharp_wrap_before_declaration_rpar = true
112139
resharper_csharp_wrap_extends_list_style = chop_if_long
113140
resharper_formatter_off_tag = @formatter:off
114141
resharper_formatter_on_tag = @formatter:on
115142
resharper_formatter_tags_enabled = true
116-
resharper_indent_inside_namespace = false
117-
resharper_indent_pars = outside_and_inside
118143
resharper_indent_preprocessor_if = usual_indent
119144
resharper_indent_preprocessor_other = do_not_change
120145
resharper_indent_raw_literal_string = indent
121-
resharper_instance_members_qualify_declared_in =
146+
resharper_instance_members_qualify_declared_in =
122147
resharper_keep_existing_attribute_arrangement = true
123148
resharper_keep_existing_declaration_block_arrangement = true
124149
resharper_keep_existing_embedded_block_arrangement = true
125150
resharper_max_attribute_length_for_same_line = 70
126151
resharper_method_or_operator_body = expression_body
127152
resharper_parentheses_redundancy_style = remove
128-
resharper_place_accessorholder_attribute_on_same_line = true
129-
resharper_place_accessor_attribute_on_same_line = true
153+
resharper_place_accessorholder_attribute_on_same_line = false
130154
resharper_place_expr_accessor_on_single_line = true
131155
resharper_place_expr_property_on_single_line = true
132-
resharper_place_record_field_attribute_on_same_line = true
133156
resharper_place_simple_accessor_on_single_line = false
134157
resharper_place_simple_anonymousmethod_on_single_line = false
158+
resharper_place_simple_case_statement_on_same_line = true
135159
resharper_place_simple_embedded_statement_on_same_line = true
136160
resharper_place_simple_initializer_on_single_line = false
161+
resharper_place_simple_list_pattern_on_single_line = false
162+
resharper_place_type_attribute_on_same_line = if_owner_is_single_line
137163
resharper_qualified_using_at_nested_scope = true
138164
resharper_space_within_empty_braces = false
165+
resharper_treat_case_statement_with_break_as_simple = false
139166
resharper_use_indent_from_vs = false
140-
resharper_wrap_before_primary_constructor_declaration_rpar = true
141-
resharper_wrap_chained_binary_expressions = chop_if_long
142167
resharper_wrap_list_pattern = chop_always
143168
resharper_wrap_object_and_collection_initializer_style = chop_always
144169

@@ -149,6 +174,7 @@ resharper_arrange_type_member_modifiers_highlighting = hint
149174
resharper_arrange_type_modifiers_highlighting = hint
150175
resharper_built_in_type_reference_style_for_member_access_highlighting = hint
151176
resharper_built_in_type_reference_style_highlighting = hint
177+
resharper_html_path_error_highlighting = none
152178
resharper_mvc_action_not_resolved_highlighting = warning
153179
resharper_mvc_area_not_resolved_highlighting = warning
154180
resharper_mvc_controller_not_resolved_highlighting = warning

README.md

Lines changed: 57 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -1,133 +1,81 @@
1-
# CliArgsParser
1+
# CodeOfChaos.CliArgsParser
22

3-
![NuGet Downloads](https://img.shields.io/nuget/dt/CliArgsParser)
4-
![NuGet Version](https://img.shields.io/nuget/v/CliArgsParser?link=https%3A%2F%2Fwww.nuget.org%2Fpackages%2FCliArgsParser)
3+
## Overview
4+
CodeOfChaos.CliArgsParser is a library designed to simplify the process of creating command-line applications in .NET projects. It provides developers with attributes, structures, and tools to quickly define, parse, and execute CLI commands with minimal boilerplate code. The library is focused on flexibility, clarity, and ease of use, utilizing C#'s powerful features like attributes and partial classes.
55

6-
CliArgsParser is a library built around Dependency Injection to allow you to create Cli tools with ease.
7-
This is particularly useful in scenarios where your application requires a large amount of commands,
8-
with specific arguments.
9-
10-
```shell
11-
dotnet add package CliArgsParser --version 2.2.7
12-
```
6+
---
137

148
## Features
9+
- **Easy Command Definition**: Define commands using attributes like `[CliArgsCommand]` and `[CliArgsParameter]` directly in your application.
10+
- **Automatic Parsing**: Command-line arguments are parsed and mapped to parameters automatically.
11+
- **Description Metadata**: Add meaningful descriptions to commands and parameters using `[CliArgsDescription]` for better documentation.
12+
- **Support for Flags and Complex Types**: Easily handle flags, strings, arrays, and even optional/default values.
13+
- **Asynchronous Execution**: Built-in support for asynchronous methods to handle complex operations.
1514

16-
Here are the key features of Cli Args Parser:
17-
18-
- **Command Declaration and Registration**: Commands are declaratively defined within a class using the `ICommandAtlas`
19-
interface.
20-
This arrangement provides a well-structured, easy-to-maintain way of defining and locating command handling logic.
21-
- **Asynchronous Command Execution**: CliArgsParser allows for asynchronous execution of commands.
22-
This can provide major performance benefits, especially when commands involve IO-bound operations.
23-
The library also exposes the `ArgsParser.ParseAsyncParallel` method for parallel async execution of cli tools.
24-
- **Argument Mapping**: CliArgsParser allows property-based argument mapping.
25-
Properties of a class implementing the ICommandParameters interface can be used as the target of argument mapping from
26-
command line input.
27-
Argument mapping is further simplified through the use of the `ArgValue` and `ArgFlag` attributes which takes the
28-
argument name as a parameter.
29-
- **Dependency Injection approach**: The library is built around using DI in your workflow. `ICommandAtlas` classes
30-
allow constructors to fully utilize dependency injection.
31-
Yet you are not required to have a `IServiceCollection`, by using the `CliParser.CreateStandalone()` or
32-
`ArgsParser.CreateStandalone()` methods.
15+
---
3316

34-
## F.A.Q:
17+
## Getting Started
18+
To use CodeOfChaos.CliArgsParser in your project, follow these steps:
3519

36-
> **"I tried to create a atlas with async commands, but they did not execute when called"**
37-
>
38-
> This is due to the parser trying to execute the commands as non-async, because the parser was most likely called
39-
> without using the async methods.
40-
> To resolve this, always run the parsers through their async methods.
41-
42-
## Quick Start
43-
44-
The following section is a basic example on how to get started with CliArgsParser.
45-
For in-code examples, they can be found in the repo under
46-
examples : https://github.com/code-of-chaos/CliArgsParser-cs/tree/core/examples
20+
### 1. Install the Library
21+
Add the library to your project via NuGet:
22+
```bash
23+
dotnet add package CodeOfChaos.CliArgsParser
24+
```
4725

48-
### Dependency Injected approach
26+
---
4927

28+
### 2. Define a Command
29+
Commands are defined as partial classes and annotated with metadata. For example:
5030
```csharp
51-
using CliArgsParser;
52-
53-
// Define a class for mapping arguments
54-
public class ArgsTest : ICommandParameters {
55-
[ArgValue("name"), Description("Defines the name of the user")]
56-
public string Name { get; set; } = "Default Name";
57-
}
58-
59-
public class MyAppCommands : ICommandAtlas {
60-
[Command("hello"), Description("Greets everyone")]
61-
public void CommandHello() {
62-
Console.Writeline("Hello there!");
63-
/* Or your command' implementation, without arguments, goes here... */
64-
}
65-
66-
[Command<ArgsTest>("greet"), Description("Greets you specificly")]
67-
public void CommandGreet(ArgsTest argsTest) {
68-
Console.Writeline($"Hello there and welcome, {argsTest.Name}");
69-
/* Or Your command implementation goes here... */
70-
}
71-
}
72-
73-
internal static class Program {
74-
public async static Task Main(string[] args) {
75-
IServiceCollection serviceCollection = new ServiceCollection();
76-
77-
serviceCollection.AddCliArgsParser(configuration =>
78-
configuration
79-
.SetConfig(new CliArgsParserConfig {
80-
Overridable = true,
81-
GenerateShortNames = true
82-
})
83-
.AddFromType<HelloAtlas>()
84-
);
31+
[CliArgsCommand("example")]
32+
[CliArgsDescription("This is a test command")]
33+
public partial class ExampleCommand : ICommand<ExampleCommandParameters> {
34+
public async Task ExecuteAsync(ExampleCommandParameters parameters) {
35+
Console.WriteLine($"Running example command with TestValue: {parameters.TestValue}");
8536

86-
ServiceProvider provider = serviceCollection.BuildServiceProvider();
37+
if (parameters.Verbose) {
38+
Console.WriteLine("Verbose mode enabled.");
39+
}
8740

88-
var cliParser = provider.GetRequiredService<ICliParser>();
89-
await cliParser.StartParsingAsync();
41+
await Task.Delay(100); // Simulating async work
9042
}
9143
}
9244
```
9345

94-
### Standalone Approach
46+
---
9547

48+
### 3. Define Parameters
49+
Parameters for a command are defined using partial structs with annotated attributes:
9650
```csharp
97-
using CliArgsParser;
98-
99-
// Define a class for mapping arguments
100-
public class ArgsTest : ICommandParameters {
101-
[ArgValue("name"), Description("Defines the name of the user")]
102-
public string Name { get; set; } = "Default Name";
51+
public readonly partial struct ExampleCommandParameters : IParameters
52+
{
53+
[CliArgsParameter("test", "t")]
54+
[CliArgsDescription("A required test parameter")]
55+
public required string TestValue { get; init; }
56+
57+
[CliArgsParameter("verbose", "v", ParameterType.Flag)]
58+
[CliArgsDescription("Enable verbose logging")]
59+
public bool Verbose { get; init; }
60+
61+
[CliArgsParameter("optional-parameter", "o")]
62+
[CliArgsDescription("An optional parameter")]
63+
public string? OptionalValue { get; init; } = "default";
10364
}
65+
```
10466

105-
public class MyAppCommands : ICommandAtlas {
106-
[Command("hello"), Description("Greets everyone")]
107-
public void CommandHello() {
108-
Console.Writeline("Hello there!");
109-
/* Or your command' implementation, without arguments, goes here... */
110-
}
67+
---
11168

112-
[Command<ArgsTest>("greet"), Description("Greets you specificly")]
113-
public void CommandGreet(ArgsTest argsTest) {
114-
Console.Writeline($"Hello there and welcome, {argsTest.Name}");
115-
/* Or Your command implementation goes here... */
116-
}
117-
}
69+
### 4. Register and Run Commands
70+
Typically, this is performed in your `Program.cs` or entry point:
71+
```csharp
72+
using CodeOfChaos.CliArgsParser;
11873

119-
internal static class Program {
120-
public async static Task Main(string[] args) {
121-
ICliParser parser = CliParser.CreateStandalone(
122-
configuration =>
123-
configuration
124-
.SetConfig(new CliArgsParserConfig {
125-
Overridable = true,
126-
GenerateShortNames = true
127-
})
128-
.AddFromType<HelloAtlas>()
129-
);
130-
await cliParser.StartParsingAsync();
74+
CliArgsParser parser = CliArgsBuilder.CreateFromConfig(
75+
config => {
76+
config.AddCommand<ExampleCommand>();
13177
}
132-
}
78+
).Build();
79+
80+
await parser.ParseAsync(args);
13381
```

src/CodeOfChaos.CliArgsParser.Generators.Sample/Example.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// ---------------------------------------------------------------------------------------------------------------------
22
// Imports
33
// ---------------------------------------------------------------------------------------------------------------------
4-
using CodeOfChaos.CliArgsParser.Attributes;
5-
using CodeOfChaos.CliArgsParser.Contracts;
64
using System;
75
using System.Threading.Tasks;
86

src/CodeOfChaos.CliArgsParser.Library/CommandAtlases/DownloadIcon/DownloadIconCommand.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// Imports
33
// ---------------------------------------------------------------------------------------------------------------------
44
using AterraEngine.Unions;
5-
using CodeOfChaos.CliArgsParser.Attributes;
6-
using CodeOfChaos.CliArgsParser.Contracts;
75
using CodeOfChaos.CliArgsParser.Library.Shared;
86
using System.Text.RegularExpressions;
97
using System.Xml.Linq;

src/CodeOfChaos.CliArgsParser.Library/CommandAtlases/DownloadIcon/DownloadIconParameters.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
// ---------------------------------------------------------------------------------------------------------------------
22
// Imports
33
// ---------------------------------------------------------------------------------------------------------------------
4-
using CodeOfChaos.CliArgsParser.Attributes;
5-
using CodeOfChaos.CliArgsParser.Contracts;
6-
74
namespace CodeOfChaos.CliArgsParser.Library.CommandAtlases.DownloadIcon;
85
// ---------------------------------------------------------------------------------------------------------------------
96
// Code

src/CodeOfChaos.CliArgsParser.Library/CommandAtlases/VersionBump/VersionBumpCommand.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// Imports
33
// ---------------------------------------------------------------------------------------------------------------------
44
using AterraEngine.Unions;
5-
using CodeOfChaos.CliArgsParser.Attributes;
6-
using CodeOfChaos.CliArgsParser.Contracts;
75
using CodeOfChaos.CliArgsParser.Library.Shared;
86
using System.Xml.Linq;
97

src/CodeOfChaos.CliArgsParser.Library/CommandAtlases/VersionBump/VersionBumpParameters.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
// ---------------------------------------------------------------------------------------------------------------------
22
// Imports
33
// ---------------------------------------------------------------------------------------------------------------------
4-
using CodeOfChaos.CliArgsParser.Attributes;
5-
using CodeOfChaos.CliArgsParser.Contracts;
6-
74
namespace CodeOfChaos.CliArgsParser.Library.CommandAtlases.VersionBump;
85
// ---------------------------------------------------------------------------------------------------------------------
96
// Code

0 commit comments

Comments
 (0)