1
1
using Dotnet . Script . Core ;
2
2
using Dotnet . Script . Core . Commands ;
3
3
using Dotnet . Script . Core . Versioning ;
4
- using Dotnet . Script . DependencyModel . Context ;
5
4
using Dotnet . Script . DependencyModel . Environment ;
6
5
using Dotnet . Script . DependencyModel . Logging ;
7
- using Dotnet . Script . DependencyModel . Runtime ;
8
6
using McMaster . Extensions . CommandLineUtils ;
9
7
using Microsoft . CodeAnalysis ;
10
8
using Microsoft . CodeAnalysis . Scripting ;
11
9
using Microsoft . CodeAnalysis . Scripting . Hosting ;
12
- using Microsoft . CodeAnalysis . Text ;
13
10
using System ;
14
- using System . Collections . Generic ;
15
11
using System . IO ;
16
12
using System . Linq ;
17
13
using System . Threading . Tasks ;
@@ -206,61 +202,34 @@ private static int Wain(string[] args)
206
202
207
203
if ( scriptFile . HasValue )
208
204
{
205
+ if ( interactive . HasValue ( ) )
206
+ {
207
+ return await RunInteractiveWithSeed ( file . Value , logFactory , app . RemainingArguments . Concat ( argsAfterDoubleHyphen ) . ToArray ( ) , packageSources . Values ? . ToArray ( ) ) ;
208
+ }
209
209
210
- // if (File.Exists(file.Value))
211
- // {
212
- if ( interactive . HasValue ( ) )
213
- {
214
- return await RunInteractiveWithSeed ( file . Value , logFactory , app . RemainingArguments . Concat ( argsAfterDoubleHyphen ) . ToArray ( ) , packageSources . Values ? . ToArray ( ) ) ;
215
- }
216
-
217
- var fileCommandOptions = new ExecuteScriptCommandOptions
218
- (
219
- new ScriptFile ( file . Value ) ,
220
- app . RemainingArguments . Concat ( argsAfterDoubleHyphen ) . ToArray ( ) ,
221
- optimizationLevel ,
222
- packageSources . Values ? . ToArray ( ) ,
223
- interactive . HasValue ( ) ,
224
- nocache . HasValue ( )
225
- ) ;
226
-
227
- var fileCommand = new ExecuteScriptCommand ( ScriptConsole . Default , logFactory ) ;
228
- return await fileCommand . Run < int , CommandLineScriptGlobals > ( fileCommandOptions ) ;
210
+ var fileCommandOptions = new ExecuteScriptCommandOptions
211
+ (
212
+ new ScriptFile ( file . Value ) ,
213
+ app . RemainingArguments . Concat ( argsAfterDoubleHyphen ) . ToArray ( ) ,
214
+ optimizationLevel ,
215
+ packageSources . Values ? . ToArray ( ) ,
216
+ interactive . HasValue ( ) ,
217
+ nocache . HasValue ( )
218
+ ) ;
229
219
230
- // }
231
- // else
232
- // {
233
- // if (IsHttpUri(file.Value))
234
- // {
235
- // var downloader = new ScriptDownloader();
236
- // var code = await downloader.Download(file.Value);
237
- // return await RunCode(code, !nocache.HasValue(), logFactory, optimizationLevel, args, Directory.GetCurrentDirectory(), packageSources.Values?.ToArray());
238
- // }
239
- // else
240
- // {
241
- // throw new Exception($"Couldn't find file '{file}'");
242
- // }
243
- // }
244
- }
220
+ var fileCommand = new ExecuteScriptCommand ( ScriptConsole . Default , logFactory ) ;
221
+ return await fileCommand . Run < int , CommandLineScriptGlobals > ( fileCommandOptions ) ;
222
+ }
245
223
else
246
224
{
247
225
await RunInteractive ( ! nocache . HasValue ( ) , logFactory , packageSources . Values ? . ToArray ( ) ) ;
248
226
}
249
227
return exitCode ;
250
228
} ) ;
251
229
252
-
253
230
return app . Execute ( argsBeforeDoubleHyphen ) ;
254
231
}
255
232
256
-
257
-
258
- private static bool IsHttpUri ( string fileName )
259
- {
260
- return Uri . TryCreate ( fileName , UriKind . Absolute , out Uri uriResult )
261
- && ( uriResult . Scheme == Uri . UriSchemeHttp || uriResult . Scheme == Uri . UriSchemeHttps ) ;
262
- }
263
-
264
233
private static async Task < int > RunInteractive ( bool useRestoreCache , LogFactory logFactory , string [ ] packageSources )
265
234
{
266
235
var options = new ExecuteInteractiveCommandOptions ( null , Array . Empty < string > ( ) , packageSources ) ;
@@ -274,27 +243,5 @@ private async static Task<int> RunInteractiveWithSeed(string file, LogFactory lo
274
243
await new ExecuteInteractiveCommand ( ScriptConsole . Default , logFactory ) . Execute ( options ) ;
275
244
return 0 ;
276
245
}
277
-
278
-
279
- private static Task < int > RunCode ( string code , bool useRestoreCache , LogFactory logFactory , OptimizationLevel optimizationLevel , IEnumerable < string > args , string currentWorkingDirectory , string [ ] packageSources )
280
- {
281
- var sourceText = SourceText . From ( code ) ;
282
- var context = new ScriptContext ( sourceText , currentWorkingDirectory ?? Directory . GetCurrentDirectory ( ) , args , null , optimizationLevel , ScriptMode . Eval , packageSources : packageSources ) ;
283
- return Run ( useRestoreCache , logFactory , context ) ;
284
- }
285
-
286
- private static Task < int > Run ( bool useRestoreCache , LogFactory logFactory , ScriptContext context )
287
- {
288
- var compiler = GetScriptCompiler ( useRestoreCache , logFactory ) ;
289
- var runner = new ScriptRunner ( compiler , logFactory , ScriptConsole . Default ) ;
290
- return runner . Execute < int > ( context ) ;
291
- }
292
-
293
- private static ScriptCompiler GetScriptCompiler ( bool useRestoreCache , LogFactory logFactory )
294
- {
295
- var runtimeDependencyResolver = new RuntimeDependencyResolver ( logFactory , useRestoreCache ) ;
296
- var compiler = new ScriptCompiler ( logFactory , runtimeDependencyResolver ) ;
297
- return compiler ;
298
- }
299
246
}
300
247
}
0 commit comments