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);
|
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 Interactive { get; set; }
|
||||||
|
|
||||||
|
public bool Version { get; set; }
|
||||||
|
|
||||||
public IEnumerable<string> Expression { get; set; } = Array.Empty<string>();
|
public IEnumerable<string> Expression { get; set; } = Array.Empty<string>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,10 @@ namespace cs_mic_cli
|
||||||
{
|
{
|
||||||
Description = "Starts an interactive session."
|
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")
|
var expressionArgument = new Argument<string[]>("expression")
|
||||||
{
|
{
|
||||||
Arity = ArgumentArity.ZeroOrMore,
|
Arity = ArgumentArity.ZeroOrMore,
|
||||||
|
|
@ -46,6 +50,7 @@ namespace cs_mic_cli
|
||||||
{
|
{
|
||||||
Verbose = parseResult.GetValue(verboseOption),
|
Verbose = parseResult.GetValue(verboseOption),
|
||||||
Interactive = parseResult.GetValue(interactiveOption),
|
Interactive = parseResult.GetValue(interactiveOption),
|
||||||
|
Version = parseResult.GetValue(versionOption),
|
||||||
Expression = parseResult.GetValue(expressionArgument) ?? Array.Empty<string>()
|
Expression = parseResult.GetValue(expressionArgument) ?? Array.Empty<string>()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -62,12 +67,20 @@ namespace cs_mic_cli
|
||||||
|
|
||||||
Initializer.InitializeAll(inputInterpreter);
|
Initializer.InitializeAll(inputInterpreter);
|
||||||
inputInterpreter.RegisterFunction(new PrintVariables(inputInterpreter));
|
inputInterpreter.RegisterFunction(new PrintVariables(inputInterpreter));
|
||||||
|
inputInterpreter.RegisterFunction(new Functions.Version());
|
||||||
|
|
||||||
if(!options.Verbose)
|
if(!options.Verbose)
|
||||||
{
|
{
|
||||||
CSMic.Interpreter.Errors.errorStream = TextWriter.Null;
|
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)
|
if (string.IsNullOrWhiteSpace(fullExpression) || options.Interactive)
|
||||||
{
|
{
|
||||||
// console mode
|
// console mode
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<PublishAot>true</PublishAot>
|
<PublishAot>true</PublishAot>
|
||||||
<InvariantGlobalization>true</InvariantGlobalization>
|
<InvariantGlobalization>true</InvariantGlobalization>
|
||||||
|
<Version>1.0.0</Version>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue