bash-completion: --formatter-property choices: first working version v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Sun, 16 Aug 2015 01:40:44 +0200
branchv_0
changeset 221e38910065d55
parent 220 0bc544b38cfa
child 222 5ffeb18b6f85
bash-completion: --formatter-property choices: first working version
java/sql-dk/src/info/globalcode/sql/dk/CLIStarter.java
scripts/bash_completion.pl
     1.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/CLIStarter.java	Sun Aug 16 01:25:01 2015 +0200
     1.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/CLIStarter.java	Sun Aug 16 01:40:44 2015 +0200
     1.3 @@ -239,7 +239,7 @@
     1.4  		}
     1.5  	}
     1.6  
     1.7 -	private void writeBashCompletionHelperFileForFormatterProperties(File formattersDir) throws ClassNotFoundException {
     1.8 +	private void writeBashCompletionHelperFileForFormatterProperties(File formattersDir) throws ClassNotFoundException, FileNotFoundException {
     1.9  		if (Constants.CONFIG_FILE.lastModified() > formattersDir.lastModified()) {
    1.10  			// TODO: delete old directory
    1.11  			formattersDir.mkdir();
    1.12 @@ -250,12 +250,20 @@
    1.13  				Class<Formatter> formatterClass = (Class<Formatter>) Class.forName(fd.getClassName());
    1.14  				List<Class<? extends Formatter>> hierarchy = Functions.getClassHierarchy(formatterClass, Formatter.class);
    1.15  				Collections.reverse(hierarchy);
    1.16 -				hierarchy.stream().forEach((c) -> {
    1.17 +				for (Class<? extends Formatter> c : hierarchy) {
    1.18  					for (PropertyDeclaration p : Functions.getPropertyDeclarations(c)) {
    1.19  						File propertyDir = new File(formatterDir, p.name());
    1.20  						propertyDir.mkdir();
    1.21 +						File choicesFile = new File(propertyDir, "choices");
    1.22 +						try (PrintWriter fw = new PrintWriter(choicesFile)) {
    1.23 +							// TODO: refactor, move
    1.24 +							if (p.type() == Boolean.class) {
    1.25 +								fw.println("true");
    1.26 +								fw.println("false");
    1.27 +							}
    1.28 +						}
    1.29  					}
    1.30 -				});
    1.31 +				}
    1.32  			}
    1.33  			log.log(Level.FINE, "Bash completion helper files was written in: {0}", formattersDir);
    1.34  		} else {
     2.1 --- a/scripts/bash_completion.pl	Sun Aug 16 01:25:01 2015 +0200
     2.2 +++ b/scripts/bash_completion.pl	Sun Aug 16 01:40:44 2015 +0200
     2.3 @@ -63,10 +63,11 @@
     2.4  
     2.5  _sql_dk_bash_completion_formatter_property_choice() {
     2.6  	local property="${COMP_WORDS[COMP_CWORD-1]}";
     2.7 -	echo true;
     2.8 -	echo false;
     2.9 -	echo "TODO_$property";
    2.10 -	# TODO: find choices for the property  
    2.11 +	local formatter_dir='.$formatterPropertiesDir.'/$formatter
    2.12 +	local property_choices_file=$formatter_dir/$property/choices;
    2.13 +	if [ -f $property_choices_file ]; then
    2.14 +		cat $property_choices_file;
    2.15 +	fi
    2.16  }
    2.17  
    2.18  _sql_dk_bash_completion() {
    2.19 @@ -110,6 +111,7 @@
    2.20  	esac;
    2.21  	
    2.22  	if [ "x${COMP_WORDS[COMP_CWORD-2]}" == "x--formatter-property" ]; then
    2.23 +		formatter=$( _sql_dk_bash_completion_find_formatter "${COMP_WORDS[@]}" );
    2.24  		COMPREPLY=( $( compgen -W "$(_sql_dk_bash_completion_formatter_property_choice )" -- $cur ) ); 
    2.25  		return 0;
    2.26  	fi