/** * Return true if the given scope is the global scope so that it can be hidden from help messages. * * @param session The command session. * @param scope The command scope. * @return True if the scope is global, false else. */ public static boolean isGlobalScope(CommandSession session, String scope) { if (session == null) return false; if (!isMultiScopeMode(session)) { String globalScope = (String) session.get("APPLICATION"); if (globalScope != null) { return scope.equals(globalScope); } } return false; }
/** * Return the name of the command which can omit the global scope prefix if the command starts with the * same prefix as the current application. * * @param session The command session. * @param key The command key. * @return The command name without the global prefix. */ public static String getCommandNameWithoutGlobalPrefix(CommandSession session, String key) { if (!isMultiScopeMode(session)) { String globalScope = (String) (session != null ? session.get("APPLICATION") : null); if (globalScope != null) { String prefix = globalScope + ":"; if (key.startsWith(prefix)) { // TODO we may only want to do this for single-scope mode when outside of OSGi? // so we may want to also check for a isMultiScope mode == false return key.substring(prefix.length()); } } } return key; }