001 /*
002 * Copyright (C) 2010 eXo Platform SAS.
003 *
004 * This is free software; you can redistribute it and/or modify it
005 * under the terms of the GNU Lesser General Public License as
006 * published by the Free Software Foundation; either version 2.1 of
007 * the License, or (at your option) any later version.
008 *
009 * This software is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * You should have received a copy of the GNU Lesser General Public
015 * License along with this software; if not, write to the Free
016 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
017 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
018 */
019
020 package org.crsh.cmdline.spi;
021
022 import org.crsh.cmdline.ParameterDescriptor;
023
024 import java.util.Map;
025
026 /**
027 * A completer provides completion suffixes for a given prefix. The cmdline framework uses it when
028 * computing a completion.
029 *
030 * @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
031 * @version $Revision$
032 */
033 public interface Completer {
034
035 /**
036 * <p>Query the completer for a set of completion for the given prefix. The returned Map
037 * should provide the possible suffixes matching the prefix argument. Each map entry maps
038 * to a possible completion: an entry key is the possible completion, its corresponding
039 * boolean value indicates wether the value can be further more completed or not.
040 *
041 * The following guidelines
042 * should be respected:
043 *
044 * <ul>
045 * <li>An empty map means no completion can be determined, the framework will not do anything.</li>
046 * <li>A singleton map means the match was entire and the framework will complete it with the sole map entry.</li>
047 * <li>A map containing string sharing a common prefix instruct the framework to insert this common prefix.</li>
048 * <li>A list containing strings with no common prefix (other than the empty string) instruct the framework to display
049 * the list of possible completions.</li>
050 * </ul>
051 * <ul>When a match is considered as full (the entry value is set to true), the completion should contain a trailing value
052 * that is usually a white space (but it could be a quote for quoted values).</ul>
053 * </p>
054 *
055 * <p>Example: a completer that would complete colors could
056 * <ul>
057 * <li>return the map ["lack ":true,"lue ":true] for the prefix "b".</li>
058 * <li>return the amp ["e ":true] for the prefix "blu".</li>
059 * <li>return the map [] for the prefix "z".</li>
060 * </ul>
061 * </p>
062 *
063 * <p>Example: a completer that would complete java packages could
064 * <ul>
065 * <li>return the map ["ext":true,"ext.spi":false] for the prefix "java.t"</li>
066 * </ul>
067 * </p>
068 *
069 * @param parameter the completed parameter
070 * @param prefix the prefix to complete
071 * @return the possible suffix map
072 * @throws Exception any exception that would prevent completion to perform correctly
073 */
074 Map<String, Boolean> complete(ParameterDescriptor<?> parameter, String prefix) throws Exception;
075
076 }