-
Notifications
You must be signed in to change notification settings - Fork 261
Expand file tree
/
Copy pathProgram.cs
More file actions
52 lines (45 loc) · 1.53 KB
/
Copy pathProgram.cs
File metadata and controls
52 lines (45 loc) · 1.53 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
// Copyright (c) Nate McMaster.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Diagnostics;
using System.Linq;
using McMaster.Extensions.CommandLineUtils;
public class Program
{
public static int Main(string[] args)
{
var app = new CommandLineApplication
{
AllowArgumentSeparator = true,
UnrecognizedArgumentHandling = UnrecognizedArgumentHandling.StopParsingAndCollect,
};
var showMilliseconds = app.Option<int>("-m", "Show time in milliseconds", CommandOptionType.NoValue);
app.OnExecute(() =>
{
var timer = Stopwatch.StartNew();
if (app.RemainingArguments != null && app.RemainingArguments.Count > 0)
{
var process = new Process
{
StartInfo =
{
FileName = app.RemainingArguments[0],
Arguments = ArgumentEscaper.EscapeAndConcatenate(app.RemainingArguments.Skip(1)),
}
};
process.Start();
process.WaitForExit();
}
timer.Stop();
if (showMilliseconds.HasValue())
{
Console.WriteLine($"Time = {timer.Elapsed.TotalMilliseconds} ms");
}
else
{
Console.WriteLine($"Time = {timer.Elapsed.TotalSeconds}s");
}
});
return app.Execute(args);
}
}