Skip to content

Commit e8f73ff

Browse files
committed
Improved help command, added Tests for Direct Messages Refinement, draft implementation
1 parent c208c65 commit e8f73ff

File tree

16 files changed

+199
-104
lines changed

16 files changed

+199
-104
lines changed

Source/LocalNetAppChat/CommandLineArguments/BoolCommandLineOption.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ public class BoolCommandLineOption : IBoolCommandLineOption
55
private bool _value = false;
66
private bool _hasValue = false;
77

8-
public BoolCommandLineOption(string name)
8+
public BoolCommandLineOption(string name, string description)
99
{
1010
Name = name;
11+
Description = description;
1112
}
1213

1314
public string Name { get; }
14-
15+
public string Description { get; }
1516
public bool IsTypeWithSeparateValue => false;
1617

1718
public bool GetValue()

Source/LocalNetAppChat/CommandLineArguments/ICommandLineOption.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
public interface ICommandLineOption
44
{
55
string Name { get; }
6-
6+
string Description { get; }
77
bool HasNoValueYet();
88
bool TryParseFrom(string[] args, ref int position);
99
bool IsTypeWithSeparateValue { get; }

Source/LocalNetAppChat/CommandLineArguments/Int32CommandLineOption.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ public class Int32CommandLineOption : WithValueCommandLineOption<int>
77

88
public Int32CommandLineOption(
99
string name,
10+
string description,
1011
int defaultValue = 0,
1112
int min = Int32.MinValue,
12-
int max = Int32.MaxValue) : base(name, defaultValue)
13+
int max = Int32.MaxValue) : base(name, description, defaultValue)
1314
{
1415
_min = min;
1516
_max = max;

Source/LocalNetAppChat/CommandLineArguments/StringCommandLineOption.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
public class StringCommandLineOption : WithValueCommandLineOption<string>
44
{
55
public StringCommandLineOption(
6-
string name,
6+
string name,
7+
string description,
78
string defaultValue = "")
8-
: base(name, defaultValue)
9+
: base(name, description,defaultValue)
910
{
1011
}
1112

Source/LocalNetAppChat/CommandLineArguments/WithValueCommandLineOption.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,20 @@
33
public abstract class WithValueCommandLineOption<T> : IWithValueCommandLineOption<T>
44
{
55
public string Name { get; }
6-
6+
public string Description { get; }
77
public bool IsTypeWithSeparateValue => true;
88

99
private T? _value;
1010
private bool _hasValue = false;
1111

1212
public WithValueCommandLineOption(
1313
string name,
14+
string description,
1415
T? defaultValue)
1516
{
1617
Name = name;
1718
_value = defaultValue;
19+
Description= description;
1820
}
1921

2022
public T? GetValue()

Source/LocalNetAppChat/LocalNetAppChat.Bot/Plugins/ScriptExecution/ScriptExecutionCommandLineParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public Result<ScriptExecutionParameters> Parse(string[] args)
99
{
1010
var parser = new Parser(
1111
new ICommandLineOption[] {
12-
new StringCommandLineOption("--scriptspath")
12+
new StringCommandLineOption("--scriptspath", "Path to the folder where the scripts are located")
1313
});
1414

1515
if (!parser.TryParse(args, true))

Source/LocalNetAppChat/LocalNetAppChat.Bot/Program.cs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,12 @@ public static async Task Main(string[] args)
3030
if (parameters.Help)
3131
{
3232
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-
};
4333

4434
List<string> commandsWithDescription = new();
45-
46-
for (int i = 0; i < commands.Length; i++)
35+
36+
foreach (var command in commands)
4737
{
48-
commandsWithDescription.Add($"{commands[i].Name}\r\n\t{commandsDescription[i]}");
38+
commandsWithDescription.Add($"{command.Name}\r\n\t{command.Description}");
4939
}
5040

5141
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" +

Source/LocalNetAppChat/LocalNetAppChat.ConsoleClient/Program.cs

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -30,33 +30,12 @@ public static async Task Main(string[] args)
3030
{
3131

3232
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 Errors 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 description"
52-
53-
};
5433

5534
List<string> commandsWithDescription = new();
5635

57-
for (int i = 0; i < commands.Length; i++)
36+
foreach (var command in commands)
5837
{
59-
commandsWithDescription.Add($"{commands[i].Name}\r\n\t{commandsDescription[i]}");
38+
commandsWithDescription.Add($"{command.Name}\r\n\t{command.Description}");
6039
}
6140

6241
Console.WriteLine($"\nThe LNAC Client allows you to communicate with the server as well as with other sub applications." +
@@ -70,13 +49,13 @@ public static async Task Main(string[] args)
7049
– Start the client in listening mode
7150
$ LocalNetAppChat.ConsoleClient listener --server ""localhost"" --port 54214 --key 1234 --clientName ""GithubReadMe""
7251
- Start the client in message mode
73-
$ LocalNetAppChat.ConsoleClient message --server ""localhost"" --port 51234 --key 1234 --text ""Hey there, I am client GithubReadMe""
52+
$ LocalNetAppChat.ConsoleClient message --server ""localhost"" --port 51234 --key 1234 --text ""Hey I am client Github""
7453
- Start the client in chat mode
7554
LocalNetAppChat.ConsoleClient chat --server ""localhost"" --port 54214 --key 1234 --clientName ""GithubReadMe""
7655
- Upload a file to the server
7756
$ LocalNetAppChat.ConsoleClient fileupload --server ""localhost"" --port 51234 --key 1234 --file ""./README.md""
7857
- Download a file from the server
79-
$ LocalNetAppChat.ConsoleClient filedownload --server ""localhost"" --port 51234 --key 1234 --file ""./README.md"" --targetPath ""/home/github/Projects""
58+
$ LocalNetAppChat.ConsoleClient filedownload --server ""localhost"" --port 51234 --key 1234 --file ""./README.md"" --targetPath ""github/Projects""
8059
- Deletes a file from the server
8160
$ LocalNetAppChat.ConsoleClient filedelete --server ""localhost"" --port 51234 --key 1234 --file ""README.md""
8261
- List all files existing on the server

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

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,23 @@ private Parser ParseArgs()
2020
var parser = new Parser(
2121
new ICommandLineOption[]
2222
{
23-
new BoolCommandLineOption("message"),
24-
new BoolCommandLineOption("listener"),
25-
new BoolCommandLineOption("fileupload"),
26-
new BoolCommandLineOption("listfiles"),
27-
new BoolCommandLineOption("filedownload"),
28-
new BoolCommandLineOption("filedelete"),
29-
new BoolCommandLineOption("chat"),
30-
new StringCommandLineOption("--file"),
31-
new StringCommandLineOption("--server", "localhost"),
32-
new Int32CommandLineOption("--port", 5000),
33-
new BoolCommandLineOption("--https"),
34-
35-
new StringCommandLineOption("--text"),
36-
new StringCommandLineOption("--clientName", Environment.MachineName),
37-
new StringCommandLineOption("--key", "1234"),
38-
new BoolCommandLineOption("--ignoresslerrors"),
39-
new StringCommandLineOption("--targetPath"),
40-
new BoolCommandLineOption("--help")
23+
new BoolCommandLineOption("message", "Run the client in message mode"),
24+
new BoolCommandLineOption("listener", "Run the client in listener mode"),
25+
new BoolCommandLineOption("fileupload", "Uploads a given file to the server"),
26+
new BoolCommandLineOption("listfiles", "Returns a list of all existing files on the server"),
27+
new BoolCommandLineOption("filedownload", "Downloads an existing file from the server"),
28+
new BoolCommandLineOption("filedelete", "Deletes an existing file from the server"),
29+
new BoolCommandLineOption("chat", "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"),
30+
new StringCommandLineOption("--file", "Path of the file you want to delete, download or upload from/to the server"),
31+
new StringCommandLineOption("--server","The IP Address the bot should connect to (e.g localhost)" ,"localhost"),
32+
new Int32CommandLineOption("--port","The port that the bot should connect to (default: 5000)", 5000),
33+
new BoolCommandLineOption("--https", "\"Whether to connect per HTTP or HTTPs\""),
34+
new StringCommandLineOption("--text", "The text message to send to the server. (only when in message mode!)"),
35+
new StringCommandLineOption("--clientName", "The name of your client. If not specified, your machine name will be sent as clientName to the server",Environment.MachineName),
36+
new StringCommandLineOption("--key","An Authentication password that the server requires to allow incoming requests from the client!" ,"1234"),
37+
new BoolCommandLineOption("--ignoresslerrors", "Whether to ignore SSL Errors in console"),
38+
new StringCommandLineOption("--targetPath", "Path where you want the requested File to be saved at after downloading it"),
39+
new BoolCommandLineOption("--help", "Prints out the commands and their corresponding description")
4140
});
4241
return parser;
4342
}

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ private Parser ParseArgs()
1414
{
1515
var parser = new Parser(
1616
new ICommandLineOption[] {
17-
new StringCommandLineOption("--server", "localhost"),
18-
new Int32CommandLineOption("--port", 5000),
19-
new BoolCommandLineOption("--https"),
17+
new StringCommandLineOption("--server", "The IP Address the bot should connect to (e.g localhost)","localhost"),
18+
new Int32CommandLineOption("--port", "The port the server should connect to (default: 5000)", 5000),
19+
new BoolCommandLineOption("--https", "Whether to connect per HTTP or HTTPs"),
2020

21-
new StringCommandLineOption("--clientName", Environment.MachineName),
22-
new StringCommandLineOption("--key", "1234"),
21+
new StringCommandLineOption("--clientName","Specifies the bot name, otherwise the name of the machine will be used\", \"Whether to ignore SSL Erros in console.", Environment.MachineName),
22+
new StringCommandLineOption("--key", "An Authentication password that the bot should send along the requests to be able to perform tasks. (default: 1234)","1234"),
2323

24-
new BoolCommandLineOption("--ignoresslerrors"),
25-
new BoolCommandLineOption("--help")
24+
new BoolCommandLineOption("--ignoresslerrors","Whether to ignore SSL Erros in console."),
25+
new BoolCommandLineOption("--help", "Prints out the commands and their corresponding description")
2626
});
2727

2828
return parser;

0 commit comments

Comments
 (0)