-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsingle-file-ex.cs
More file actions
31 lines (21 loc) · 844 Bytes
/
Copy pathsingle-file-ex.cs
File metadata and controls
31 lines (21 loc) · 844 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#:package CommandLine.EasyBuilder@2.0.1
using static System.Console;
using System.CommandLine;
using CommandLine.EasyBuilder;
WriteLine("Single file .cs app CLI example (let's GO csharp!)");
RootCommand rootCmd = new("Command line is cool");
rootCmd.AddAutoCommand<HelloWorldCmd>();
await BasicCLI.Run(rootCmd, args, interactive: true);
[Command("hello", "Hello commandline world!")]
public class HelloWorldCmd
{
[Option("--name", "-n", required: true)]
public string Name { get; set; }
[Option("--age", required: true)]
public int Age { get; set; }
[Option("--animal", "-a", required: true)]
public FavoriteAnimal FavAnimal { get; set; } = FavoriteAnimal.Cheetah;
public void Handle()
=> WriteLine($"Hello {Name} ({Age}), glad to see you love {FavAnimal}s!");
}
public enum FavoriteAnimal { None, Dog, Cat, Cheetah, Rhino }