forked from KSP-CKAN/CKAN-cmdline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOptions.cs
235 lines (179 loc) · 7.81 KB
/
Options.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
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
using System.Collections.Generic;
using CommandLine;
namespace CKAN.CmdLine
{
// Look, parsing options is so easy and beautiful I made
// it into a special class for you to admire!
public class Options
{
public string action { get; set; }
public object options { get; set; }
/// <summary>
/// Returns an options object on success. Prints a default help
/// screen and throws a BadCommandKraken on failure.
/// </summary>
public Options(string[] args)
{
Parser.Default.ParseArgumentsStrict
(
args, new Actions(), (verb, suboptions) =>
{
action = verb;
options = suboptions;
},
delegate
{
throw (new BadCommandKraken());
}
);
}
}
// Actions supported by our client go here.
// TODO: Figure out how to do per action help screens.
internal class Actions
{
[VerbOption("gui", HelpText = "Start the CKAN GUI")]
public GuiOptions GuiOptions { get; set; }
[VerbOption("gui-with-console", HelpText = "Start the CKAN GUI with the console visible")]
public GuiOptions GuiConsoleOptions { get; set; }
[VerbOption("search", HelpText = "Search for mods")]
public SearchOptions SearchOptions { get; set; }
[VerbOption("upgrade", HelpText = "Upgrade an installed mod")]
public UpgradeOptions Upgrade { get; set; }
[VerbOption("update", HelpText = "Update list of available mods")]
public UpdateOptions Update { get; set; }
[VerbOption("available", HelpText = "List available mods")]
public AvailableOptions Available { get; set; }
[VerbOption("install", HelpText = "Install a KSP mod")]
public InstallOptions Install { get; set; }
[VerbOption("remove", HelpText = "Remove an installed mod")]
public RemoveOptions Remove { get; set; }
[VerbOption("scan", HelpText = "Scan for manually installed KSP mods")]
public ScanOptions Scan { get; set; }
[VerbOption("list", HelpText = "List installed modules")]
public ListOptions List { get; set; }
[VerbOption("show", HelpText = "Show information about a mod")]
public ShowOptions Show { get; set; }
[VerbOption("clean", HelpText = "Clean away downloaded files from the cache")]
public CleanOptions Clean { get; set; }
[VerbOption("repair", HelpText = "Attempt various automatic repairs")]
public SubCommandOptions Repair { get; set; }
[VerbOption("repo", HelpText = "Manage CKAN repositories")]
public SubCommandOptions KSP { get; set; }
[VerbOption("ksp", HelpText = "Manage KSP installs")]
public SubCommandOptions Repo { get; set; }
[VerbOption("version", HelpText = "Show the version of the CKAN client being used.")]
public VersionOptions Version { get; set; }
}
// Options common to all classes.
public class CommonOptions
{
[Option('v', "verbose", DefaultValue = false, HelpText = "Show more of what's going on when running.")]
public bool Verbose { get; set; }
[Option('d', "debug", DefaultValue = false, HelpText = "Show debugging level messages. Implies verbose")]
public bool Debug { get; set; }
[Option("ksp", DefaultValue = null, HelpText = "KSP install to use")]
public string KSP { get; set; }
[Option("kspdir", DefaultValue = null, HelpText = "KSP dir to use")]
public string KSPdir { get; set; }
[Option("net-useragent", DefaultValue = null, HelpText = "Set the default user-agent string for HTTP requests")]
public string NetUserAgent { get; set; }
[Option("headless", DefaultValue = null, HelpText = "Set to disable all prompts")]
public bool Headless { get; set; }
[Option("asroot", DefaultValue = null, HelpText = "Allows CKAN to run as root on Linux- based systems")]
public bool AsRoot { get; set; }
}
/// <summary>
/// For things which are subcommands ('ksp', 'repair' etc), we just grab a list
/// we can pass on.
/// </summary>
public class SubCommandOptions : CommonOptions
{
[ValueList(typeof(List<string>))]
public List<string> options { get; set; }
}
// Each action defines its own options that it supports.
// Don't forget to cast to this type when you're processing them later on.
internal class InstallOptions : CommonOptions
{
[OptionArray('c', "ckanfiles", HelpText = "Local CKAN files to process")]
public string[] ckan_files { get; set; }
[Option("no-recommends", HelpText = "Do not install recommended modules")]
public bool no_recommends { get; set; }
[Option("with-suggests", HelpText = "Install suggested modules")]
public bool with_suggests { get; set; }
[Option("with-all-suggests", HelpText = "Install suggested modules all the way down")]
public bool with_all_suggests { get; set; }
// TODO: How do we provide helptext on this?
[ValueList(typeof (List<string>))]
public List<string> modules { get; set; }
}
internal class UpgradeOptions : CommonOptions
{
[Option('c', "ckanfile", HelpText = "Local CKAN file to process")]
public string ckan_file { get; set; }
[Option("no-recommends", HelpText = "Do not install recommended modules")]
public bool no_recommends { get; set; }
[Option("with-suggests", HelpText = "Install suggested modules")]
public bool with_suggests { get; set; }
[Option("with-all-suggests", HelpText = "Install suggested modules all the way down")]
public bool with_all_suggests { get; set; }
[Option("all", HelpText = "Upgrade all available updated modules")]
public bool upgrade_all { get; set; }
// TODO: How do we provide helptext on this?
[ValueList(typeof (List<string>))]
public List<string> modules { get; set; }
}
internal class ScanOptions : CommonOptions
{
}
internal class ListOptions : CommonOptions
{
[Option("porcelain", HelpText = "Dump raw list of modules, good for shell scripting")]
public bool porcelain { get; set; }
}
internal class VersionOptions : CommonOptions
{
}
internal class CleanOptions : CommonOptions
{
}
internal class AvailableOptions : CommonOptions
{
}
internal class GuiOptions : CommonOptions
{
[Option("show-console", HelpText = "Shows the console while running the GUI")]
public bool ShowConsole { get; set; }
}
internal class UpdateOptions : CommonOptions
{
// This option is really meant for devs testing their CKAN-meta forks.
[Option('r', "repo", HelpText = "CKAN repository to use (experimental!)")]
public string repo { get; set; }
[Option("all", HelpText = "Upgrade all available updated modules")]
public bool update_all { get; set; }
[Option("list-changes", DefaultValue = false, HelpText = "List new and removed modules")]
public bool list_changes { get; set; }
}
internal class RemoveOptions : CommonOptions
{
[Option("re", HelpText = "Parse arguments as regular expressions")]
public bool regex { get; set; }
[ValueList(typeof(List<string>))]
public List<string> modules { get; set; }
}
internal class ShowOptions : CommonOptions
{
[ValueOption(0)]
public string Modname { get; set; }
}
internal class ClearCacheOptions : CommonOptions
{
}
internal class SearchOptions : CommonOptions
{
[ValueOption(0)]
public string search_term { get; set; }
}
}