-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCommandLineCommand.cs
97 lines (89 loc) · 3.13 KB
/
CommandLineCommand.cs
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
using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CLARiNET
{
public static class CommandLineCommand
{
public static string CommandGet(string command)
{
if (String.IsNullOrEmpty(command))
{
string[] commands = Commands.COMMAND_LIST.Split("\n");
PrintCommand(commands);
Console.WriteLine("Enter the number that identifies the CLARiNET Command (1 - " + commands.Length + "):\n");
command = Console.ReadLine().Trim().ToUpper();
Console.WriteLine("");
}
return command;
}
public static string CommandValidate(string command)
{
// Ensure Command is uppercase.
if (command != null)
{
command = command.Trim().ToUpper();
}
int ndx = 0;
if (int.TryParse(command, out ndx))
{
string[] commands = Commands.COMMAND_LIST.Split("\n");
command = commands[ndx - 1];
}
// Check for valid commands
switch (command.ToEnum<Command>())
{
case Command.CLAR_UPLOAD:
case Command.CLAR_DOWNLOAD:
case Command.DRIVE_UPLOAD:
case Command.DRIVE_TRASH:
case Command.PHOTO_DOWNLOAD:
case Command.PHOTO_UPLOAD:
case Command.DOCUMENT_UPLOAD:
case Command.CANDIDATE_ATTACHMENT_UPLOAD:
break;
default:
throw new Exception("Invalid command. Please use --help for a list of valid commands.");
}
Console.WriteLine("\n\nCommand: " + command + "\n");
return command;
}
public static void PrintCommand(string[] commands)
{
string[] commandName = new string[3];
string colFormat = "{0,-35} {1,-35} {2,-35}\n";
Console.WriteLine("-- Commands --\n");
for (int ndx = 0; ndx < commands.Length; ndx++)
{
if (ndx > 0 && ndx % 3 == 0)
{
Console.Write(colFormat, commandName[0], commandName[1], commandName[2]);
commandName = new string[3];
}
if (commandName[0] == null)
{
commandName[0] = ndx + 1 + ") " + commands[ndx];
}
else
{
if (commandName[1] == null)
{
commandName[1] = ndx + 1 + ") " + commands[ndx];
}
else
{
commandName[2] = ndx + 1 + ") " + commands[ndx];
}
}
}
if (commandName[0] != null)
{
Console.Write(colFormat, commandName[0], commandName[1], commandName[2]);
}
Console.WriteLine("\n");
}
}
}