14 {
15
16 SentenceBuilder.Factory = () => new LocalizableSentenceBuilder();
17
18 Func<IOptions, string> reader = opts =>
19 {
20 var fromTop = opts.GetType() == typeof(HeadOptions);
21 return opts.Lines.HasValue
22 ?
ReadLines(opts.FileName, fromTop, (
int)opts.Lines)
23 :
ReadBytes(opts.FileName, fromTop, (int)opts.Bytes);
24 };
25 Func<IOptions, string> header = opts =>
26 {
27 if (opts.Quiet)
28 {
29 return string.Empty;
30 }
31 var fromTop = opts.GetType() == typeof(HeadOptions);
32 var builder = new StringBuilder(Properties.Resources.Reading);
33 builder = opts.Lines.HasValue
34 ? builder.Append(opts.Lines).Append(Properties.Resources.Lines)
35 : builder.Append(opts.Bytes).Append(Properties.Resources.Bytes);
36 builder = fromTop ? builder.Append(Properties.Resources.FromTop) : builder.Append(Properties.Resources.FromBottom);
37 return builder.ToString();
38 };
39 Action<string> printIfNotEmpty = text =>
40 {
41 if (text.Length == 0) { return; }
42 Console.WriteLine(text);
43 };
44
46 var texts = result
47 .MapResult(
48 (HeadOptions opts) => Tuple.Create(header(opts), reader(opts)),
49 (TailOptions opts) => Tuple.Create(header(opts), reader(opts)),
51
52 printIfNotEmpty(texts.Item1);
53 printIfNotEmpty(texts.Item2);
54
56 }
Provides methods to parse command line arguments.
ParserResult< object > ParseArguments(IEnumerable< string > args, params Type[] types)
Parses a string array of command line arguments for verb commands scenario, constructing the proper i...
static Parser Default
Gets the singleton instance created with basic defaults.
static string ReadLines(string fileName, bool fromTop, int count)
static string ReadBytes(string fileName, bool fromTop, int count)
static Tuple< string, string > MakeError()