Package org.jboss.fresh.shell.commands

Source Code of org.jboss.fresh.shell.commands.AliasExe

package org.jboss.fresh.shell.commands;

import org.jboss.fresh.io.BufferWriter;
import org.jboss.fresh.io.PrintWriter2;
import org.jboss.fresh.shell.AbstractExecutable;
import org.jboss.fresh.shell.impl.ShellImpl;

import java.util.Iterator;

import java.util.Map;


// EX OK

public class AliasExe extends AbstractExecutable {
  private static transient org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(AliasExe.class);

  /**
   Displays file information of the files specified with props.
   */


  public void process(String exename, String[] params) throws Exception {
    log.debug("entered");

    if (helpRequested()) {
      PrintWriter2 out = new PrintWriter2(new BufferWriter(getStdOut()));
      out.println("Usage: alias [--help] [-ex] <alias> <command_line>");
            out.println("    command_line parameter can be several parameters which will be concatenated");
            out.println("                 and seperated by spaces");
            out.println("    --list    : list existing aliases");
            out.println("    --listfull : list existing aliases and their values");
            out.println("    --help    : this help");
      out.close();
      log.debug("done");
      return;
    }

        String alias = null;
        if(params.length > 0) {

            alias = params[0];
            boolean full = "--listfull".equals(alias);

            if("--list".equals(alias) || full) {
                Map aliases = ((ShellImpl)shell).getRuntime().listAliases();
                PrintWriter2 out = new PrintWriter2(new BufferWriter(getStdOut()));
                Iterator it = aliases.entrySet().iterator();
                while(it.hasNext()) {
                    Map.Entry ent = (Map.Entry) it.next();
                    out.println(ent.getKey() + ( full ?  "\t\t" + ent.getValue() : ""));
                }
                out.flush();
                return;
            }
        }


        if(params.length < 2) {
            error("No alias name or replace command specified");
            return;
        }

        alias = params[0];

        if("--remove".equals(alias)) {
            ((ShellImpl)shell).getRuntime().removeAlias(params[1]);
        } else {

            StringBuffer val = new StringBuffer();

            for (int i = 1; i < params.length; i++) {
                if(i > 1)
                    val.append(" ");

                val.append(params[i]);
            }

            ((ShellImpl)shell).getRuntime().addAlias(alias, val.toString());
        }

        log.debug("done");

  }
}
TOP

Related Classes of org.jboss.fresh.shell.commands.AliasExe

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.