1
1
using System ;
2
+ using System . Collections . Generic ;
3
+ using System . Diagnostics ;
2
4
using System . IO ;
3
5
using GitCredentialManager . Interop . Linux ;
4
6
using GitCredentialManager . Interop . MacOS ;
@@ -15,7 +17,7 @@ public interface ICommandContext : IDisposable
15
17
/// <summary>
16
18
/// Absolute path the application entry executable.
17
19
/// </summary>
18
- string ApplicationPath { get ; }
20
+ string ApplicationPath { get ; set ; }
19
21
20
22
/// <summary>
21
23
/// Absolute path to the Git Credential Manager installation directory.
@@ -47,6 +49,11 @@ public interface ICommandContext : IDisposable
47
49
/// </summary>
48
50
ITrace Trace { get ; }
49
51
52
+ /// <summary>
53
+ /// Application TRACE2 tracing system.
54
+ /// </summary>
55
+ ITrace2 Trace2 { get ; }
56
+
50
57
/// <summary>
51
58
/// File system abstraction (exists mainly for testing).
52
59
/// </summary>
@@ -78,12 +85,11 @@ public interface ICommandContext : IDisposable
78
85
/// </summary>
79
86
public class CommandContext : DisposableObject , ICommandContext
80
87
{
81
- public CommandContext ( string appPath , string installDir )
88
+ public CommandContext ( string [ ] argv )
82
89
{
83
- EnsureArgument . NotNullOrWhiteSpace ( appPath , nameof ( appPath ) ) ;
84
-
85
- ApplicationPath = appPath ;
86
- InstallationDirectory = installDir ;
90
+ var applicationStartTime = DateTimeOffset . UtcNow ;
91
+ ApplicationPath = GetEntryApplicationPath ( ) ;
92
+ InstallationDirectory = GetInstallationDirectory ( ) ;
87
93
88
94
Streams = new StandardStreams ( ) ;
89
95
Trace = new Trace ( ) ;
@@ -139,6 +145,7 @@ public CommandContext(string appPath, string installDir)
139
145
throw new PlatformNotSupportedException ( ) ;
140
146
}
141
147
148
+ Trace2 = new Trace2 ( Environment , Settings . GetTrace2Settings ( ) , argv , applicationStartTime ) ;
142
149
HttpClientFactory = new HttpClientFactory ( FileSystem , Trace , Settings , Streams ) ;
143
150
CredentialStore = new CredentialStore ( this ) ;
144
151
}
@@ -177,7 +184,7 @@ private static string GetGitPath(IEnvironment environment, IFileSystem fileSyste
177
184
178
185
#region ICommandContext
179
186
180
- public string ApplicationPath { get ; }
187
+ public string ApplicationPath { get ; set ; }
181
188
182
189
public string InstallationDirectory { get ; }
183
190
@@ -191,6 +198,8 @@ private static string GetGitPath(IEnvironment environment, IFileSystem fileSyste
191
198
192
199
public ITrace Trace { get ; }
193
200
201
+ public ITrace2 Trace2 { get ; }
202
+
194
203
public IFileSystem FileSystem { get ; }
195
204
196
205
public ICredentialStore CredentialStore { get ; }
@@ -214,5 +223,17 @@ protected override void ReleaseManagedResources()
214
223
}
215
224
216
225
#endregion
226
+
227
+ public static string GetEntryApplicationPath ( )
228
+ {
229
+ return PlatformUtils . GetNativeEntryPath ( ) ??
230
+ Process . GetCurrentProcess ( ) . MainModule ? . FileName ??
231
+ System . Environment . GetCommandLineArgs ( ) [ 0 ] ;
232
+ }
233
+
234
+ public static string GetInstallationDirectory ( )
235
+ {
236
+ return AppContext . BaseDirectory ;
237
+ }
217
238
}
218
239
}
0 commit comments