Package org.platformlayer.keystone.cli.autocomplete

Source Code of org.platformlayer.keystone.cli.autocomplete.UserNameAutoCompleter

package org.platformlayer.keystone.cli.autocomplete;

import java.util.List;

import org.platformlayer.auth.UserDatabase;
import org.platformlayer.keystone.cli.KeystoneCliContext;

import com.fathomdb.cli.CliContext;
import com.fathomdb.cli.autocomplete.SimpleArgumentAutoCompleter;

public class UserNameAutoCompleter extends SimpleArgumentAutoCompleter {

  @Override
  public List<String> doComplete(CliContext context, String prefix) throws Exception {
    if (prefix.length() < 3) {
      // Let's avoid returning thousands of users
      return null;
    }

    KeystoneCliContext keystoneContext = (KeystoneCliContext) context;
    UserDatabase userRepository = keystoneContext.getUserRepository();
    List<String> userIds = userRepository.listAllUserNames(prefix);
    addSuffix(userIds, " ");

    return userIds;
  }

}
TOP

Related Classes of org.platformlayer.keystone.cli.autocomplete.UserNameAutoCompleter

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.