@ Nonnull protected Completer discoverCompleter ( ) { log . debug ( "Discovering completer" ) ; // TODO: Could probably use CliProcessorAware to avoid re-creating this CliProcessor cli = new CliProcessor ( ) ; cli . addBean ( this ) ; List < ArgumentDescriptor > argumentDescriptors = cli . getArgumentDescriptors ( ) ; Collections . sort ( argumentDescriptors ) ; if ( log . isDebugEnabled ( ) ) { log . debug ( "Argument descriptors:" ) ; argumentDescriptors . forEach ( descriptor -> log . debug ( " {}" , descriptor ) ) ; } List < Completer > completers = new LinkedList <> ( ) ; // attempt to resolve @Complete on each argument argumentDescriptors . forEach ( descriptor -> { AccessibleObject accessible = descriptor . getSetter ( ) . getAccessible ( ) ; if ( accessible != null ) { Complete complete = accessible . getAnnotation ( Complete . class ) ; if ( complete != null ) { Completer completer = namedCompleters . get ( complete . value ( ) ) ; checkState ( completer != null , "Missing named completer: %s" , complete . value ( ) ) ; completers . add ( completer ) ; } } } ) ; // short-circuit if no completers detected if ( completers . isEmpty ( ) ) { return NullCompleter . INSTANCE ; } if ( log . isDebugEnabled ( ) ) { log . debug ( "Discovered completers:" ) ; completers . forEach ( completer -> { log . debug ( " {}" , completer ) ; } ) ; } // append terminal completer for strict completers . add ( NullCompleter . INSTANCE ) ; ArgumentCompleter completer = new ArgumentCompleter ( completers ) ; completer . setStrict ( true ) ; return completer ; }
Discover the completer for the command .