public static void main ( String [ ] args ) { try { jCommander = new JCommander ( ) ; jCommander . setProgramName ( "cadmium" ) ; HelpCommand helpCommand = new HelpCommand ( ) ; jCommander . addCommand ( "help" , helpCommand ) ; Map < String , CliCommand > commands = wireCommands ( jCommander ) ; try { jCommander . parse ( args ) ; } catch ( ParameterException pe ) { System . err . println ( pe . getMessage ( ) ) ; System . exit ( 1 ) ; } String commandName = jCommander . getParsedCommand ( ) ; if ( commandName == null ) { System . out . println ( "Please use one of the following commands:" ) ; for ( String command : jCommander . getCommands ( ) . keySet ( ) ) { String desc = jCommander . getCommands ( ) . get ( command ) . getObjects ( ) . get ( 0 ) . getClass ( ) . getAnnotation ( Parameters . class ) . commandDescription ( ) ; System . out . format ( " %16s -%s\n" , command , desc ) ; } } else if ( commandName . equals ( "help" ) ) { if ( helpCommand . subCommand == null || helpCommand . subCommand . size ( ) == 0 ) { jCommander . usage ( ) ; return ; } else { JCommander subCommander = jCommander . getCommands ( ) . get ( helpCommand . subCommand . get ( 0 ) ) ; if ( subCommander == null ) { System . out . println ( "Unknown sub command " + commandName ) ; return ; } subCommander . usage ( ) ; return ; } } else if ( commands . containsKey ( commandName ) ) { CliCommand command = commands . get ( commandName ) ; if ( command instanceof AuthorizedOnly ) { setupSsh ( ( ( AuthorizedOnly ) command ) . isAuthQuiet ( ) ) ; setupAuth ( ( AuthorizedOnly ) command ) ; } command . execute ( ) ; } } catch ( Exception e ) { System . err . println ( "Error: " + e . getMessage ( ) ) ; logger . debug ( "Cli Failed" , e ) ; e . printStackTrace ( ) ; System . exit ( 1 ) ; } }
The main entry point to Cadmium cli .