forked from dubasdey/File-Splitter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommandLine.cs
More file actions
142 lines (127 loc) · 5.83 KB
/
Copy pathCommandLine.cs
File metadata and controls
142 lines (127 loc) · 5.83 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.Text;
using System.Collections.Generic;
namespace FileSplitter {
/// <summary>
/// Commandline parser
/// </summary>
internal class CommandLine {
internal const int SizeParameterIndex = 0;
internal const int UnitParameterIndex = 2;
internal const string SplitParameterCmd = "split";
internal const string DeleteParameterCmd = "d";
internal const string FormatParameterCmd = "f";
internal const string DestinationFolderParameterCmd = "df";
internal const string LogFileParameterCmd = "lf";
internal const string UnitBytes = "b";
internal const string UnitKiloBytes = "kb";
internal const string UnitMegaBytes = "mb";
internal const string UnitGigaBytes = "gb";
internal const string UnitLines = "l";
/// <summary>
/// Parameters collection
/// </summary>
private Dictionary<string, List<string>> parameters = new Dictionary<string, List<string>>();
/// <summary>
/// Parse arguments
/// </summary>
/// <param name="args">Command line arguments</param>
public void parseArguments(string[] args) {
parameters.Clear();
string lastKey = "";
foreach (String arg in args) {
if (arg.StartsWith("-")) {
lastKey = arg.Replace("-", "");
if (!parameters.ContainsKey(lastKey)) {
parameters.Add(lastKey, new List<string>());
}
} else {
parameters[lastKey].Add(arg);
}
}
}
/// <summary>
/// Check for key
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public Boolean hasKey(string key) {
return parameters.ContainsKey(key);
}
/// <summary>
/// Detect if key exists with parameters
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public Boolean hasParams(string key) {
return (parameters[key].Count > 0);
}
/// <summary>
/// Get params of key
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public List<string> getParamsOfKey(string key) {
return parameters[key];
}
/// <summary>
/// Get all parameters of key as string with spaces
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public String getParamsOfKeyAsString(string key) {
StringBuilder builder = new StringBuilder();
foreach (string s in parameters[key]) {
builder.Append(s).Append(" ");
}
return builder.ToString().TrimEnd();
}
/// <summary>
/// Prints usage help
/// </summary>
public void printUsageHelp() {
Console.WriteLine("Usage:");
Console.WriteLine($"fsplit -{SplitParameterCmd} <size> <unit> <filePath> [-{DeleteParameterCmd}] [-{FormatParameterCmd} <format>] [-{DestinationFolderParameterCmd} <folder>] [-{LogFileParameterCmd} <file>]");
Console.WriteLine();
Console.WriteLine("Parameter help:");
Console.WriteLine();
Console.WriteLine($"-{SplitParameterCmd}");
Console.WriteLine(" size Size of parts");
Console.WriteLine($" If size unit is '{UnitLines}' defines number of lines");
Console.WriteLine(" in other case the size in the selected unit");
Console.WriteLine();//TODO: Retrieve units from the SplitUnit Attributes
Console.WriteLine($" unit unit of size '{UnitBytes}' '{UnitKiloBytes} '{UnitMegaBytes}' '{UnitGigaBytes}' '{UnitLines}'");
Console.WriteLine($" {UnitBytes} - bytes");
Console.WriteLine($" {UnitKiloBytes} - Kilobytes");
Console.WriteLine($" {UnitMegaBytes} - megabytes");
Console.WriteLine($" {UnitGigaBytes} - gigabytes");
Console.WriteLine($" {UnitLines} - lines (based on endline detection)");
Console.WriteLine();
Console.WriteLine(" filePath Path of the file to be split.");
Console.WriteLine();
Console.WriteLine($" -{DeleteParameterCmd} Delete the original file if the process is done.");
Console.WriteLine();
Console.WriteLine($" -{DestinationFolderParameterCmd} <folder>");
Console.WriteLine(" Set destination folder for files.");
Console.WriteLine($" -{LogFileParameterCmd} <file>");
Console.WriteLine(" Set a file to store generated names.");
Console.WriteLine();
Console.WriteLine($" -{FormatParameterCmd} <format> Use a custom format using pattern replacements");
Console.WriteLine(" {0} the current part");
Console.WriteLine(" {1} number of parts");
Console.WriteLine();
}
}
}