forked from scriptcs/scriptcs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScriptCsArgs.cs
More file actions
111 lines (89 loc) · 4.14 KB
/
ScriptCsArgs.cs
File metadata and controls
111 lines (89 loc) · 4.14 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
using System;
using System.Collections.Generic;
using PowerArgs;
using ScriptCs.Contracts;
namespace ScriptCs
{
[ArgExample(
"scriptcs server.csx -logLevel debug",
"Executes the 'server.csx' script and displays detailed log messages. Useful for debugging.")]
public class ScriptCsArgs
{
[ArgDescription("Launch REPL mode when running script. To just launch REPL, simply omit the 'script' argument.")]
public bool Repl { get; set; }
[ArgPosition(0)]
[ArgShortcut("script")]
[ArgDescription("Script file name, must be specified first")]
public string ScriptName { get; set; }
[ArgShortcut("e")]
[ArgDescription("Code to immediately evaluate")]
public string Eval { get; set; }
[ArgShortcut("?")]
[ArgDescription("Displays help")]
public bool Help { get; set; }
[ArgDescription("Emits PDB symbols allowing for attaching a Visual Studio debugger")]
public bool Debug { get; set; }
[ArgDescription("Flag which determines whether to run in memory or from a .dll")]
public bool Cache { get; set; }
[ArgShortcut("log")]
[ArgDescription("Flag which defines the log level used.")]
public LogLevel? LogLevel { get; set; }
[ArgDescription("Installs and restores packages which are specified in packages.config")]
[ArgShortcut("i")]
public string Install { get; set; }
[ArgShortcut("g")]
[ArgDescription("Installs and restores global packages which are specified in packages.config")]
public bool Global { get; set; }
[ArgDescription("Creates a packages.config file based on the packages directory")]
public bool Save { get; set; }
[ArgDescription("Cleans installed packages from working directory")]
public bool Clean { get; set; }
[ArgShortcut("pre")]
[ArgDescription("Allows installation of packages' prelease versions")]
public bool AllowPreRelease { get; set; }
[ArgDescription("Outputs version information")]
public bool Version { get; set; }
[ArgDescription("Watch the script file and reload it when changed")]
public bool Watch { get; set; }
[ArgDescription("Specify modules to load")]
public string Modules { get; set; }
[ArgDescription("Defines config file name")]
public string Config { get; set; }
[ArgDescription("Defines the version of the package to install. Used in conjunction with -install")]
public string PackageVersion { get; set; }
[ArgDescription("Write all console output to the specified file")]
public string Output { get; set; }
public static ScriptCsArgs Parse(string[] args)
{
Guard.AgainstNullArgument("args", args);
var curatedArgs = new List<string>();
string implicitPackageVersion = null;
for (var index = 0; index < args.Length; ++index)
{
if (index < args.Length - 2 &&
(string.Equals(args[index], "-install", StringComparison.OrdinalIgnoreCase) ||
string.Equals(args[index], "-i", StringComparison.OrdinalIgnoreCase)) &&
!args[index + 1].StartsWith("-", StringComparison.Ordinal) &&
!args[index + 2].StartsWith("-", StringComparison.Ordinal))
{
curatedArgs.Add(args[index]);
curatedArgs.Add(args[index + 1]);
implicitPackageVersion = args[index + 2];
index += 2;
}
else
{
curatedArgs.Add(args[index]);
}
}
var scriptCsArgs = Args.Parse<ScriptCsArgs>(curatedArgs.ToArray());
scriptCsArgs.PackageVersion = scriptCsArgs.PackageVersion ?? implicitPackageVersion;
return scriptCsArgs;
}
public static string GetUsage()
{
return ArgUsage.GetUsage<ScriptCsArgs>(
null, new ArgUsageOptions { ShowPosition = false, ShowType = false, });
}
}
}