/** * Perform the 'alias' command. * * @param session JSwat session on which to operate. * @param args Tokenized string of command arguments. * @param out Output to write messages to. */ public void perform(Session session, CommandArguments args, Log out) { CommandManager cmdman = (CommandManager) session.getManager(CommandManager.class); if (args.hasMoreTokens()) { String aliasName = args.nextToken(); if (args.hasMoreTokens()) { // Grab rest of string as alias value. // Be sure to preserve the quotes and escapes. args.returnAsIs(true); String alias = args.rest().trim(); if (alias.charAt(0) == '"' && alias.charAt(alias.length() - 1) == '"') { // Must remove the enclosing quotes because the // command parser doesn't handle that. alias = alias.substring(1, alias.length() - 1); } // Add the command alias to the list. cmdman.createAlias(aliasName, alias); out.writeln(Bundle.getString("alias.defined") + ' ' + aliasName); } else { // One argument, show the alias definition. String alias = cmdman.getAlias(aliasName); if (alias == null) { throw new CommandException(Bundle.getString("alias.undefined") + ' ' + aliasName); } else { out.writeln("alias " + aliasName + ' ' + alias); } } } else { // No arguments, show the defined aliases. cmdman.listAliases(); } } // perform