# HG changeset patch # User František Kučera # Date 1439682044 -7200 # Node ID e38910065d558dd31f2ce11c3f478d109af5eb28 # Parent 0bc544b38cfab4d6b5a3f0dafe262279f64c1699 bash-completion: --formatter-property choices: first working version diff -r 0bc544b38cfa -r e38910065d55 java/sql-dk/src/info/globalcode/sql/dk/CLIStarter.java --- 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 formatterClass = (Class) Class.forName(fd.getClassName()); List> hierarchy = Functions.getClassHierarchy(formatterClass, Formatter.class); Collections.reverse(hierarchy); - hierarchy.stream().forEach((c) -> { + for (Class 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 { diff -r 0bc544b38cfa -r e38910065d55 scripts/bash_completion.pl --- 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