Skip to content

Commit 7b39e5e

Browse files
authored
Added help command for all projects (#20)
1 parent 8d53fd1 commit 7b39e5e

File tree

10 files changed

+164
-19
lines changed

10 files changed

+164
-19
lines changed

Source/LocalNetAppChat/CommandLineArguments/Parser.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ public Parser(ICommandLineOption[] options)
88
this.options = options;
99
}
1010

11+
public ICommandLineOption[] GetCommandsList()
12+
{
13+
return this.options;
14+
}
15+
1116
public bool TryParse(string[] args, bool allowIncompleteness)
1217
{
1318
var position = 0;

Source/LocalNetAppChat/LocalNetAppChat.Bot/Program.cs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using LocalNetAppChat.Bot.Plugins.ScriptExecution;
1+
using CommandLineArguments;
2+
using LocalNetAppChat.Bot.Plugins.ScriptExecution;
23
using LocalNetAppChat.Domain.Bots.ClientCommands;
34
using LocalNetAppChat.Domain.Clientside;
45
using LocalNetAppChat.Domain.Clientside.ServerApis;
@@ -26,6 +27,37 @@ public static async Task Main(string[] args)
2627

2728
var parameters = commandLineParametersResult.Value;
2829

30+
if (parameters.Help)
31+
{
32+
ICommandLineOption[] commands = parser.GetCommandsList();
33+
string[] commandsDescription =
34+
{
35+
"The IP Address the bot should connect to (e.g localhost)",
36+
"The port that the bot should connect to (default: 5000)",
37+
"Whether to connect per HTTP or HTTPs",
38+
"Specifies the bot name, otherwise the name of the machine will be used\", \"Whether to ignore SSL Erros in console.",
39+
"An Authentication password that the bot should send along the requests to be able to perform tasks. (default: 1234)",
40+
"Whether to ignore SSL Erros in console.",
41+
"Prints out the commands and their corresponding descriptioon"
42+
};
43+
44+
List<string> commandsWithDescription = new();
45+
46+
for (int i = 0; i < commands.Length; i++)
47+
{
48+
commandsWithDescription.Add($"{commands[i].Name}\r\n\t{commandsDescription[i]}");
49+
}
50+
51+
Console.WriteLine($"\nThe LNAC Bot. It's main purpose for now is to execute special commands on the machine it is running on and send the result of the execution to the client who requested it" +
52+
$"\n\n [Usage]\n\n" +
53+
$"\n{string.Join("\r\n", commandsWithDescription)}");
54+
55+
Console.WriteLine("\n\nExamples:\r\n\r\n – Start the bot\r\n $ LocalNetAppChat.Bot --server \"localhost\" --port 54214 --key 1234 --clientName \"TheBestBot\" --scriptspath \"./home/ScriptsFolder\"");
56+
57+
return;
58+
}
59+
60+
2961
var apiAccessor = new WebApiServerApiAccessor(
3062
parameters.Server, parameters.Port, parameters.Https, parameters.IgnoreSslErrors,
3163
parameters.Key,

Source/LocalNetAppChat/LocalNetAppChat.Bot/Properties/launchSettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"profiles": {
33
"LocalNetAppChat.Bot": {
44
"commandName": "Project",
5-
"commandLineArgs": "--server localhost --port 5000 --key 1234 --scriptspath \"C:\\Users\\Kane\\Documents\\Github\\LocalNetAppChat\\Source\\LocalNetAppChat\\LocalNetAppChat.Bot\\my_scripts\""
5+
"commandLineArgs": "--help"
66
}
77
}
88
}

Source/LocalNetAppChat/LocalNetAppChat.ConsoleClient/Program.cs

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using LocalNetAppChat.Domain.Clientside;
1+
using CommandLineArguments;
2+
using LocalNetAppChat.Domain.Clientside;
23
using LocalNetAppChat.Domain.Clientside.OperatingModes;
34
using LocalNetAppChat.Domain.Clientside.ServerApis;
45
using LocalNetAppChat.Domain.Shared.Inputs;
@@ -25,6 +26,48 @@ public static async Task Main(string[] args)
2526

2627
var parameters = commandLineParametersResult.Value;
2728

29+
if (parameters.Help)
30+
{
31+
32+
ICommandLineOption[] commands = parser.GetCommandsList();
33+
string[] commandsDescription =
34+
{
35+
"Run the client in message mode",
36+
"Run the client in listener mode",
37+
"Uploads a given file to the server",
38+
"Returns a list of all existing files on the server",
39+
"Downloads an existing file from the server",
40+
"Deletes an existing file from the server",
41+
"Runs the client essentially in a listener mode, but when you start typing you are delivered a prompt and with enter you will send the message",
42+
"The IP Address the bot should connect to (e.g localhost)",
43+
"The port that the bot should connect to (default: 5000)",
44+
"Path of the file you want to delete, download or upload from/to the server",
45+
"Whether to connect per HTTP or HTTPs",
46+
"The text message to send to the server. (only when in message mode!)",
47+
"The name of your client. If not specified, your machine name will be sent as clientName to the server",
48+
"An Authentication password that the server requires to allow incoming requests from the client!",
49+
"Whether to ignore SSL Erros in console",
50+
"Path where you want the requested File to be saved at after downloading it",
51+
"Prints out the commands and their corresponding descriptioon"
52+
53+
};
54+
55+
List<string> commandsWithDescription = new();
56+
57+
for (int i = 0; i < commands.Length; i++)
58+
{
59+
commandsWithDescription.Add($"{commands[i].Name}\r\n\t{commandsDescription[i]}");
60+
}
61+
62+
Console.WriteLine($"\nThe LNAC Client allows you to communicate with the server as well as with other sub applications." +
63+
$"\n\n [Usage]\n\n" +
64+
$"\n{string.Join("\n", commandsWithDescription)}");
65+
66+
Console.WriteLine("\n\nExamples:\r\n\r\n – Start the client in listening mode\r\n $ LocalNetAppChat.ConsoleClient listener --server \"localhost\" --port 54214 --key 1234 --clientName \"GithubReadMe\"\r\n - Start the client in message mode\r\n $ LocalNetAppChat.ConsoleClient message --server \"localhost\" --port 51234 --key 1234 --text \"Hey there, I am client GithubReadMe\"\r\n - Start the client in chat mode\r\n LocalNetAppChat.ConsoleClient chat --server \"localhost\" --port 54214 --key 1234 --clientName \"GithubReadMe\"\r\n - Upload a file to the server\r\n $ LocalNetAppChat.ConsoleClient fileupload --server \"localhost\" --port 51234 --key 1234 --file \"./README.md\"\r\n - Download a file from the server\r\n $ LocalNetAppChat.ConsoleClient filedownload --server \"localhost\" --port 51234 --key 1234 --file \"./README.md\" --targetPath \"/home/github/Projects\"\r\n - Deletes a file from the server\r\n $ LocalNetAppChat.ConsoleClient filedelete --server \"localhost\" --port 51234 --key 1234 --file \"README.md\"\r\n - List all files existing on the server\r\n $ LocalNetAppChat.ConsoleClient listfiles --server \"localhost\" --port 51234 --key 1234");
67+
68+
return;
69+
}
70+
2871
var apiAccessor = new WebApiServerApiAccessor(
2972
parameters.Server, parameters.Port, parameters.Https, parameters.IgnoreSslErrors,
3073
parameters.Key,
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"profiles": {
3+
"LocalNetAppChat.ConsoleClient": {
4+
"commandName": "Project",
5+
"commandLineArgs": "--help"
6+
}
7+
}
8+
}

Source/LocalNetAppChat/LocalNetAppChat.Domain/Clientside/ClientSideCommandLineParameters.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ public record ClientSideCommandLineParameters(
1919
string ClientName,
2020
string Key,
2121
bool IgnoreSslErrors,
22-
string TargetPath);
22+
string TargetPath,
23+
bool Help);

Source/LocalNetAppChat/LocalNetAppChat.Domain/Clientside/ClientSideCommandLineParser.cs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,16 @@ public ClientSideCommandLineParser()
99
{
1010
}
1111

12-
public Result<ClientSideCommandLineParameters> Parse(string[] args)
12+
public ICommandLineOption[] GetCommandsList()
13+
{
14+
var parser = this.ParseArgs();
15+
return parser.GetCommandsList();
16+
}
17+
18+
private Parser ParseArgs()
1319
{
1420
var parser = new Parser(
15-
new ICommandLineOption[] {
21+
new ICommandLineOption[] {
1622
new BoolCommandLineOption("message"),
1723
new BoolCommandLineOption("listener"),
1824
new BoolCommandLineOption("fileupload"),
@@ -29,8 +35,14 @@ public Result<ClientSideCommandLineParameters> Parse(string[] args)
2935
new StringCommandLineOption("--clientName", Environment.MachineName),
3036
new StringCommandLineOption("--key", "1234"),
3137
new BoolCommandLineOption("--ignoresslerrors"),
32-
new StringCommandLineOption("--targetPath")
33-
});
38+
new StringCommandLineOption("--targetPath"),
39+
new BoolCommandLineOption("--help")
40+
});
41+
return parser;
42+
}
43+
public Result<ClientSideCommandLineParameters> Parse(string[] args)
44+
{
45+
var parser = this.ParseArgs();
3446

3547
if (!parser.TryParse(args, true) || args.Length == 0)
3648
{
@@ -54,8 +66,8 @@ public Result<ClientSideCommandLineParameters> Parse(string[] args)
5466
parser.GetOptionWithValue<string>("--clientName") ?? Environment.MachineName,
5567
parser.GetOptionWithValue<string>("--key") ?? "1234",
5668
parser.GetBoolOption("--ignoresslerrors"),
57-
parser.GetOptionWithValue<string>("--targetPath") ?? Directory.GetCurrentDirectory()
58-
69+
parser.GetOptionWithValue<string>("--targetPath") ?? Directory.GetCurrentDirectory(),
70+
parser.GetBoolOption("--help")
5971
));
6072
}
6173
}

Source/LocalNetAppChat/LocalNetAppChat.Domain/Clientside/ServerConnectionCommandLineParameters.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ public record ServerConnectionCommandLineParameters(
66
bool Https,
77
string ClientName,
88
string Key,
9-
bool IgnoreSslErrors);
9+
bool IgnoreSslErrors,
10+
bool Help);

Source/LocalNetAppChat/LocalNetAppChat.Domain/Clientside/ServerConnectionCommandLineParser.cs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,32 @@ namespace LocalNetAppChat.Domain.Clientside;
55

66
public class ServerConnectionCommandLineParser
77
{
8-
public Result<ServerConnectionCommandLineParameters> Parse(string[] args)
8+
public ICommandLineOption[] GetCommandsList()
9+
{
10+
var parser = this.ParseArgs();
11+
return parser.GetCommandsList();
12+
}
13+
private Parser ParseArgs()
914
{
1015
var parser = new Parser(
11-
new ICommandLineOption[] {
16+
new ICommandLineOption[] {
1217
new StringCommandLineOption("--server", "localhost"),
1318
new Int32CommandLineOption("--port", 5000),
1419
new BoolCommandLineOption("--https"),
1520

1621
new StringCommandLineOption("--clientName", Environment.MachineName),
1722
new StringCommandLineOption("--key", "1234"),
18-
19-
new BoolCommandLineOption("--ignoresslerrors")
20-
});
21-
23+
24+
new BoolCommandLineOption("--ignoresslerrors"),
25+
new BoolCommandLineOption("--help")
26+
});
27+
28+
return parser;
29+
}
30+
public Result<ServerConnectionCommandLineParameters> Parse(string[] args)
31+
{
32+
var parser = this.ParseArgs();
33+
2234
if (!parser.TryParse(args, true) || args.Length == 0) {
2335
return Result<ServerConnectionCommandLineParameters>.Failure("Invalid command line arguments");
2436
}
@@ -30,7 +42,8 @@ public Result<ServerConnectionCommandLineParameters> Parse(string[] args)
3042
parser.GetBoolOption("--https"),
3143
parser.GetOptionWithValue<string>("--clientName") ?? Environment.MachineName,
3244
parser.GetOptionWithValue<string>("--key")?? "1234",
33-
parser.GetBoolOption("--ignoresslerrors")
45+
parser.GetBoolOption("--ignoresslerrors"),
46+
parser.GetBoolOption("--help")
3447
));
3548
}
3649
}

Source/LocalNetAppChat/LocalNetAppChat.Server/Program.cs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,46 @@
1212
new StringCommandLineOption("--listenOn", "localhost"),
1313
new Int32CommandLineOption("--port", 5000),
1414
new BoolCommandLineOption("--https"),
15-
new StringCommandLineOption("--key", "1234")
15+
new StringCommandLineOption("--key", "1234"),
16+
new BoolCommandLineOption("--help")
1617
});
1718

19+
1820
if (!parser.TryParse(args, true))
1921
{
2022
Console.WriteLine("Unfortunately there have been problems with the command line arguments.");
2123
Console.WriteLine("");
2224
return;
2325
}
2426

27+
if (parser.GetBoolOption("--help"))
28+
{
29+
ICommandLineOption[] commands = parser.GetCommandsList();
30+
string[] commandsDescription =
31+
{
32+
"The IP Address the server should start litening on (e.g localhost)",
33+
"The port the server should connect to (default: 5000)",
34+
"Whether to start the server as HTTPS or HTTP server",
35+
"An Authentication password that the client should send along the requests to be able to perform tasks. (default: 1234)",
36+
"Prints out the commands and their corresponding descriptioon"
37+
};
38+
39+
List<string> commandsWithDescription = new();
40+
41+
for (int i = 0; i < commands.Length; i++)
42+
{
43+
commandsWithDescription.Add($"{commands[i].Name}\r\n\t{commandsDescription[i]}");
44+
}
45+
46+
Console.WriteLine($"\nThe LNAC Server is responsible for handling communication and incoming requests from the clients. It is the main core of the application and has a lot of features." +
47+
$"\n\n [Usage]\n\n" +
48+
$"\n{string.Join("\n", commandsWithDescription)}");
49+
50+
Console.WriteLine("\n\nExamples:\r\n\r\n – Start the server with the default settings\r\n $ LocalNetAppChat.Server\r\n - Start the server in HTTPS mode\r\n $ LocalNetAppChat.Server --https\r\n - Start the server with different ip and port and custom key\r\n $ LocalNetAppChat.Server --listenOn \"54.15.12.1\" --port \"54822\" --https --key \"HeythereGithubExample\"");
51+
52+
return;
53+
}
54+
2555
var serverKey = parser.TryGetOptionWithValue<string>("--key");
2656
var accessControl = new KeyBasedAccessControl(serverKey??string.Empty);
2757

0 commit comments

Comments
 (0)