diff --git a/src/tink/MacroApi.hx b/src/tink/MacroApi.hx index fe22d99..874bfb9 100644 --- a/src/tink/MacroApi.hx +++ b/src/tink/MacroApi.hx @@ -29,6 +29,19 @@ typedef TypeResolution = Ref>; class MacroApi { + static var MAIN_CANDIDATES = ['-main', '-x', '--run']; + static public function getMainClass():Option { + var args = Sys.args(); + + for (c in MAIN_CANDIDATES) + switch args.indexOf(c) { + case -1: + case v: return Some(args[v+1]); + } + + return None; + } + static var idCounter = 0; @:noUsing static public inline function tempName(?prefix:String = 'tmp'):String diff --git a/tests/Misc.hx b/tests/Misc.hx new file mode 100644 index 0000000..f5dc306 --- /dev/null +++ b/tests/Misc.hx @@ -0,0 +1,10 @@ +import tink.MacroApi; +import haxe.unit.TestCase; + +using tink.CoreApi; + +class Misc extends TestCase { + function testMain() { + assertEquals('Run', MacroApi.getMainClass().force()); + } +} \ No newline at end of file diff --git a/tests/Run.hx b/tests/Run.hx index 519789e..3a73b7b 100644 --- a/tests/Run.hx +++ b/tests/Run.hx @@ -12,6 +12,7 @@ class Run { new Types(), new Positions(), new TypeMapTest(), + new Misc(), ]; #end macro static function test() {