forked from commandlineparser/commandline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOptions.cs
65 lines (52 loc) · 2.16 KB
/
Options.cs
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using CommandLine;
using CommandLine.Text;
using System.Collections.Generic;
namespace ReadText.Demo
{
interface IOptions
{
[Option('n', "lines",
Default = 5U,
SetName = "bylines",
HelpText = "Lines to be printed from the beginning or end of the file.")]
uint? Lines { get; set; }
[Option('c', "bytes",
SetName = "bybytes",
HelpText = "Bytes to be printed from the beginning or end of the file.")]
uint? Bytes { get; set; }
[Option('q', "quiet",
HelpText = "Suppresses summary messages.")]
bool Quiet { get; set; }
[Value(0, MetaName = "input file",
HelpText = "Input file to be processed.",
Required = true)]
string FileName { get; set; }
}
[Verb("head", true, HelpText = "Displays first lines of a file.")]
class HeadOptions : IOptions
{
public uint? Lines { get; set; }
public uint? Bytes { get; set; }
public bool Quiet { get; set; }
public string FileName { get; set; }
[Usage(ApplicationAlias = "ReadText.Demo.exe")]
public static IEnumerable<Example> Examples
{
get
{
yield return new Example("normal scenario", new HeadOptions { FileName = "file.bin"});
yield return new Example("specify bytes", new HeadOptions { FileName = "file.bin", Bytes=100 });
yield return new Example("suppress summary", UnParserSettings.WithGroupSwitchesOnly(), new HeadOptions { FileName = "file.bin", Quiet = true });
yield return new Example("read more lines", new[] { UnParserSettings.WithGroupSwitchesOnly(), UnParserSettings.WithUseEqualTokenOnly() }, new HeadOptions { FileName = "file.bin", Lines = 10 });
}
}
}
[Verb("tail", HelpText = "Displays last lines of a file.")]
class TailOptions : IOptions
{
public uint? Lines { get; set; }
public uint? Bytes { get; set; }
public bool Quiet { get; set; }
public string FileName { get; set; }
}
}