Skip to content

Instantly share code, notes, and snippets.

@clarkjones
Forked from jasononeil/HaxeScript.hx
Last active July 12, 2018 19:55
Show Gist options
  • Select an option

  • Save clarkjones/9c7c05b64c5b2b0763c2 to your computer and use it in GitHub Desktop.

Select an option

Save clarkjones/9c7c05b64c5b2b0763c2 to your computer and use it in GitHub Desktop.

Revisions

  1. clarkjones revised this gist Oct 8, 2015. 1 changed file with 10 additions and 6 deletions.
    16 changes: 10 additions & 6 deletions haxex
    Original file line number Diff line number Diff line change
    @@ -1,13 +1,17 @@
    #!/bin/bash
    compArgs=$@
    args=$@

    # Get cli args
    cliArgs=${compArgs/*@/""}
    # Get compiler args
    compArgs=${compArgs/@*/" --run"}
    # Create compiler args
    compArgs=${args/@*/" --run"}

    # Create string to match and remove compiler args
    compMatch=${compArgs/ --run/"@"}

    # Get cli args by removing compiler args
    cliArgs=${args/${compMatch}/""}

    set -- $cliArgs
    # Give file name its own var
    # Give filename its own var
    filename=$1
    # Set args to be passed to script
    cliArgs=${@:2}
  2. clarkjones revised this gist Oct 8, 2015. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions haxex
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,8 @@
    #!/bin/bash
    compArgs=${@:1}
    compArgs=$@

    # Get cli args
    cliArgs=${compArgs/* @/""}
    cliArgs=${compArgs/*@/""}
    # Get compiler args
    compArgs=${compArgs/@*/" --run"}

  3. clarkjones revised this gist Oct 8, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion haxex
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,7 @@ cliArgs=${compArgs/* @/""}
    compArgs=${compArgs/@*/" --run"}

    set -- $cliArgs
    # Give file name into its own var
    # Give file name its own var
    filename=$1
    # Set args to be passed to script
    cliArgs=${@:2}
  4. clarkjones revised this gist Oct 8, 2015. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions haxex
    Original file line number Diff line number Diff line change
    @@ -2,12 +2,12 @@
    compArgs=${@:1}

    # Get cli args
    cliArgs=${compArgs/*@/""}
    cliArgs=${compArgs/* @/""}
    # Get compiler args
    compArgs=${compArgs/@*/" --run"}

    set -- $cliArgs
    # Give filename its own var
    # Give file name into its own var
    filename=$1
    # Set args to be passed to script
    cliArgs=${@:2}
  5. clarkjones revised this gist Oct 8, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion haxex
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,7 @@ cliArgs=${compArgs/*@/""}
    compArgs=${compArgs/@*/" --run"}

    set -- $cliArgs
    # Give file name into its own var
    # Give filename its own var
    filename=$1
    # Set args to be passed to script
    cliArgs=${@:2}
  6. clarkjones revised this gist Oct 8, 2015. 2 changed files with 15 additions and 8 deletions.
    2 changes: 0 additions & 2 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -49,6 +49,4 @@ What this script actually does:

    Limitations:

    Currently the first occurance of './' will be stripped and '/' will be replaced with '.' so avoiding using these symbols in your args is probably best for now

    If your script is in the root package (has no `package` statement at the top of the file), then you need to call it from the directory the script is in. If your script is in a sub-package, you need to call it from the root-level package. Easy rule of thumb: don't use packages, and call from the directory the script is in.
    21 changes: 15 additions & 6 deletions haxex
    Original file line number Diff line number Diff line change
    @@ -1,15 +1,24 @@
    #!/bin/bash
    args=${@:1}
    compArgs=${@:1}

    args=${args/@/" --run"}
    # Get cli args
    cliArgs=${compArgs/*@/""}
    # Get compiler args
    compArgs=${compArgs/@*/" --run"}

    set -- $cliArgs
    # Give file name into its own var
    filename=$1
    # Set args to be passed to script
    cliArgs=${@:2}

    # Remove ".hx" if it's there
    args=${args/\.hx/""}
    filename=${filename/\.hx/""}

    # Remove "./" if it's there
    args=${args/\.\//""}
    filename=${filename/\.\//""}

    # Change "/" to "."
    args=${args/\//"."}
    filename=${filename/\//"."}

    haxe $args
    haxe $compArgs $filename $cliArgs
  7. clarkjones revised this gist Oct 8, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,7 @@ This is a tiny shell script that you can use to make scripting with Haxe very st
    Using a straight #!/usr/bin/haxe doesn't work currently, as the Haxe compiler will have to be a little more clever about realising it is a shell script and that we wish to execute it. Maybe this will be native some day, for now, you can install the script below into `/usr/bin/haxex` and then use that.

    Installation:
    **if you're using OS X El Capitain you'll probably need to put haxex in /usr/local/bin/**
    **if you're using OS X El Capitan you'll probably need to put haxex in /usr/local/bin/**

    1. `sudo nano /usr/bin/haxex`, paste the 'haxex' file in there
    2. `sudo chmod +x /usr/bin/haxex`
  8. clarkjones revised this gist Oct 7, 2015. 2 changed files with 2 additions and 2 deletions.
    2 changes: 1 addition & 1 deletion HaxeScript.hx
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    #!/usr/bin/env haxex -lib mcli @

    /**
    Take from mcli example https://github.com/waneck/mcli
    Taken from mcli example https://github.com/waneck/mcli
    Say hello.
    Example inspired by ruby's "executable" lib example
    **/
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    **Note: This is modified version of the haxex script created by @jasononeil**
    **Note: This is a modified version of the haxex script created by @jasononeil**

    **This version allows for specifying compiler args in your script. so you can include and use libraries like mcli**

  9. clarkjones revised this gist Oct 7, 2015. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -33,8 +33,8 @@ Running:
    ./MyScript.hx

    For the included HaxeScript:
    haxelib install mcli

    haxelib install mcli
    chmod +x HaxeScript.hx
    ./HaxeScript.hx [yourname] --loud

  10. clarkjones revised this gist Oct 7, 2015. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -32,8 +32,9 @@ Running:
    chmod +x MyScript.hx
    ./MyScript.hx

    For the included HaxeScript:
    haxelib install mcli
    For the included HaxeScript:
    haxelib install mcli

    chmod +x HaxeScript.hx
    ./HaxeScript.hx [yourname] --loud

  11. clarkjones revised this gist Oct 7, 2015. 2 changed files with 7 additions and 5 deletions.
    5 changes: 3 additions & 2 deletions HelloWorld.hx → HaxeScript.hx
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,11 @@
    #!/usr/bin/env haxex -lib mcli @

    /**
    Take from mcli example https://github.com/waneck/mcli
    Say hello.
    Example inspired by ruby's "executable" lib example
    **/
    class HelloWorld extends mcli.CommandLine
    class HaxeScript extends mcli.CommandLine
    {
    /**
    Say it in uppercase?
    @@ -32,7 +33,7 @@ class HelloWorld extends mcli.CommandLine

    public static function main()
    {
    new mcli.Dispatch(Sys.args()).dispatch(new HelloWorld());
    new mcli.Dispatch(Sys.args()).dispatch(new HaxeScript());
    }

    }
    7 changes: 4 additions & 3 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -32,9 +32,10 @@ Running:
    chmod +x MyScript.hx
    ./MyScript.hx

    For the included HelloWorld
    chmod +x HelloWorld.hx
    ./HelloWorld.hx [yourname] --loud
    For the included HaxeScript:
    haxelib install mcli
    chmod +x HaxeScript.hx
    ./HaxeScript.hx [yourname] --loud

    Pretty neat-o if you ask me.

  12. clarkjones revised this gist Oct 7, 2015. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -26,10 +26,15 @@ Usage:
    }
    }


    Running:

    chmod +x MyScript.hx
    ./MyScript.hx

    For the included HelloWorld
    chmod +x HelloWorld.hx
    ./HelloWorld.hx [yourname] --loud

    Pretty neat-o if you ask me.

  13. clarkjones revised this gist Oct 7, 2015. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,5 @@
    **Note: This is modified version of the haxex script created by @jasononeil**

    **This version allows for specifying compiler args in your script. so you can include and use libraries like mcli**

    This is a tiny shell script that you can use to make scripting with Haxe very straight forward.
  14. clarkjones revised this gist Oct 7, 2015. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,5 @@
    **Note: This is modified version of the haxex script created by @jasononeil*
    **Note: This is modified version of the haxex script created by @jasononeil**
    **This version allows for specifying compiler args in your script. so you can include and use libraries like mcli**

    This is a tiny shell script that you can use to make scripting with Haxe very straight forward.

  15. clarkjones revised this gist Oct 7, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    **Note: This is modified version of the haxex script created by Jason O'Neil**
    **Note: This is modified version of the haxex script created by @jasononeil*

    This is a tiny shell script that you can use to make scripting with Haxe very straight forward.

  16. clarkjones revised this gist Oct 7, 2015. 4 changed files with 59 additions and 28 deletions.
    15 changes: 0 additions & 15 deletions HaxeScript.hx
    Original file line number Diff line number Diff line change
    @@ -1,15 +0,0 @@
    #!/usr/bin/haxex

    // Run with "./HaxeScript.hx some args here"

    class HaxeScript
    {
    public static function main()
    {
    trace('Hi, the following ${Sys.args().length} arguments were passed in:');
    for (a in Sys.args())
    {
    trace (' $a');
    }
    }
    }
    38 changes: 38 additions & 0 deletions HelloWorld.hx
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    #!/usr/bin/env haxex -lib mcli @

    /**
    Say hello.
    Example inspired by ruby's "executable" lib example
    **/
    class HelloWorld extends mcli.CommandLine
    {
    /**
    Say it in uppercase?
    **/
    public var loud:Bool;

    /**
    Show this message.
    **/
    public function help()
    {
    Sys.println(this.showUsage());
    Sys.exit(0);
    }

    public function runDefault(?name:String)
    {
    if(name == null)
    name = "World";
    var msg = 'Hello, $name!';
    if (loud)
    msg = msg.toUpperCase();
    Sys.println(msg);
    }

    public static function main()
    {
    new mcli.Dispatch(Sys.args()).dispatch(new HelloWorld());
    }

    }
    18 changes: 13 additions & 5 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,20 +1,26 @@
    **Note: This is modified version of the haxex script created by Jason O'Neil**

    This is a tiny shell script that you can use to make scripting with Haxe very straight forward.

    Using a straight #!/usr/bin/haxe doesn't work currently, as the Haxe compiler will have to be a little more clever about realising it is a shell script and that we wish to execute it. Maybe this will be native some day, for now, you can install the script below into `/usr/bin/haxex` and then use that.

    Installation:
    **if you're using OS X El Capitain you'll probably need to put haxex in /usr/local/bin/**

    1. `sudo nano /usr/bin/haxex`, paste the 'haxex' file in there
    2. `sudo chmod +x /usr/bin/haxex`
    2. `sudo chmod +x /usr/bin/haxex`

    Usage:

    #!/usr/bin/haxex
    #!/usr/bin/env haxex -debug @
    class MyScript
    {
    public static function main()
    {
    trace('My Script is executing!');
    #if debug
    trace('with debug flag!');
    #end
    }
    }

    @@ -27,11 +33,13 @@ Pretty neat-o if you ask me.

    What this script actually does:

    1. Reads the first argument as "filename"
    2. Gets rid of the "./" at the start of $filename
    3. Gets rid of the ".hx" at the end of $filename
    1. Replaces '@' with --run
    2. Gets rid of "./" at the start of filename
    3. Gets rid of the ".hx" at the end of filename
    4. Turns the "/" dir separators into "." package separators, in case your script is in a subpackage.

    Limitations:

    Currently the first occurance of './' will be stripped and '/' will be replaced with '.' so avoiding using these symbols in your args is probably best for now

    If your script is in the root package (has no `package` statement at the top of the file), then you need to call it from the directory the script is in. If your script is in a sub-package, you need to call it from the root-level package. Easy rule of thumb: don't use packages, and call from the directory the script is in.
    16 changes: 8 additions & 8 deletions haxex
    Original file line number Diff line number Diff line change
    @@ -1,15 +1,15 @@
    #!/bin/bash
    args=${@:1}

    # First argument is the filename
    filename=$1

    # Remove "./" if it's there
    filename=${filename/"./"/""}
    args=${args/@/" --run"}

    # Remove ".hx" if it's there
    filename=${filename/".hx"/""}
    args=${args/\.hx/""}

    # Remove "./" if it's there
    args=${args/\.\//""}

    # Change "/" to "."
    filename=${filename/"/"/"."}
    args=${args/\//"."}

    haxe --run $filename ${@:2}
    haxe $args
  17. @jasononeil jasononeil created this gist Apr 22, 2013.
    15 changes: 15 additions & 0 deletions HaxeScript.hx
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    #!/usr/bin/haxex

    // Run with "./HaxeScript.hx some args here"

    class HaxeScript
    {
    public static function main()
    {
    trace('Hi, the following ${Sys.args().length} arguments were passed in:');
    for (a in Sys.args())
    {
    trace (' $a');
    }
    }
    }
    37 changes: 37 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,37 @@
    This is a tiny shell script that you can use to make scripting with Haxe very straight forward.

    Using a straight #!/usr/bin/haxe doesn't work currently, as the Haxe compiler will have to be a little more clever about realising it is a shell script and that we wish to execute it. Maybe this will be native some day, for now, you can install the script below into `/usr/bin/haxex` and then use that.

    Installation:

    1. `sudo nano /usr/bin/haxex`, paste the 'haxex' file in there
    2. `sudo chmod +x /usr/bin/haxex`

    Usage:

    #!/usr/bin/haxex
    class MyScript
    {
    public static function main()
    {
    trace('My Script is executing!');
    }
    }

    Running:

    chmod +x MyScript.hx
    ./MyScript.hx

    Pretty neat-o if you ask me.

    What this script actually does:

    1. Reads the first argument as "filename"
    2. Gets rid of the "./" at the start of $filename
    3. Gets rid of the ".hx" at the end of $filename
    4. Turns the "/" dir separators into "." package separators, in case your script is in a subpackage.

    Limitations:

    If your script is in the root package (has no `package` statement at the top of the file), then you need to call it from the directory the script is in. If your script is in a sub-package, you need to call it from the root-level package. Easy rule of thumb: don't use packages, and call from the directory the script is in.
    15 changes: 15 additions & 0 deletions haxex
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    #!/bin/bash

    # First argument is the filename
    filename=$1

    # Remove "./" if it's there
    filename=${filename/"./"/""}

    # Remove ".hx" if it's there
    filename=${filename/".hx"/""}

    # Change "/" to "."
    filename=${filename/"/"/"."}

    haxe --run $filename ${@:2}