-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram.cs
More file actions
113 lines (96 loc) · 3.17 KB
/
Program.cs
File metadata and controls
113 lines (96 loc) · 3.17 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
using System.CommandLine;
namespace Beinggs.Transfer;
/// <summary>
/// Implements a simple test data and file transfer command-line utility.
/// </summary>
/// <remarks>
/// See the README.md file for details of operation.
/// </remarks>
public partial class Program
{
/// <summary>
/// Defines the entry point for <see cref="Program"/>.
/// </summary>
/// <param name="args"></param>
/// <returns></returns>
static async Task<int> Main (string[] args)
{
// as commands can't be declared with aliases, we have to declare them here and add aliases later <grr!>
Command sendCommand;
Command sendFileCommand;
Command sendTestCommand;
Command receiveCommand;
Command receiveFileCommand;
Command receiveTestCommand;
// build the command line...
var arg0 = Environment.GetCommandLineArgs() [0];
var exeName = Path.GetFileNameWithoutExtension (arg0);
RootCommand rootCommand = new ($"Beinggs Transfer ({exeName}) - Simple Transfer App")
{
(sendCommand = new (
name: "send",
description: "Send a file or test data")
{
(sendFileCommand = new (
name: "file",
description: "Send a file")
{
argFile,
optIncludeFileName,
cmdFileTo
}),
(sendTestCommand = new (
name: "test",
description: "Send test data")
{
cmdTestTo
}),
cmdTestTo // implicit 'test' command
}),
(receiveCommand = new (
name: "receive",
description: "Receive a file or test data")
{
(receiveFileCommand = new (
name: "file",
description: "Receive a file")
{
argFileName, // this is a string?, so can't use argFile as that's a FileInfo?
cmdFileFrom
}),
(receiveTestCommand = new (
name: "test",
description: "Receive test data")
{
cmdTestFrom
}),
cmdTestFrom // implicit 'test' command
})
};
// ... add aliases...
sendCommand.AddAlias ("s");
sendFileCommand.AddAlias ("f");
sendTestCommand.AddAlias ("t");
receiveCommand.AddAlias ("r");
receiveFileCommand.AddAlias ("f");
receiveTestCommand.AddAlias ("t");
// ... add globals...
globalOptVerbosity.Arity = ArgumentArity.ZeroOrOne; // verbosity with no value defaults to verbose
globalOptMeasured.Arity = ArgumentArity.ZeroOrOne; // measured with no value defaults to measured
rootCommand.AddGlobalOption (globalOptVerbosity);
rootCommand.AddGlobalOption (globalOptMeasured);
rootCommand.AddGlobalOption (globalOptPort);
// ... set handlers...
// rootCommand.SetHandler (SetLogLevel, verbosity); // GRR! This should be supported, at least for globals! :-/
cmdFileTo.SetHandler (ToFileCommand, globalOptVerbosity, globalOptMeasured, globalOptPort, optRepeat,
argFile, optIncludeFileName, argRecipient);
cmdTestTo.SetHandler (ToTestCommand, globalOptVerbosity, globalOptMeasured, globalOptPort, optRepeat,
optTestSize, argRecipient);
cmdFileFrom.SetHandler (FromFileCommand, globalOptVerbosity, globalOptMeasured, globalOptPort,
argFileName, argSender);
cmdTestFrom.SetHandler (FromTestCommand, globalOptVerbosity, globalOptMeasured, globalOptPort,
optMaxSize, optMaxTime, argSender);
// ... and let the magic happen!
return await rootCommand.InvokeAsync (args);
}
}