-
Notifications
You must be signed in to change notification settings - Fork 261
Expand file tree
/
Copy pathProgram.cs
More file actions
49 lines (42 loc) · 1.42 KB
/
Copy pathProgram.cs
File metadata and controls
49 lines (42 loc) · 1.42 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
// 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;
[Command(
UnrecognizedArgumentHandling = UnrecognizedArgumentHandling.StopParsingAndCollect,
AllowArgumentSeparator = true)]
public class Program
{
public static int Main(string[] args) => CommandLineApplication.Execute<Program>(args);
[Option("-m", Description = "Show time in milliseconds")]
public bool Milliseconds { get; }
public string[] RemainingArguments { get; } // = { "ls", "-a", "-l" }
private void OnExecute()
{
var timer = Stopwatch.StartNew();
if (RemainingArguments != null && RemainingArguments.Length > 0)
{
var process = new Process
{
StartInfo =
{
FileName = RemainingArguments[0],
Arguments = ArgumentEscaper.EscapeAndConcatenate(RemainingArguments.Skip(1)),
}
};
process.Start();
process.WaitForExit();
}
timer.Stop();
if (Milliseconds)
{
Console.WriteLine($"Time = {timer.Elapsed.TotalMilliseconds} ms");
}
else
{
Console.WriteLine($"Time = {timer.Elapsed.TotalSeconds}s");
}
}
}