Skip to content

Remove hardwired return type in ExecuteScriptCommand #725

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Dotnet.Script.Core/Commands/ExecuteScriptCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public async Task<TReturn> Run<TReturn, THost>(ExecuteScriptCommandOptions optio
return await DownloadAndRunCode<TReturn>(options);
}

var pathToLibrary = GetLibrary(options);
var pathToLibrary = GetLibrary<TReturn>(options);

var libraryOptions = new ExecuteLibraryCommandOptions(pathToLibrary, options.Arguments, options.NoCache)
{
Expand All @@ -50,7 +50,7 @@ private async Task<TReturn> DownloadAndRunCode<TReturn>(ExecuteScriptCommandOpti
return await new ExecuteCodeCommand(_scriptConsole, _logFactory).Execute<TReturn>(options);
}

private string GetLibrary(ExecuteScriptCommandOptions executeOptions)
private string GetLibrary<TReturn>(ExecuteScriptCommandOptions executeOptions)
{
var projectFolder = FileUtils.GetPathToScriptTempFolder(executeOptions.File.Path);
var executionCacheFolder = Path.Combine(projectFolder, "execution-cache");
Expand All @@ -70,7 +70,7 @@ private string GetLibrary(ExecuteScriptCommandOptions executeOptions)
AssemblyLoadContext = executeOptions.AssemblyLoadContext
#endif
};
new PublishCommand(_scriptConsole, _logFactory).Execute(options);
new PublishCommand(_scriptConsole, _logFactory).Execute<TReturn>(options);
if (hash != null)
{
File.WriteAllText(Path.Combine(executionCacheFolder, "script.sha256"), hash);
Expand Down
9 changes: 7 additions & 2 deletions src/Dotnet.Script.Core/Commands/PublishCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ public PublishCommand(ScriptConsole scriptConsole, LogFactory logFactory)
}

public void Execute(PublishCommandOptions options)
{
Execute<int>(options);
}

public void Execute<TReturn>(PublishCommandOptions options)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense thanks. It's technically a breaking change - could you please keep the old one too and add the generic as a new overload?

It does not matter that much but I would like to have backwards compatibility in the public API unless we rev up major version

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you're right, should be an overload, backwards compatibility is very important. Sure, I'll add it

{
var absoluteFilePath = options.File.Path;

Expand All @@ -41,11 +46,11 @@ public void Execute(PublishCommandOptions options)

if (options.PublishType == PublishType.Library)
{
publisher.CreateAssembly<int, CommandLineScriptGlobals>(context, _logFactory, options.LibraryName);
publisher.CreateAssembly<TReturn, CommandLineScriptGlobals>(context, _logFactory, options.LibraryName);
}
else
{
publisher.CreateExecutable<int, CommandLineScriptGlobals>(context, _logFactory, options.RuntimeIdentifier, options.LibraryName);
publisher.CreateExecutable<TReturn, CommandLineScriptGlobals>(context, _logFactory, options.RuntimeIdentifier, options.LibraryName);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Dotnet.Script/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ private static int Wain(string[] args)
);

var logFactory = CreateLogFactory(verbosity.Value(), debugMode.HasValue());
new PublishCommand(ScriptConsole.Default, logFactory).Execute(options);
new PublishCommand(ScriptConsole.Default, logFactory).Execute<int>(options);
return 0;
});
});
Expand Down