Skip to content
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

(consoleapp) Remove custom IConsole implementations #456

Merged
merged 1 commit into from
Apr 12, 2024
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
8 changes: 0 additions & 8 deletions src/Perlang.ConsoleApp/IPerlangConsole.cs

This file was deleted.

117 changes: 0 additions & 117 deletions src/Perlang.ConsoleApp/PerlangConsole.cs

This file was deleted.

56 changes: 12 additions & 44 deletions src/Perlang.ConsoleApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Collections.Generic;
using System.CommandLine;
using System.CommandLine.Builder;
using System.CommandLine.IO;
using System.CommandLine.NamingConventionBinder;
using System.CommandLine.Parsing;
using System.IO;
Expand All @@ -26,13 +25,6 @@ namespace Perlang.ConsoleApp
{
public class Program
{
private static readonly ISet<string> ReplCommands = new HashSet<string>(new List<string>
{
"exit",
"help",
"quit"
}.Select(s => "/" + s));

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No longer used, should rightfully have been removed already in #446.

internal enum ExitCodes
{
/// <summary>
Expand Down Expand Up @@ -103,21 +95,6 @@ internal enum ExitCodes
/// <param name="args">The command line arguments.</param>
/// <returns>Zero if the program executed successfully; non-zero otherwise.</returns>
public static int Main(string[] args)
{
return MainWithCustomConsole(args, console: new PerlangConsole());
}

/// <summary>
/// Entry point for `perlang`, with the possibility to override the console streams (stdin, stdout, stderr).
///
/// This constructor is typically used from tests, wishing to intercept the output to stdout and/or stderr.
/// </summary>
/// <param name="args">The command line arguments.</param>
/// <param name="console">A custom `IConsole` implementation to use. May be null, in which case the standard
/// streams of the calling process will be used.</param>
/// <returns>Zero if the program executed successfully; non-zero otherwise.</returns>
// TODO: Replace IConsole here with interface which is "Perlang string-aware", so we can delegate to libc write() instead of using Console.WriteLine.
public static int MainWithCustomConsole(string[] args, IPerlangConsole console)
{
var versionOption = new Option<bool>(new[] { "--version", "-v" }, "Show version information");
var detailedVersionOption = new Option<bool>("-V", "Show detailed version information");
Expand Down Expand Up @@ -169,18 +146,18 @@ public static int MainWithCustomConsole(string[] args, IPerlangConsole console)
{
if (parseResult.HasOption(versionOption))
{
console.Out.WriteLine(CommonConstants.InformationalVersion);
Console.Out.WriteLine(CommonConstants.InformationalVersion);
return Task.FromResult(0);
}

if (parseResult.HasOption(detailedVersionOption))
{
console.Out.WriteLine($"Perlang {CommonConstants.InformationalVersion} (built from git commit {CommonConstants.GitCommit}) on .NET {Environment.Version}");
console.Out.WriteLine();
console.Out.WriteLine($" Number of detected (v)CPUs: {Environment.ProcessorCount}");
console.Out.WriteLine($" Running in 64-bit mode: {Environment.Is64BitProcess}");
console.Out.WriteLine($" Operating system info: {Environment.OSVersion.VersionString}");
console.Out.WriteLine();
Console.Out.WriteLine($"Perlang {CommonConstants.InformationalVersion} (built from git commit {CommonConstants.GitCommit}) on .NET {Environment.Version}");
Console.Out.WriteLine();
Console.Out.WriteLine($" Number of detected (v)CPUs: {Environment.ProcessorCount}");
Console.Out.WriteLine($" Running in 64-bit mode: {Environment.Is64BitProcess}");
Console.Out.WriteLine($" Operating system info: {Environment.OSVersion.VersionString}");
Console.Out.WriteLine();

return Task.FromResult(0);
}
Expand All @@ -191,7 +168,7 @@ public static int MainWithCustomConsole(string[] args, IPerlangConsole console)

new Program(
replMode: true,
standardOutputHandler: console.WriteStdoutLine,
standardOutputHandler: Console.WriteLine,
disabledWarningsAsErrors: disabledWarningsAsErrorsList
).ParseAndPrint(source);

Expand All @@ -209,18 +186,9 @@ public static int MainWithCustomConsole(string[] args, IPerlangConsole console)
{
string scriptName = parseResult.GetValueForArgument(scriptNameArgument);

// Console.Out.WriteLine(parseResult.Tokens);
// Console.Out.WriteLine(parseResult.GetValueForArgument(scriptArguments));
//
// if (parseResult.Tokens.Count != 1)
// {
// Console.Error.WriteLine("ERROR: When the -c option is used, no script arguments can be provided since the Perlang script/program will not get executed");
// return Task.FromResult(1);
// }

var program = new Program(
replMode: false,
standardOutputHandler: console.WriteStdoutLine,
standardOutputHandler: Console.WriteLine,
disabledWarningsAsErrors: disabledWarningsAsErrorsList,
experimentalCompilation: PerlangMode.ExperimentalCompilation
);
Expand All @@ -237,7 +205,7 @@ public static int MainWithCustomConsole(string[] args, IPerlangConsole console)
{
var program = new Program(
replMode: false,
standardOutputHandler: console.WriteStdoutLine,
standardOutputHandler: Console.WriteLine,
disabledWarningsAsErrors: disabledWarningsAsErrorsList,
experimentalCompilation: PerlangMode.ExperimentalCompilation
);
Expand All @@ -251,7 +219,7 @@ public static int MainWithCustomConsole(string[] args, IPerlangConsole console)
var program = new Program(
replMode: false,
arguments: remainingArguments,
standardOutputHandler: console.WriteStdoutLine,
standardOutputHandler: Console.WriteLine,
disabledWarningsAsErrors: disabledWarningsAsErrorsList,
experimentalCompilation: PerlangMode.ExperimentalCompilation
);
Expand Down Expand Up @@ -283,7 +251,7 @@ public static int MainWithCustomConsole(string[] args, IPerlangConsole console)
return new CommandLineBuilder(rootCommand)
.UseHelp()
.Build()
.Invoke(args, console);
.Invoke(args);
}

internal Program(
Expand Down
7 changes: 0 additions & 7 deletions src/Perlang.Stdlib/Stdlib/Libc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,6 @@ internal static partial class Internal
#endif
internal static unsafe partial int memcmp(byte* b1, byte* b2, uint count);

#if _WINDOWS
[LibraryImport("ucrtbase", EntryPoint = "_write")]
#else // POSIX
[LibraryImport("libc", SetLastError = true)]
#endif
internal static partial int write(int fd, IntPtr s, int count);

#if _WINDOWS
[LibraryImport("ucrtbase")]
#else // POSIX
Expand Down
Loading
Loading