Skip to content

Commit 820ea75

Browse files
committed
Added support for --info
1 parent 09f74fc commit 820ea75

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

src/Dotnet.Script/Program.cs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ private static int Wain(string[] args)
7070

7171
app.HelpOption("-? | -h | --help");
7272

73-
app.VersionOption("-v | --version", GetVersionInfo);
73+
app.VersionOption("-v | --version", GetVersion());
74+
75+
var infoOption = app.Option("--info", "Displays environmental information", CommandOptionType.NoValue);
7476

7577
app.Command("eval", c =>
7678
{
@@ -127,6 +129,13 @@ private static int Wain(string[] args)
127129
app.OnExecute(async () =>
128130
{
129131
int exitCode = 0;
132+
133+
if (infoOption.HasValue())
134+
{
135+
Console.Write(GetEnvironmentInfo());
136+
return 0;
137+
}
138+
130139
if (!string.IsNullOrWhiteSpace(file.Value))
131140
{
132141
var optimizationLevel = OptimizationLevel.Debug;
@@ -207,18 +216,21 @@ private static Task<int> Run(bool debugMode, ScriptContext context)
207216
return runner.Execute<int>(context);
208217
}
209218

210-
private static string GetVersionInfo()
219+
private static string GetEnvironmentInfo()
211220
{
212-
StringBuilder sb = new StringBuilder();
213-
var versionAttribute = typeof(Program).GetTypeInfo().Assembly.GetCustomAttributes<AssemblyInformationalVersionAttribute>().SingleOrDefault();
214-
sb.AppendLine($"Version : {versionAttribute?.InformationalVersion}");
221+
StringBuilder sb = new StringBuilder();
222+
sb.AppendLine($"Version : {GetVersion()}");
215223
sb.AppendLine($"Install location : {ScriptEnvironment.Default.InstallLocation}");
216224
sb.AppendLine($"Target framework : {ScriptEnvironment.Default.TargetFramework}");
217225
sb.AppendLine($"Platform identifier : {ScriptEnvironment.Default.PlatformIdentifier}");
218226
sb.AppendLine($"Runtime identifier : {ScriptEnvironment.Default.RuntimeIdentifier}");
219-
return sb.ToString();
227+
return sb.ToString();
228+
}
220229

221-
230+
private static string GetVersion()
231+
{
232+
var versionAttribute = typeof(Program).GetTypeInfo().Assembly.GetCustomAttributes<AssemblyInformationalVersionAttribute>().SingleOrDefault();
233+
return versionAttribute?.InformationalVersion;
222234
}
223235

224236
private static ScriptCompiler GetScriptCompiler(bool debugMode)

0 commit comments

Comments
 (0)