Skip to content

Commit 2466343

Browse files
committed
2 parents 9a45f60 + 84088e3 commit 2466343

2 files changed

Lines changed: 82 additions & 1 deletion

File tree

.github/workflows/cipackage.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: CI and Build Package
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
7+
jobs:
8+
windows64:
9+
runs-on: windows-latest
10+
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v4
14+
- name: Install .NET Core
15+
uses: actions/setup-dotnet@v4
16+
with:
17+
dotnet-version: 9.0.x
18+
19+
- name: Restore dependencies
20+
run: dotnet restore src/FlowCommandLine/FlowCommandLine.csproj
21+
- name: Build
22+
run: dotnet build --configuration Release src/FlowCommandLine/FlowCommandLine.csproj
23+
- name: Tests
24+
run: dotnet test --configuration Release --no-build src/FlowCommandLine/FlowCommandLine.csproj
25+
- name: Pack package
26+
run: dotnet pack --configuration Release --no-build --output . src/FlowCommandLine/FlowCommandLine.csproj

README.md

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,57 @@
11
# FlowCommandLine
2-
A fast and simple command line parser that works in two modes: command-based (e.g. `git commit ...`) or parameter-only. It support modern dotnet core runtimes (net8+), compilation in NativeAot.
2+
A fast and simple command line parser that works in two modes: command-based (e.g. `git commit ...`) or parameters-only. Parsing can be happened to any model class or record with parameterless constructor.
3+
It support modern dotnet core runtimes (net8+), compilation in NativeAot. It supported auto documentation for commands and parameters.
4+
Model parameters mapped types is supported: int, long, double, float, string, DateOnly, DateTime, TimeSpan.
5+
By default, the output will be to the system console, but can be redefined to any of your case - instead `CommandLine.Console ()` you can use `new CommandLine (new MyConsoleCommandLineProvider())` where `MyConsoleCommandLineProvider` it is you class which is implement `ICommandLineProvider` interface.
6+
7+
## Command-based mode
8+
9+
Example command line:
10+
`myconapp runapp --param1=stringvalue --param2=120`
11+
12+
```csharp
13+
public class Test {
14+
public string Param1 { get; set; } = "";
15+
public int Param2 { get; set; }
16+
}
17+
18+
CommandLine.Console ()
19+
// setup console application description version and so on
20+
.Application ( "My Console App", "1.0.0", "full description.", "Copyright My Super Corporation", "myconapp" )
21+
.AddCommand ( // add console command
22+
"runapp", // command name
23+
( Test parameters ) => { // command delegate handler for class Test
24+
...
25+
},
26+
"Command description", // command description :)
27+
new List<FlowCommandParameter> { // adjust command parameters
28+
new FlowCommandParameter {
29+
FullName = "param1", // for parameter in format --param1
30+
ShortName = "p1, // for parameter in format -p1
31+
PropertyName = "Param1" // it
32+
Description = "parameter description",
33+
Required = true, // parameter is required
34+
},
35+
new FlowCommandParameter {
36+
FullName = "param2", // full name is required property, other properties ShortName or PropertyName can be inferred from FullName
37+
Description = "parameter2 description",
38+
Required = false,
39+
}
40+
}
41+
)
42+
.RunCommand ();
43+
```
44+
45+
## Parameters-only mode
46+
47+
Example command line:
48+
`myconapp --param1=stringvalue --param2=120`
49+
50+
```csharp
51+
var options = CommandLine.Console ()
52+
.Application ( "My Console App", "1.0.0", "full description.", "Copyright My Super Corporation", "myconapp" )
53+
.AddOption ( "p1", "param1", "parameter 1 description", required: true )
54+
.AddOption ( "p2", "param2", "parameter 2 description", required: false )
55+
.RunOptions<Test> (); // run options parse and
56+
```
57+

0 commit comments

Comments
 (0)