Exit Full View

Feather2 / documentation / CommandLine.md

Command Line

This document assumes you have good command line tools, which are NOT present in Windows. I strongly suggest Windows users should install decent command-line tools. Don't use CMD.EXE, it is an outdated relic from the DOS era. Use bash or similar instead. Bing it, if you don't know how to install bash ;-)

Feather's root project includes an executable called feather2 which compiles & runs Feather scripts, making it ideal for simple command-line applications.

The entry point is the standard main method. e.g. The preferred file extension is feather, so save this as MyCommandLineTool.feather :

class MyCommandLineTool {    
    static fun main( args : String ... ) {
    }
}

To run this script :

feather2 MyCommandLineTool.feather

Feather Configuration

These scripts do not use the standard FeatherConfiguration.

  • There is no sanbox protection, you can use all the java standard libraries.
  • Commands are enabled.
  • A special library directive lets you use 3rd party Java/Kotlin libraries within your script.

Command Line Arguments

Both the feather2 program and your script may accept command line arguments. To distinguish between the two, use -- to indicate the end of the feather2 arguments, and the beginning of your script's arguments.

e.g. Using the HelloWorld.feather script as an example (in the project root) :

feather2 HelloWorld.feather -- foo bar

This script prints a greeting as well as each command line argument (indented), so the result is :

Hello World
    foo
    bar

If we omit the --, then foo and bar are assumed to be additional feather scripts filenames, and will likely result in an error message. (Unless foo and bar are files, which happen to contain valid Feather syntax!)

Feather Command Line Options

To see the full usage of feather2 :

feather2 --help

At the time of writing, the usage is :

feather2 [--mainClass=CLASSNAME] scriptFilename...

Unlike Java, mainClass is optional, and when omitted, the first feather class with a suitable main method is used as the entry point. So this is only required when you include more than one main method.

Shebang

On Linux, you can also make use of shebang (aka hash-bang), which is a special instruction at the very start of the script, which tells the operating system which program should run the script. Alas, shebangs requires absolute paths; here I've used my home directory's bin :

#!/home/nick/bin/feather2

class MyCommandLineTool {
    static fun main( args : String ... ) {
    }
}

If you make the script executable, you can then run it directly :

chmod +x MyCommandLineTool.feather
./MyCommandLineTool.feather

And if the script is in your PATH, then the ./ can also be omitted :

MyCommandLineTool.feather

Using shebang with feather2 is NOT supported by other unix-like operating systems, such as macOS, because feather2 is itself a script with a shebang and only Linux supports chaining of shabangs.