--- a/java/sql-dk/src/info/globalcode/sql/dk/CLIStarter.java Sun Aug 16 01:25:01 2015 +0200
+++ b/java/sql-dk/src/info/globalcode/sql/dk/CLIStarter.java Sun Aug 16 01:40:44 2015 +0200
@@ -239,7 +239,7 @@
}
}
- private void writeBashCompletionHelperFileForFormatterProperties(File formattersDir) throws ClassNotFoundException {
+ private void writeBashCompletionHelperFileForFormatterProperties(File formattersDir) throws ClassNotFoundException, FileNotFoundException {
if (Constants.CONFIG_FILE.lastModified() > formattersDir.lastModified()) {
// TODO: delete old directory
formattersDir.mkdir();
@@ -250,12 +250,20 @@
Class<Formatter> formatterClass = (Class<Formatter>) Class.forName(fd.getClassName());
List<Class<? extends Formatter>> hierarchy = Functions.getClassHierarchy(formatterClass, Formatter.class);
Collections.reverse(hierarchy);
- hierarchy.stream().forEach((c) -> {
+ for (Class<? extends Formatter> c : hierarchy) {
for (PropertyDeclaration p : Functions.getPropertyDeclarations(c)) {
File propertyDir = new File(formatterDir, p.name());
propertyDir.mkdir();
+ File choicesFile = new File(propertyDir, "choices");
+ try (PrintWriter fw = new PrintWriter(choicesFile)) {
+ // TODO: refactor, move
+ if (p.type() == Boolean.class) {
+ fw.println("true");
+ fw.println("false");
+ }
+ }
}
- });
+ }
}
log.log(Level.FINE, "Bash completion helper files was written in: {0}", formattersDir);
} else {
--- a/scripts/bash_completion.pl Sun Aug 16 01:25:01 2015 +0200
+++ b/scripts/bash_completion.pl Sun Aug 16 01:40:44 2015 +0200
@@ -63,10 +63,11 @@
_sql_dk_bash_completion_formatter_property_choice() {
local property="${COMP_WORDS[COMP_CWORD-1]}";
- echo true;
- echo false;
- echo "TODO_$property";
- # TODO: find choices for the property
+ local formatter_dir='.$formatterPropertiesDir.'/$formatter
+ local property_choices_file=$formatter_dir/$property/choices;
+ if [ -f $property_choices_file ]; then
+ cat $property_choices_file;
+ fi
}
_sql_dk_bash_completion() {
@@ -110,6 +111,7 @@
esac;
if [ "x${COMP_WORDS[COMP_CWORD-2]}" == "x--formatter-property" ]; then
+ formatter=$( _sql_dk_bash_completion_find_formatter "${COMP_WORDS[@]}" );
COMPREPLY=( $( compgen -W "$(_sql_dk_bash_completion_formatter_property_choice )" -- $cur ) );
return 0;
fi