Fixed for AOT publishing on linux.

This commit is contained in:
Jordan Wages 2026-06-30 02:53:33 -05:00
commit b36efadefd
3 changed files with 91 additions and 60 deletions

View file

@ -1,21 +1,11 @@
using CommandLine;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace cs_mic_cli
namespace cs_mic_cli
{
internal class Options
{
[Option('v', "verbose", HelpText = "Displays error messages from the parser if a soft error occurs.")]
public bool Verbose { get; set; }
[Option('i', "interactive", HelpText = "Starts an interactive session.")]
public bool Interactive { get; set; }
[Value(0)]
public required IEnumerable<string> Expression { get; set; }
public IEnumerable<string> Expression { get; set; } = Array.Empty<string>();
}
}

View file

@ -1,17 +1,61 @@
using CommandLine;
using cs_mic_cli.Functions;
using cs_mic_cli.Functions;
using CSMic;
using CSMic.StandardLibrary;
using System.CommandLine;
namespace cs_mic_cli
{
internal class Program
{
static void Main(string[] args)
static int Main(string[] args)
{
CommandLine.Parser.Default.ParseArguments<Options>(args)
.WithParsed(options =>
var verboseOption = new Option<bool>("--verbose", "-v")
{
Description = "Displays error messages from the parser if a soft error occurs."
};
var interactiveOption = new Option<bool>("--interactive", "-i")
{
Description = "Starts an interactive session."
};
var expressionArgument = new Argument<string[]>("expression")
{
Arity = ArgumentArity.ZeroOrMore,
Description = "Expression to evaluate."
};
expressionArgument.Validators.Add(result =>
{
foreach (var token in result.Tokens)
{
if (token.Value.StartsWith("--", StringComparison.Ordinal))
{
result.AddError($"Unrecognized command or argument '{token.Value}'.");
}
}
});
var rootCommand = new RootCommand("CSMic command line client")
{
verboseOption,
interactiveOption,
expressionArgument
};
rootCommand.SetAction(parseResult =>
{
var options = new Options
{
Verbose = parseResult.GetValue(verboseOption),
Interactive = parseResult.GetValue(interactiveOption),
Expression = parseResult.GetValue(expressionArgument) ?? Array.Empty<string>()
};
return Run(options);
});
return rootCommand.Parse(args).Invoke();
}
private static int Run(Options options)
{
var fullExpression = string.Join(' ', options.Expression);
var inputInterpreter = new InputInterpreter();
@ -56,11 +100,8 @@ namespace cs_mic_cli
// one-shot mode
Calculate(inputInterpreter, options, fullExpression);
}
})
.WithNotParsed<Options>(options =>
{
});
return 0;
}
private static void Calculate(InputInterpreter inputInterpreter, Options options, string expression)

View file

@ -11,7 +11,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.9.1" />
<PackageReference Include="System.CommandLine" Version="2.0.9" />
<PackageReference Include="CSMic" Version="2.1.0" />
<PackageReference Include="CSMic.StandardLibrary" Version="2.1.1" />
</ItemGroup>