Added version check
This commit is contained in:
parent
591f729867
commit
0a1f5360bd
5 changed files with 131 additions and 15 deletions
|
|
@ -59,7 +59,7 @@ namespace cs_mic_cli.Functions
|
|||
Console.WriteLine("{0}. {1} {2} = {3}", variableIndex++, variable.Type, variable.Name, displayValue);
|
||||
}
|
||||
|
||||
return FunctionValue.NONE;
|
||||
return FunctionValue.ZERO;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
100
src/cs-mic-cli/Functions/Version.cs
Normal file
100
src/cs-mic-cli/Functions/Version.cs
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
using CSMic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace cs_mic_cli.Functions
|
||||
{
|
||||
internal class Version : ICodedFunction
|
||||
{
|
||||
private static Lazy<string> versionCLI = new Lazy<string>(() =>
|
||||
{
|
||||
string version = GetVersion(Assembly.GetExecutingAssembly());
|
||||
|
||||
return string.Format("{0,-20} {1}", "CLI", version);
|
||||
});
|
||||
|
||||
private static Lazy<string> versionCSMIC = new Lazy<string>(() =>
|
||||
{
|
||||
string version = GetVersion(typeof(CSMic.InputInterpreter).Assembly);
|
||||
|
||||
return string.Format("{0,-20} {1}", "CS-MIC", version);
|
||||
});
|
||||
|
||||
private static Lazy<string> versionStandardLibrary = new Lazy<string>(() =>
|
||||
{
|
||||
string version = GetVersion(typeof(CSMic.StandardLibrary.Initializer).Assembly);
|
||||
|
||||
return string.Format("{0,-20} {1}", "Standard Library", version);
|
||||
});
|
||||
|
||||
public static string VersionCLI
|
||||
{
|
||||
get
|
||||
{
|
||||
return versionCLI.Value;
|
||||
}
|
||||
}
|
||||
|
||||
public static string VersionCSMIC
|
||||
{
|
||||
get
|
||||
{
|
||||
return versionCSMIC.Value;
|
||||
}
|
||||
}
|
||||
|
||||
public static string VersionStandardLibrary
|
||||
{
|
||||
get
|
||||
{
|
||||
return versionStandardLibrary.Value;
|
||||
}
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return "version";
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<FunctionArgument> ExpectedArguments
|
||||
{
|
||||
get
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public FunctionValue ReturnValue
|
||||
{
|
||||
get
|
||||
{
|
||||
return FunctionValue.NONE;
|
||||
}
|
||||
}
|
||||
|
||||
public FunctionValue Execute(params FunctionArgument[] args)
|
||||
{
|
||||
Console.WriteLine(VersionCLI);
|
||||
Console.WriteLine(VersionCSMIC);
|
||||
Console.WriteLine(VersionStandardLibrary);
|
||||
|
||||
return FunctionValue.ZERO;
|
||||
}
|
||||
|
||||
static string GetVersion(Assembly assembly)
|
||||
{
|
||||
var version = assembly.GetName()?.Version?.ToString()
|
||||
?? "Unknown";
|
||||
|
||||
return version;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -6,6 +6,8 @@
|
|||
|
||||
public bool Interactive { get; set; }
|
||||
|
||||
public bool Version { get; set; }
|
||||
|
||||
public IEnumerable<string> Expression { get; set; } = Array.Empty<string>();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,10 @@ namespace cs_mic_cli
|
|||
{
|
||||
Description = "Starts an interactive session."
|
||||
};
|
||||
var versionOption = new Option<bool>("--version", "-v")
|
||||
{
|
||||
Description = "Prints the version number of CS-MIC."
|
||||
};
|
||||
var expressionArgument = new Argument<string[]>("expression")
|
||||
{
|
||||
Arity = ArgumentArity.ZeroOrMore,
|
||||
|
|
@ -46,6 +50,7 @@ namespace cs_mic_cli
|
|||
{
|
||||
Verbose = parseResult.GetValue(verboseOption),
|
||||
Interactive = parseResult.GetValue(interactiveOption),
|
||||
Version = parseResult.GetValue(versionOption),
|
||||
Expression = parseResult.GetValue(expressionArgument) ?? Array.Empty<string>()
|
||||
};
|
||||
|
||||
|
|
@ -62,12 +67,20 @@ namespace cs_mic_cli
|
|||
|
||||
Initializer.InitializeAll(inputInterpreter);
|
||||
inputInterpreter.RegisterFunction(new PrintVariables(inputInterpreter));
|
||||
inputInterpreter.RegisterFunction(new Functions.Version());
|
||||
|
||||
if(!options.Verbose)
|
||||
{
|
||||
CSMic.Interpreter.Errors.errorStream = TextWriter.Null;
|
||||
}
|
||||
|
||||
if(options.Version)
|
||||
{
|
||||
Console.WriteLine(Functions.Version.VersionCLI);
|
||||
Console.WriteLine(Functions.Version.VersionCSMIC);
|
||||
Console.WriteLine(Functions.Version.VersionStandardLibrary);
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(fullExpression) || options.Interactive)
|
||||
{
|
||||
// console mode
|
||||
|
|
|
|||
|
|
@ -1,19 +1,20 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<RootNamespace>cs_mic_cli</RootNamespace>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<PublishAot>true</PublishAot>
|
||||
<InvariantGlobalization>true</InvariantGlobalization>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<RootNamespace>cs_mic_cli</RootNamespace>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<PublishAot>true</PublishAot>
|
||||
<InvariantGlobalization>true</InvariantGlobalization>
|
||||
<Version>1.0.0</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="System.CommandLine" Version="2.0.9" />
|
||||
<PackageReference Include="CSMic" Version="2.1.0" />
|
||||
<PackageReference Include="CSMic.StandardLibrary" Version="2.1.1" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="System.CommandLine" Version="2.0.9" />
|
||||
<PackageReference Include="CSMic" Version="2.1.0" />
|
||||
<PackageReference Include="CSMic.StandardLibrary" Version="2.1.1" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue