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

Refactor node commands (#536) #1

Merged
merged 1 commit into from
Apr 1, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 20 additions & 14 deletions .github/workflows/dotnetcore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ env:
jobs:

Test:
runs-on: ubuntu-latest
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v1
Expand All @@ -17,26 +20,29 @@ jobs:
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Check format
if: runner.os == 'Linux'
run: |
dotnet tool install --version 3.2.111002 --tool-path ./ dotnet-format --add-source https://dotnet.myget.org/F/format/api/v3/index.json
./dotnet-format --check --dry-run -v diagnostic
- name: Build
- name: Build CLI
if: runner.os == 'Linux'
run: |
dotnet publish -o ./out -c Release neo-cli
find ./out -name 'config.json' | xargs perl -pi -e 's|LevelDBStore|MemoryStore|g'
- name: Install dependencies
if: runner.os == 'Linux'
run: sudo apt-get install libleveldb-dev expect
- name: Run tests with expect
if: runner.os == 'Linux'
run: expect ./.github/workflows/test-neo-cli.expect

Test_GUI:
runs-on: windows-latest
steps:
- name: Chectout
uses: actions/checkout@v1
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Build
run: dotnet build -c Release neo-gui
- name: Run Unit Tests
if: runner.os == 'Windows'
run: |
forfiles /p tests /m *.csproj /s /c "cmd /c dotnet add @PATH package coverlet.msbuild"
dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=lcov /p:CoverletOutput=${GITHUB_WORKSPACE}/coverage/lcov
- name: Coveralls
if: runner.os == 'Windows'
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: \coverage\lcov.info
43 changes: 43 additions & 0 deletions Neo.ConsoleService/CommandQuoteToken.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using System.Diagnostics;

namespace Neo.ConsoleService
{
[DebuggerDisplay("Value={Value}, Value={Value}")]
internal class CommandQuoteToken : CommandToken
{
/// <summary>
/// Constructor
/// </summary>
/// <param name="offset">Offset</param>
/// <param name="value">Value</param>
public CommandQuoteToken(int offset, char value) : base(CommandTokenType.Quote, offset)
{
if (value != '\'' && value != '"')
{
throw new ArgumentException("Not valid quote");
}

Value = value.ToString();
}

/// <summary>
/// Parse command line quotes
/// </summary>
/// <param name="commandLine">Command line</param>
/// <param name="index">Index</param>
/// <returns>CommandQuoteToken</returns>
internal static CommandQuoteToken Parse(string commandLine, ref int index)
{
var c = commandLine[index];

if (c == '\'' || c == '"')
{
index++;
return new CommandQuoteToken(index - 1, c);
}

throw new ArgumentException("No quote found");
}
}
}
54 changes: 54 additions & 0 deletions Neo.ConsoleService/CommandSpaceToken.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using System;
using System.Diagnostics;

namespace Neo.ConsoleService
{
[DebuggerDisplay("Value={Value}, Count={Count}")]
internal class CommandSpaceToken : CommandToken
{
/// <summary>
/// Count
/// </summary>
public int Count { get; }

/// <summary>
/// Constructor
/// </summary>
/// <param name="offset">Offset</param>
/// <param name="count">Count</param>
public CommandSpaceToken(int offset, int count) : base(CommandTokenType.Space, offset)
{
Value = "".PadLeft(count, ' ');
Count = count;
}

/// <summary>
/// Parse command line spaces
/// </summary>
/// <param name="commandLine">Command line</param>
/// <param name="index">Index</param>
/// <returns>CommandSpaceToken</returns>
internal static CommandSpaceToken Parse(string commandLine, ref int index)
{
int offset = index;
int count = 0;

for (int ix = index, max = commandLine.Length; ix < max; ix++)
{
if (commandLine[ix] == ' ')
{
count++;
}
else
{
break;
}
}

if (count == 0) throw new ArgumentException("No spaces found");

index += count;
return new CommandSpaceToken(offset, count);
}
}
}
80 changes: 80 additions & 0 deletions Neo.ConsoleService/CommandStringToken.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
using System;
using System.Diagnostics;

namespace Neo.ConsoleService
{
[DebuggerDisplay("Value={Value}, RequireQuotes={RequireQuotes}")]
internal class CommandStringToken : CommandToken
{
/// <summary>
/// Require quotes
/// </summary>
public bool RequireQuotes { get; }

/// <summary>
/// Constructor
/// </summary>
/// <param name="offset">Offset</param>
/// <param name="value">Value</param>
public CommandStringToken(int offset, string value) : base(CommandTokenType.String, offset)
{
Value = value;
RequireQuotes = value.IndexOfAny(new char[] { '\'', '"' }) != -1;
}

/// <summary>
/// Parse command line spaces
/// </summary>
/// <param name="commandLine">Command line</param>
/// <param name="index">Index</param>
/// <param name="quote">Quote (could be null)</param>
/// <returns>CommandSpaceToken</returns>
internal static CommandStringToken Parse(string commandLine, ref int index, CommandQuoteToken quote)
{
int end;
int offset = index;

if (quote != null)
{
var ix = index;

do
{
end = commandLine.IndexOf(quote.Value[0], ix + 1);

if (end == -1)
{
throw new ArgumentException("String not closed");
}

if (IsScaped(commandLine, end - 1))
{
ix = end;
end = -1;
}
}
while (end < 0);
}
else
{
end = commandLine.IndexOf(' ', index + 1);
}

if (end == -1)
{
end = commandLine.Length;
}

var ret = new CommandStringToken(offset, commandLine.Substring(index, end - index));
index += end - index;
return ret;
}

private static bool IsScaped(string commandLine, int index)
{
// TODO: Scape the scape

return (commandLine[index] == '\\');
}
}
}
Loading