Skip to content

Commit

Permalink
Fix #1 - print usage
Browse files Browse the repository at this point in the history
  • Loading branch information
atilaneves committed Nov 12, 2018
1 parent 5bee2c8 commit e2be450
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
19 changes: 14 additions & 5 deletions source/jupyter/wire/kernel.d
Expand Up @@ -8,11 +8,7 @@ mixin template Main(Backend) {
int main(string[] args) {
import std.experimental.logger: error;
try {
import jupyter.wire.kernel: Kernel;
const connectionFileName = args[1];
auto backend = Backend();
auto k = kernel(backend, connectionFileName);
k.run;
run!Backend(args);
return 0;
} catch(Exception e) {
error("Error: ", e.msg);
Expand All @@ -24,6 +20,19 @@ mixin template Main(Backend) {
}
}

void run(Backend)(in string[] args) {
import jupyter.wire.kernel: Kernel;
import std.exception: enforce;

const exeName = args.length > 0 ? args[0] : "<exeName>";
enforce(args.length == 2, "Usage: " ~ exeName ~ " <connectionFileName>");

const connectionFileName = args[1];
auto backend = Backend();
auto k = kernel(backend, connectionFileName);
k.run;
}


struct LanguageInfo {
string name;
Expand Down
10 changes: 10 additions & 0 deletions tests/ut/kernel.d
Expand Up @@ -2,7 +2,17 @@ module ut.kernel;


import unit_threaded;
import jupyter.wire.kernel;

private struct DummyBackend {
enum languageInfo = LanguageInfo();
ExecutionResult execute(in string) {
return ExecutionResult.init;
}
}

@("usage")
unittest {
run!DummyBackend([]).shouldThrowWithMessage("Usage: <exeName> <connectionFileName>");
run!DummyBackend(["foobin"]).shouldThrowWithMessage("Usage: foobin <connectionFileName>");
}

0 comments on commit e2be450

Please sign in to comment.