-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added externs listing
- Loading branch information
Showing
15 changed files
with
544 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# cache files for sublime text | ||
*.tmlanguage.cache | ||
*.tmPreferences.cache | ||
*.stTheme.cache | ||
|
||
# workspace files are user-specific | ||
*.sublime-workspace | ||
|
||
# project files should be checked into the repository, unless a significant | ||
# proportion of contributors will probably not be using SublimeText | ||
*.sublime-project | ||
|
||
# sftp configuration file | ||
sftp-config.json | ||
|
||
# Package control specific files | ||
Package Control.last-run | ||
Package Control.ca-list | ||
Package Control.ca-bundle | ||
Package Control.system-ca-bundle | ||
Package Control.cache/ | ||
Package Control.ca-certs/ | ||
bh_unicode_properties.cache | ||
|
||
# Sublime-github package stores a github token in this file | ||
# https://packagecontrol.io/packages/sublime-github | ||
GitHub.sublime-settings | ||
|
||
# Haxe | ||
.haxelib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--interp | ||
-main hxextern.Main | ||
-cp src/ | ||
-lib hxargs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"main": "hxextern.Main", | ||
"name": "hxextern", | ||
"url": "https://github.com/ExternKit/hxextern", | ||
"license": "MIT", | ||
"tags": ["extern", "hxextern"], | ||
"description": "Extern manager", | ||
"version": "0.1.0", | ||
"classPath": "src/", | ||
"contributors": ["fantoine"], | ||
"dependencies": { | ||
"hxargs": "", | ||
"hxssl": "" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package hxextern; | ||
|
||
import hxargs.Args; | ||
import hxextern.command.*; | ||
import hxextern.service.*; | ||
|
||
typedef ArgsHandler = { | ||
function getDoc() : String; | ||
|
||
function parse(__args : Array<Dynamic>) : Void; | ||
}; | ||
|
||
class Cli | ||
{ | ||
private var handler : ArgsHandler; | ||
|
||
public function new() | ||
{ | ||
this.handler = Args.generate([ | ||
@doc('List available externs') | ||
'list' => function(?target : String) : Void { | ||
this.runCommand(new ListCommand(target)); | ||
}, | ||
|
||
@doc('Search for an extern') | ||
'search' => function(name : String, ?target : String) : Void { | ||
this.runCommand(new SearchCommand(name, target)); | ||
}, | ||
|
||
@doc('Generate extern code') | ||
'generate' => function(?path : String) : Void { | ||
trace('Not implemented'); | ||
}, | ||
|
||
@doc('Show this help') | ||
'help' => function() : Void { | ||
this.runCommand(new HelpCommand(this.handler.getDoc())); | ||
}, | ||
|
||
_ => function(arg : String) : Void { | ||
this.runCommand(new HelpCommand(this.handler.getDoc())); | ||
}, | ||
]); | ||
} | ||
|
||
public function run(args : Array<String>) : Void | ||
{ | ||
if (args.length == 0) { | ||
args.push('help'); | ||
} | ||
try { | ||
this.handler.parse(args); | ||
} catch (e : Dynamic) { | ||
Console.instance.error(Std.string(e)); | ||
} | ||
} | ||
|
||
private function runCommand(command : ICommand) : Void | ||
{ | ||
try { | ||
command.run(); | ||
} catch (e : Dynamic) { | ||
Console.instance.error(Std.string(e)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package hxextern; | ||
|
||
class Main | ||
{ | ||
public static function main() : Void | ||
{ | ||
// Get arguments | ||
var args = Sys.args(); | ||
args.pop(); | ||
|
||
// Run | ||
var cli = new Cli(); | ||
cli.run(args); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package hxextern; | ||
|
||
@:enum | ||
abstract Target(String) to String | ||
{ | ||
var Cpp : Target = 'cpp'; | ||
var Cs : Target = 'cs'; | ||
var Flash : Target = 'flash'; | ||
var Java : Target = 'java'; | ||
var Js : Target = 'js'; | ||
var Lua : Target = 'lua'; | ||
var Neko : Target = 'neko'; | ||
var Php : Target = 'php'; | ||
var Python : Target = 'python'; | ||
|
||
public static function fromString(target : String) : Null<Target> | ||
{ | ||
return switch (target.toLowerCase()) { | ||
case 'cpp' | 'c++': Cpp; | ||
case 'cs' | 'csharp': Cs; | ||
case 'flash': Flash; | ||
case 'js' | 'javascript': Js; | ||
case 'lua': Lua; | ||
case 'neko' | 'n': Neko; | ||
case 'php': Php; | ||
case 'py' | 'python': Python; | ||
case _: throw 'Unsupported target "${target}"'; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package hxextern.command; | ||
|
||
import hxextern.service.Console; | ||
import hxextern.service.Repository; | ||
|
||
class AbstractListCommand implements ICommand | ||
{ | ||
public function new() | ||
{ | ||
// Nothing to do | ||
} | ||
|
||
public function run() : Void | ||
{ | ||
throw 'Must be overriden'; | ||
} | ||
|
||
private function printList(infos : Array<RepositoryInfo>) : Void | ||
{ | ||
if (0 == infos.length) { | ||
Console.instance.info('No results found'); | ||
return; | ||
} | ||
|
||
Console.instance.success('Found ${infos.length} result(s)'); | ||
for (info in infos) { | ||
Console.instance.message(' * ', false); | ||
Console.instance.info('${info.name} (${info.target})', false); | ||
Console.instance.message(' : ${info.description}'); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package hxextern.command; | ||
|
||
class HelpCommand implements ICommand | ||
{ | ||
private var doc : String; | ||
|
||
public function new(doc : String) | ||
{ | ||
this.doc = doc; | ||
} | ||
|
||
public function run() : Void | ||
{ | ||
Sys.println(this.doc); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package hxextern.command; | ||
|
||
interface ICommand | ||
{ | ||
public function run() : Void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package hxextern.command; | ||
|
||
import hxextern.service.Repository; | ||
|
||
class ListCommand extends AbstractListCommand | ||
{ | ||
private var target : String; | ||
|
||
public function new(?target : String) | ||
{ | ||
super(); | ||
|
||
this.target = target; | ||
} | ||
|
||
public override function run() : Void | ||
{ | ||
var target = (null == this.target ? null : Target.fromString(this.target)); | ||
|
||
var infos = Repository.instance.list(target); | ||
this.printList(infos); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package hxextern.command; | ||
|
||
import hxextern.service.Repository; | ||
|
||
class SearchCommand extends AbstractListCommand | ||
{ | ||
private var name : String; | ||
private var target : String; | ||
|
||
public function new(name : String, ?target : String) | ||
{ | ||
super(); | ||
|
||
this.name = name; | ||
this.target = target; | ||
} | ||
|
||
public override function run() : Void | ||
{ | ||
var target = (null == this.target ? null : Target.fromString(this.target)); | ||
|
||
var infos = Repository.instance.find(this.name, target); | ||
this.printList(infos); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package hxextern.service; | ||
|
||
import haxe.io.Output; | ||
import hxextern.utils.Colors; | ||
|
||
class Console | ||
{ | ||
@:isVar | ||
public static var instance(get, null) : Console; | ||
private static function get_instance() : Console | ||
{ | ||
if (null == Console.instance) { | ||
Console.instance = new Console(); | ||
} | ||
return Console.instance; | ||
} | ||
|
||
private var stdout : Output; | ||
private var stderr : Output; | ||
|
||
private function new() | ||
{ | ||
this.stdout = Sys.stdout(); | ||
this.stderr = Sys.stderr(); | ||
} | ||
|
||
public function message(message : String, newline : Bool = true) : Void | ||
{ | ||
this.print(this.stdout, message, newline); | ||
} | ||
|
||
public function debug(message : String, newline : Bool = true) : Void | ||
{ | ||
this.print(this.stdout, Colors.magenta('${message}'), newline); | ||
} | ||
|
||
public function info(message : String, newline : Bool = true) : Void | ||
{ | ||
this.print(this.stdout, Colors.cyan('${message}'), newline); | ||
} | ||
|
||
public function success(message : String, newline : Bool = true) : Void | ||
{ | ||
this.print(this.stdout, Colors.green('${message}'), newline); | ||
} | ||
|
||
public function warning(message : String, newline : Bool = true) : Void | ||
{ | ||
this.print(this.stderr, Colors.yellow('${message}'), newline); | ||
} | ||
|
||
public function error(message : String, newline : Bool = true) : Void | ||
{ | ||
this.print(this.stderr, Colors.red('${message}'), newline); | ||
} | ||
|
||
private function print(output : Output, message : String, newline : Bool = true) : Void | ||
{ | ||
output.writeString(message); | ||
if (newline) { | ||
output.writeString('\n'); | ||
} | ||
output.flush(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package hxextern.service; | ||
|
||
import haxe.io.Bytes; | ||
import sys.io.Process as HxProcess; | ||
|
||
typedef ProcessOutput = { | ||
var output : Null<String>; | ||
var error : Null<String>; | ||
var valid : Bool; | ||
var code : Int; | ||
}; | ||
|
||
class Process | ||
{ | ||
@:isVar | ||
public static var instance(get, null) : Process; | ||
private static function get_instance() : Process | ||
{ | ||
if (null == Process.instance) { | ||
Process.instance = new Process(); | ||
} | ||
return Process.instance; | ||
} | ||
|
||
private function new() | ||
{ | ||
|
||
} | ||
|
||
public function execute(command : String, ?args : Array<String>) : ProcessOutput | ||
{ | ||
Console.instance.debug('Calling command "${command}' + (null != args && args.length > 0 ? ' ' + args.join(' ') : '') + '"'); | ||
|
||
var process = new HxProcess(command, args); | ||
var output = process.stdout.readAll().toString(); | ||
var error = process.stderr.readAll().toString(); | ||
var result = ('' != error && null != error ? { | ||
output: null, | ||
error: error, | ||
valid: false, | ||
code: process.exitCode(), | ||
} : { | ||
output: output, | ||
error: null, | ||
valid: true, | ||
code: process.exitCode(), | ||
}); | ||
process.close(); | ||
|
||
return result; | ||
} | ||
} |
Oops, something went wrong.