Skip to content

Commit 8ea4463

Browse files
committed
AI 翻译英文文档,并将文档摘要放一部分到仓库根目录
1 parent 4eb3621 commit 8ea4463

File tree

4 files changed

+346
-52
lines changed

4 files changed

+346
-52
lines changed

README.md

Lines changed: 47 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2,102 +2,99 @@
22

33
![Build](https://github.com/dotnet-campus/dotnetCampus.CommandLine/workflows/.NET%20Build/badge.svg) ![NuGet Package](https://github.com/dotnet-campus/dotnetCampus.CommandLine/workflows/NuGet%20Publish/badge.svg) [![dotnetCampus.CommandLine](https://img.shields.io/nuget/v/dotnetCampus.CommandLine)](https://www.nuget.org/packages/dotnetCampus.CommandLine/) [![dotnetCampus.CommandLine.Source](https://img.shields.io/nuget/v/dotnetCampus.CommandLine.Source)](https://www.nuget.org/packages/dotnetCampus.CommandLine.Source/)
44

5-
[English][en]|[简体中文][zh-chs]|[繁體中文][zh-cht]
6-
-|-|-
5+
| [English][en] | [简体中文][zh-hans] | [繁體中文][zh-hant] |
6+
| ------------- | ------------------- | ------------------- |
77

8-
[en]: /README.md
9-
[zh-chs]: /docs/zh-chs/README.md
10-
[zh-cht]: /docs/zh-cht/README.md
8+
[en]: /docs/en/README.md
9+
[zh-hans]: /docs/zh-hans/README.md
10+
[zh-hant]: /docs/zh-hant/README.md
1111

12-
dotnetCampus.CommandLine is probably the fastest command line parser in all .NET open-source projects.
12+
dotnetCampus.CommandLine is a simple yet high-performance command line parsing library for .NET. Thanks to the power of source code generators, it provides efficient parsing capabilities with a developer-friendly experience.
1313

14-
Parsing a classical command line only takes 1091ns, thus 10 ticks.
14+
Parsing a typical command line takes only about 5000ns (0.005ms), making it one of the fastest command line parsers available in .NET.
1515

1616
## Get Started
1717

18-
For your program `Main` method, write this code below:
18+
For your program `Main` method, write this code:
1919

2020
```csharp
2121
class Program
2222
{
2323
static void Main(string[] args)
2424
{
25+
// Create a new instance of CommandLine type from command line arguments
2526
var commandLine = CommandLine.Parse(args);
26-
var options = commandLine.As<Options>(new OptionsParser());
2727

28-
// Then, use your Options instance here.
28+
// Parse the command line into an instance of Options type
29+
// The source generator will automatically handle the parsing for you
30+
var options = commandLine.As<Options>();
31+
32+
// Now use your options object to implement your functionality
2933
}
3034
}
3135
```
3236

33-
You need to define the `Options` class as followed below:
37+
Define a class that maps command line arguments:
3438

3539
```csharp
3640
class Options
3741
{
3842
[Value(0)]
39-
public string FilePath { get; }
40-
41-
[Option('s', "Silence")]
42-
public bool IsSilence { get; }
43+
public string FilePath { get; init; }
4344

44-
[Option('m', "Mode")]
45-
public string StartMode { get; }
45+
[Option('s', "silence")]
46+
public bool IsSilence { get; init; }
4647

47-
[Option("StartupSessions")]
48-
public IReadonlyList<string> StartupSessions { get; }
48+
[Option('m', "mode")]
49+
public string StartMode { get; init; }
4950

50-
public Options(
51-
string filePath,
52-
bool isSilence,
53-
string startMode,
54-
IReadonlyList<string> startupSessions)
55-
{
56-
FilePath = filePath;
57-
IsSilence = isSilence;
58-
StartMode = startMode;
59-
StartupSessions = startupSessions;
60-
}
51+
[Option("startup-sessions")]
52+
public IReadOnlyList<string> StartupSessions { get; init; } = [];
6153
}
6254
```
6355

64-
Then you can run your program by passing these kind of command line args:
56+
Then use different command line styles to populate instances of this type:
6557

66-
Windows style:
58+
### Windows PowerShell Style
6759

6860
```powershell
6961
> demo.exe "C:\Users\lvyi\Desktop\demo.txt" -s -Mode Edit -StartupSessions A B C
7062
```
7163

64+
### Windows CMD Style
65+
7266
```cmd
7367
> demo.exe "C:\Users\lvyi\Desktop\demo.txt" /s /Mode Edit /StartupSessions A B C
7468
```
7569

76-
Linux style:
70+
### Linux/GNU Style
7771

7872
```bash
7973
$ demo.exe "C:/Users/lvyi/Desktop/demo.txt" -s --mode Edit --startup-sessions A B C
8074
```
8175

82-
Notice that you cannot use different styles in a single command line.
83-
84-
For `bool`:
85-
86-
- You can pass `true` / `True` / `false` / `False` to specify a boolean value;
87-
- You can pass nothing but only a switch.
88-
89-
It means that `-s true`, `-s True`, `-s` are the same.
90-
91-
For `ValueAttribute` and `OptionAttribute`:
92-
93-
- You can specify both on a single property.
94-
- If there is a value without option the property got the value, but if another value with the specified option exists, the new value will override the old one.
95-
96-
```csharp
97-
[Value(0), Option('f', "File")]
98-
public string FilePath { get; }
76+
### .NET CLI Style
77+
```
78+
> demo.exe "C:\Users\lvyi\Desktop\demo.txt" -s:true --mode:Edit --startup-sessions:A;B;C
9979
```
10080

81+
## Command Styles and Features
82+
83+
The library supports multiple command line styles through `CommandLineStyle` enum:
84+
- Flexible (default): Intelligently recognizes multiple styles
85+
- GNU: GNU standard compliant
86+
- POSIX: POSIX standard compliant
87+
- DotNet: .NET CLI style
88+
- PowerShell: PowerShell style
89+
90+
Advanced features include:
91+
- Support for various data types including collections and dictionaries
92+
- Positional arguments with `ValueAttribute`
93+
- Required properties with C# `required` modifier
94+
- Command handling with verb support
95+
- URL protocol parsing
96+
- High performance thanks to source generators
97+
10198
## Engage, Contribute and Provide Feedback
10299

103100
Thank you very much for firing a new issue and providing new pull requests.

0 commit comments

Comments
 (0)