001package votorola.s.line; // Copyright 2008, Michael Allan.  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Votorola Software"), to deal in the Votorola Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicence, and/or sell copies of the Votorola Software, and to permit persons to whom the Votorola Software is furnished to do so, subject to the following conditions: The preceding copyright notice and this permission notice shall be included in all copies or substantial portions of the Votorola Software. THE VOTOROLA SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE VOTOROLA SOFTWARE OR THE USE OR OTHER DEALINGS IN THE VOTOROLA SOFTWARE.
002
003import java.io.*;
004import java.util.*;
005import votorola.a.response.line.*;
006import votorola.g.*;
007import votorola.g.lang.*;
008import votorola.g.logging.*;
009import votorola.g.option.*;
010import votorola.g.script.*;
011
012
013/** Main class of the executable <code>voscript</code> - an interpreter to test the
014  * compilation of a configuration script.
015  *
016  *     @see <a href='../../../../../s/manual.xht#line-voscript' target='_top'>voscript</a>
017  */
018public @ThreadSafe final class VOScript
019{
020
021    private VOScript() {}
022
023
024
025    /** Executes from the command line.
026      *
027      *     @param argv command line argument array
028      */
029    public static void main( final String[] argv )
030    {
031        LoggerX.i(VOScript.class).info( "voscript is running with arguments " + Arrays.toString( argv ));
032        final Map<String,Option> optionMap = CommandLine.compileBaseOptions();
033        final int aFirstNonOption = GetoptX.parse( "voscript", argv, optionMap );
034        if( optionMap.get("help").hasOccured() )
035        {
036            System.out.print
037            (
038              "Usage: voscript SCRIPT-FILE\n" +
039              "Test the compilation of a configuration script.\n"
040            );
041            System.exit( 0 );
042        }
043
044        String scriptFilePath = null; // final after init
045        {
046            final int addressCount = argv.length - aFirstNonOption;
047            if( addressCount > 1 )
048            {
049                System.err.println( "voscript: too many arguments" );
050                System.err.println( GetoptX.createHelpPrompt( "voscript" ));
051                System.exit( 1 );
052            }
053            else if( addressCount == 1 ) scriptFilePath = argv[aFirstNonOption];
054            else
055            {
056                System.err.println( "voscript: missing SCRIPT-FILE argument" );
057                System.err.println( GetoptX.createHelpPrompt( "voscript" ));
058                System.exit( 1 );
059            }
060        }
061
062        try
063        {
064            File scriptFile = new File( scriptFilePath );
065            new JavaScriptIncluder( scriptFile );
066        }
067        catch( RuntimeException x ) { throw x; }
068        catch( Exception x ) // IOException, ScriptException
069        {
070            System.err.print( "voscript: fatal error" + Votorola.unmessagedDetails(x) + ": " );
071         // System.err.println( x );
072            x.printStackTrace( System.err );
073            System.exit( 1 );
074        }
075    }
076
077
078
079}