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

#248 - xFunc Dotnet Tool #251

Merged
merged 1 commit into from
Feb 29, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
"request": "launch",
"preLaunchTask": "Build",
"program": "${workspaceFolder}/xFunc.DotnetTool/bin/Debug/netcoreapp3.0/xFunc.DotnetTool.dll",
"args": [],
"args": [
"interactive"
],
"cwd": "${workspaceFolder}/xFunc.DotnetTool",
"console": "integratedTerminal",
"stopAtEntry": false
Expand Down
7 changes: 1 addition & 6 deletions xFunc.DotnetTool/Options/BaseOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,7 @@ namespace xFunc.DotnetTool.Options
{
public abstract class BaseOptions : DebugInfoOptions
{
protected BaseOptions(string stringExpression, bool debug) : base(debug)
{
StringExpression = stringExpression;
}

[Value(0, Required = true, MetaName = "String Expression", HelpText = "The string expression.")]
public string StringExpression { get; }
public string StringExpression { get; set; }
}
}
9 changes: 2 additions & 7 deletions xFunc.DotnetTool/Options/DebugInfoOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,7 @@ namespace xFunc.DotnetTool.Options
{
public abstract class DebugInfoOptions
{
protected DebugInfoOptions(bool debug)
{
Debug = debug;
}

[Option('d', "debug", Required = false, HelpText = "Show stack trace.")]
public bool Debug { get; }
[Option('d', "debug", Default = false, Required = false, HelpText = "Show stack trace.")]
public bool Debug { get; set; }
}
}
6 changes: 1 addition & 5 deletions xFunc.DotnetTool/Options/InteractiveOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,14 @@ namespace xFunc.DotnetTool.Options
[Verb("interactive", HelpText = "Run interactive mode.")]
public class InteractiveOptions : DebugInfoOptions
{
public InteractiveOptions(bool debug) : base(debug)
{
}

[Usage(ApplicationAlias = "xfunc")]
public static IEnumerable<Example> Examples
{
get
{
return new List<Example>
{
new Example("Run iteractive mode", new InteractiveOptions(false))
new Example("Run iteractive mode", new InteractiveOptions())
};
}
}
Expand Down
8 changes: 3 additions & 5 deletions xFunc.DotnetTool/Options/ParseOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,16 @@ namespace xFunc.DotnetTool.Options
[Verb("parse", HelpText = "Parse string expression.")]
public class ParseOptions : BaseOptions
{
public ParseOptions(string stringExpression, bool debug) : base(stringExpression, debug)
{
}

[Usage(ApplicationAlias = "xfunc")]
public static IEnumerable<Example> Examples
{
get
{
return new List<Example>
{
new Example("Parse string expression", new ParseOptions("1 + 1", false))
new Example(
"Parse string expression",
new ParseOptions { StringExpression = "1 + 1" })
};
}
}
Expand Down
13 changes: 9 additions & 4 deletions xFunc.DotnetTool/Options/SolveOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
using CommandLine;
using CommandLine.Text;
using System.Collections.Generic;
using xFunc.Maths.Expressions;

namespace xFunc.DotnetTool.Options
{
[Verb("solve", HelpText = "Calculate result of expression.")]
public class SolveOptions : BaseOptions
{
public SolveOptions(string stringExpression, bool debug) : base(stringExpression, debug)
{
}
[Option('a', "angle", Default = AngleMeasurement.Degree, Required = false, HelpText = "Angle Measurement")]
public AngleMeasurement Angle { get; set; }

[Usage(ApplicationAlias = "xfunc")]
public static IEnumerable<Example> Examples
Expand All @@ -33,7 +33,12 @@ public static IEnumerable<Example> Examples
{
return new List<Example>
{
new Example("Calculate string expression", new SolveOptions("1 + 1", false))
new Example(
"Calculate string expression",
new SolveOptions { StringExpression = "1 + 1" }),
new Example(
"Set angle measurement",
new SolveOptions { StringExpression = "1 + 1" , Angle = AngleMeasurement.Radian })
};
}
}
Expand Down
8 changes: 3 additions & 5 deletions xFunc.DotnetTool/Options/TokenizeOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,16 @@ namespace xFunc.DotnetTool.Options
[Verb("tokenize", HelpText = "Convert string expression to list of tokens.")]
public class TokenizeOptions : BaseOptions
{
public TokenizeOptions(string stringExpression, bool debug) : base(stringExpression, debug)
{
}

[Usage(ApplicationAlias = "xfunc")]
public static IEnumerable<Example> Examples
{
get
{
return new List<Example>
{
new Example("Tokenize string expression", new TokenizeOptions("1 + 1", false))
new Example(
"Tokenize string expression",
new TokenizeOptions { StringExpression = "1 + 1" })
};
}
}
Expand Down
26 changes: 23 additions & 3 deletions xFunc.DotnetTool/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
using xFunc.Maths.Analyzers.TypeAnalyzers;
using xFunc.Maths.Expressions;
using xFunc.Maths.Expressions.Collections;
using xFunc.Maths.Tokenization;

namespace xFunc.DotnetTool
{
Expand Down Expand Up @@ -52,6 +51,8 @@ private static void Solve(SolveOptions options)
{
Run(options, () =>
{
processor.Parameters.AngleMeasurement = options.Angle;

var result = processor.Solve(options.StringExpression);
Console.WriteLine(result);
});
Expand All @@ -63,9 +64,28 @@ private static void Interactive(InteractiveOptions options)
{
Console.Write("> ");

var stringExpression = Console.ReadLine().ToLower();
if (stringExpression == "quit" || stringExpression == "exit")
var stringExpression = Console.ReadLine()?.ToLower();
if (stringExpression == null ||
stringExpression == "#quit" ||
stringExpression == "#exit")
{
break;
}
else if (stringExpression == "#degree")
{
processor.Parameters.AngleMeasurement = AngleMeasurement.Degree;
continue;
}
else if (stringExpression == "#radian")
{
processor.Parameters.AngleMeasurement = AngleMeasurement.Radian;
continue;
}
else if (stringExpression == "#gradian")
{
processor.Parameters.AngleMeasurement = AngleMeasurement.Gradian;
continue;
}

Run(options, () =>
{
Expand Down
4 changes: 2 additions & 2 deletions xFunc.DotnetTool/xFunc.DotnetTool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<LangVersion>latest</LangVersion>
<PackAsTool>true</PackAsTool>
<ToolCommandName>xFunc</ToolCommandName>
Expand All @@ -23,7 +23,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.6.0" />
<PackageReference Include="CommandLineParser" Version="2.7.82" />
</ItemGroup>

<ItemGroup>
Expand Down