Last active
August 29, 2015 14:16
-
-
Save ruby0x1/488bb826e5e702adf237 to your computer and use it in GitHub Desktop.
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
#use this class as our entry point | |
-main HaxelibCounter | |
#generate a neko file from the code | |
-neko run.n | |
#use the arguable lib as a dependency | |
-lib arguable | |
#specify the define, which we can comment out to disable | |
-D haxelibcounter_verbose | |
#execute our new file with neko to test it immediately | |
-cmd neko run.n |
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
#use this class as our entry point | |
-main HaxelibCounter | |
#is this a debug build? leave this line enabled | |
#-debug | |
#generate a neko file from the code | |
-neko run.n | |
#use the arguable lib as a dependency | |
-lib arguable | |
#specify the define, which we can comment out to disable | |
#-D haxelibcounter_verbose | |
#execute our new file with neko to test it immediately | |
-cmd neko run.n --count --show-names |
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
import arguable.ArgParser; | |
using StringTools; | |
class HaxelibCounter { | |
//The main entry point | |
static function main() { | |
var args = ArgParser.parse( Sys.args() ); | |
print('haxelibcounter'); | |
debug('> found args $args'); | |
if(args.length == 0) { | |
return usage(); | |
} | |
if(args.has('count')) { | |
return do_count(args); | |
} | |
} //main | |
static function usage() { | |
print('usage:'); | |
print(' --count | displays the number of haxelib libraries installed'); | |
print(' --show-names | must be specified with --count, lists installed haxelibs one per line'); | |
} | |
static function do_count(args) { | |
//call `haxelib list` and read the output: | |
var process = new sys.io.Process('haxelib',['list']); | |
var result = process.stdout.readAll().toString(); | |
debug('> haxelib list returned a ${result.length} length string'); | |
if(result.length > 0) { | |
//split the list up by each line | |
var items = result.split('\n'); | |
//remove any blank items from the list, in case haxelib adds empty lines | |
items = items.filter(function(item) return item.length > 0); | |
//we know how many there are now | |
print('${items.length} haxelibs installed!'); | |
//now we can handle the additional flag | |
if(args.has('show-names')) { | |
var item_names = items.map(function(item) return item.split(': ')[0]); | |
for(name in item_names) print(' $name'); | |
} | |
} else { | |
print('An unknown error occured. `haxelib list` was not able to be called, it returned status ${process.exitCode()}'); | |
} | |
} //do_count | |
//Internal | |
static function print(value) { | |
#if debug trace(value); | |
#else Sys.println(value); | |
#end | |
} | |
static function debug(value) { | |
#if haxelibcounter_verbose | |
trace(value); | |
#end | |
} | |
} //HaxelibCount |
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
{ | |
"name": "haxelibcounter", | |
"url" : "https://github.com/underscorediscovery/haxe-entry-point-example/", | |
"license": "MIT", | |
"tags": ["cross"], | |
"description": "Haxe entry point - An article on getting started with Haxe", | |
"version": "1.0.0", | |
"releasenote": "Initial version", | |
"contributors": ["underscorediscovery"] | |
} |
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
> haxelib run haxelibcounter | |
HaxelibCounter.hx:69: haxelibcounter | |
HaxelibCounter.hx:76: > found args { any => true, length => 0, valid => [], invalid => [{ name => /Users/sven/dev/haxe-entry-point-example/, value => }] } | |
HaxelibCounter.hx:69: usage: | |
HaxelibCounter.hx:69: --count | displays the number of haxelib libraries installed | |
HaxelibCounter.hx:69: --show-names | must be specified with --count, lists installed haxelibs one per line |
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
HaxelibCounter.hx:68: > found args { any => true, length => 1, valid => [{ name => count, value => }], invalid => [] } | |
HaxelibCounter.hx:68: > haxelib list returned a 1409 length string | |
HaxelibCounter.hx:48: 42 haxelibs installed! |
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
haxelib run haxelibcounter --count --show-names | |
haxelibcounter | |
43 haxelibs installed! | |
actuate | |
arguable | |
box2d | |
... |
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
> haxelib install arguable | |
Downloading arguable-1,0,2.zip... | |
Download complete : 12071 bytes in 0.2s (47.7KB/s) | |
Install .gitignore | |
Install README.md | |
Created arguable/ | |
Install arguable/ArgParser.hx | |
Install arguable/Stack.hx | |
Install haxelib.json | |
Created test/ | |
Install test/Test.hx | |
Install test/TestArguable.n | |
Install test/build.hxml | |
Current version is now 1.0.2 | |
Done |
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
static function main() { | |
var args = ArgParser.parse( Sys.args() ); | |
debug('> found args $args'); | |
if(args.length == 0) { | |
return usage(); | |
} | |
if(args.has('count')) { | |
return do_count(args); | |
} | |
} //main | |
static function usage() { | |
trace('haxelibcounter usage:'); | |
trace(' --count | displays number of haxelib libraries installed'); | |
trace(' --show-names | must be specified with --count, lists installed haxelibs one per line'); | |
} |
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
static function do_count(args) { | |
//call `haxelib list` and read the output: | |
var process = new sys.io.Process('haxelib',['list']); | |
var result = process.stdout.readAll().toString(); | |
debug('> haxelib list returned a ${result.length} length string'); | |
if(result.length > 0) { | |
//split the list up by each line | |
var items = result.split('\n'); | |
//remove any blank items from the list, in case haxelib adds empty lines | |
items = items.filter(function(item) return item.length > 0); | |
//we know how many there are now | |
trace('${items.length} haxelibs installed!'); | |
//:todo: handle --show-names | |
} else { | |
trace('An unknown error occured. `haxelib list` was not able to be called, it returned status ${process.exitCode()}'); | |
} | |
} //do_count |
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
//we know how many there are now | |
trace('${items.length} haxelibs installed!'); | |
//now we can handle the additional flag | |
if(args.has('show-names')) { | |
var item_names = items.map(function(item) return item.split(': ')[0]); | |
for(name in item_names) print(' $name'); | |
} |
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
static function debug(value) { | |
#if haxelibcounter_verbose | |
trace(value); | |
#end | |
} |
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
static function print(value) { | |
#if debug trace(value); | |
#else Sys.println(value); | |
#end | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment