private File modulesDir;
public ASModuleHandler(CommandContext ctx) {
super("module", false);
final FilenameTabCompleter pathCompleter = Util.isWindows() ? new WindowsFilenameTabCompleter(ctx) : new DefaultFilenameTabCompleter(ctx);
final CommandLineCompleter moduleNameCompleter = new CommandLineCompleter() {
@Override
public int complete(CommandContext ctx, String buffer, int cursor, List<String> candidates) {
String path = buffer.replace('.', File.separatorChar);
String modulesPath;
try {
modulesPath = getModulesDir().getAbsolutePath() + File.separatorChar;
} catch (CommandLineException e) {
return -1;
}
int result = pathCompleter.complete(ctx, modulesPath + path, cursor, candidates);
if(result < 0) {
return result;
}
for(int i = 0; i < candidates.size(); ++i) {
candidates.set(i, candidates.get(i).replace(File.separatorChar, '.'));
}
return result - modulesPath.length();
}
};
name = new ArgumentWithValue(this, moduleNameCompleter, "--name");
name.addRequiredPreceding(action);
mainClass = new AddModuleArgument("--main-class");
resources = new AddModuleArgument("--resources", new CommandLineCompleter(){
@Override
public int complete(CommandContext ctx, String buffer, int cursor, List<String> candidates) {
final int lastSeparator = buffer.lastIndexOf(PATH_SEPARATOR);
if(lastSeparator >= 0) {
return lastSeparator + 1 + pathCompleter.complete(ctx, buffer.substring(lastSeparator + 1), cursor, candidates);
}
return pathCompleter.complete(ctx, buffer, cursor, candidates);
}}) {
@Override
public String getValue(ParsedCommandLine args) {
String value = super.getValue(args);
if(value != null) {
if(value.length() >= 0 && value.charAt(0) == '"' && value.charAt(value.length() - 1) == '"') {
value = value.substring(1, value.length() - 1);
}
value = pathCompleter.translatePath(value);
}
return value;
}
};