-
Notifications
You must be signed in to change notification settings - Fork 6
/
Options.cs
63 lines (54 loc) · 2.28 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
using System.Linq;
using System.Collections.Generic;
using System;
using CommandLine;
using CommandLine.Text;
namespace UninstallRelatedProducts
{
/// <summary>
/// Contains command-line options
/// </summary>
public class Options : CommandLineOptionsBase
{
[Option(null, "upgradecode", Required = true, HelpText = "Upgrade code of the products to uninstall.")]
public string UpgradeCode { get; set; }
[Option(null, "peruseronly", DefaultValue = false,
HelpText = "Whether to only uninstall per-user products. " +
"If not specified, both per-user and per-machine products will be uninstalled.")]
public bool PerUserOnly { get; set; }
[Option(null, "maxversion",
HelpText = "Maximum product version to uninstall. " +
"Products with a version greater than this number will be skipped. " +
"If not specified, all related products will be uninstalled.")]
public string MaxVersion { get; set; }
[Option(null, "log", HelpText = "Path to a log file to write progress information.")]
public string LogFilePath { get; set; }
[Option(null, "quiet", DefaultValue = false, HelpText = "Quiet mode, no user interaction")]
public bool Silent { get; set; }
[HelpOption]
public string GetUsage()
{
return HelpText.AutoBuild(this, c => HelpText.DefaultParsingErrorsHandler(this, c));
}
/// <summary>
/// Parse command-line arguments into an <see cref="Options"/> instance.
/// </summary>
/// <param name="args">
/// Command-line arguments to parse, not null
/// </param>
/// <returns>
/// <see cref="Options"/> containing the parsed arguments, never null.
/// </returns>
public static Options Parse(string[] args)
{
if (args == null)
throw new ArgumentNullException("args");
var options = new Options();
if (!CommandLineParser.Default.ParseArguments(args, options))
{
throw new ArgumentException("Invalid command-line arguments", "args");
}
return options;
}
}
}