-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOptions.cs
More file actions
48 lines (39 loc) · 1.65 KB
/
Options.cs
File metadata and controls
48 lines (39 loc) · 1.65 KB
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
using CommandLine;
using CommandLine.Text;
namespace csvcat;
public class Options
{
[Value(0, MetaName = "csv file", Required = true)]
public string Filename { get; set; }
[Option('n', "number", Default = 0, HelpText = "Number of lines.")]
public int Lines { get; set; }
[Option('t', "tail", Default = false, HelpText = "Tail csv file")]
public bool Tail { get; set; }
[Option('s', "sort", HelpText = "Sort by field index (0-based)")]
public int? Sort { get; set; }
[Option('r', "reverse", Default = false, HelpText = "Reverse results")]
public bool Reverse { get; set; }
[Option('d', "delimiter", Default = ',', HelpText = "Delimiting character. Default = ','")]
public char Delimiter { get; set; }
[Usage(ApplicationAlias = "csvcat")]
public static IEnumerable<Example> Examples
{
get
{
yield return new Example("cat csv file", new Options { Filename = "file.csv", Lines = 20 });
yield return new Example("tail csv file", new Options { Filename = "file.csv", Lines = 30, Tail = true, Delimiter = '|' });
}
}
public static void DisplayHelp<T>(ParserResult<T> result, IEnumerable<Error> errs)
{
HelpText helpText = errs.IsVersion() ? HelpText.AutoBuild(result)
: HelpText.AutoBuild(result, h =>
{
h.AdditionalNewLineAfterOption = false;
h.Heading = "csvcat 1.1.2";
h.Copyright = "Copyright (c) 2023 lc9er";
return HelpText.DefaultParsingErrorsHandler(result, h);
}, e => e);
Console.WriteLine(helpText);
}
}