001/* 002 * (C) Copyright 2006-2010 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * bstefanescu 018 */ 019package org.nuxeo.shell; 020 021import java.util.List; 022import java.util.Map; 023 024import jline.Completor; 025 026/** 027 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a> 028 */ 029public interface CommandType extends Comparable<CommandType> { 030 031 Class<?> getCommandClass(); 032 033 String getHelp(); 034 035 String getName(); 036 037 String[] getAliases(); 038 039 List<Token> getArguments(); 040 041 Map<String, Token> getParameters(); 042 043 String getSyntax(); 044 045 Runnable newInstance(Shell shell, String... line) throws ShellException; 046 047 Completor getLastTokenCompletor(Shell shell, String... line); 048 049 interface Setter { 050 Class<?> getType(); 051 052 void set(Object obj, Object value) throws ShellException; 053 } 054 055 class Token implements Comparable<Token> { 056 057 public String name; 058 059 public int index = -1; 060 061 public String help; 062 063 // for params required means value is required 064 public boolean isRequired; 065 066 public Setter setter; 067 068 public Class<? extends Completor> completor; 069 070 public boolean isArgument() { 071 return index > -1; 072 } 073 074 public int compareTo(Token o) { 075 return index - o.index; 076 } 077 078 } 079 080}