| | |
| | | import com.google.common.base.Strings; |
| | | import com.google.common.collect.Maps; |
| | | |
| | | /** |
| | | * Parses an SSH command-line and dispatches the command to the appropriate |
| | | * BaseCommand instance. |
| | | * |
| | | * @since 1.5.0 |
| | | */ |
| | | public abstract class DispatchCommand extends BaseCommand implements ExtensionPoint { |
| | | |
| | | private Logger log = LoggerFactory.getLogger(getClass()); |
| | |
| | | * registered within this method. |
| | | * |
| | | * @param user |
| | | * @since 1.5.0 |
| | | */ |
| | | protected abstract void setup(UserModel user); |
| | | |
| | |
| | | return false; |
| | | } |
| | | |
| | | public String getDescription() { |
| | | return getClass().getAnnotation(CommandMetaData.class).description(); |
| | | } |
| | | |
| | | @Override |
| | | public String usage() { |
| | | Set<String> cmds = new TreeSet<String>(); |
| | |
| | | String format = "%-" + maxLength + "s %s"; |
| | | |
| | | final StringBuilder usage = new StringBuilder(); |
| | | if (!StringUtils.isEmpty(getName())) { |
| | | String title = getName().toUpperCase() + ": " + getDescription(); |
| | | String b = com.gitblit.utils.StringUtils.leftPad("", title.length() + 2, '═'); |
| | | usage.append('\n'); |
| | | usage.append(b).append('\n'); |
| | | usage.append(' ').append(title).append('\n'); |
| | | usage.append(b).append('\n'); |
| | | usage.append('\n'); |
| | | } |
| | | |
| | | if (!cmds.isEmpty()) { |
| | | usage.append("Available commands"); |
| | | if (!getName().isEmpty()) { |