Broken command completion in shell

Project:JNode Core
Component:Code
Category:bug report
Priority:critical
Assigned:Stephen Crawley
Status:closed
Description

The completion of parameters for certain commands is broken in the shell.
An example is the device command.
I type: device <TAB>
- at this point the device names should be listed too since they are valid arguments, not only the command parameters
I type: device restart <TAB>
- now the device names will be listed but the command will be completed to: device restart restart ,which is wrong
An other command with similar problems is plugin.
I suggest to test all commands where parameter completion is important.

#1

Status:active» closed

#2

This issue actually covers two separate problems.

The first example is happening because the command is defining multiple syntaxes. IIRC, the completion code tries to complete with each Syntax, then picks the one which matches the longest completion. At any rate, it only populates the alternatives list using the results of one Argument's complete method. This behavior has been there since before I started working on the code. It is really a "feature" ... given the current implementation.

The second example is a bug. I should be able to work out what is going on.

Incidentally, the current way that we do Syntax parsing and completion is broken in other ways. For a start, it doesn't cope with completion of shell metasyntax, redirections, etc. Furthermore there is quite a bit of brokeness in the Argument / Option classes that supposedly denote command option syntax. I cannot recall the precise details, but I remember that the meaning of some of the classes was unclear, and that some common forms of (UNIX) command syntax were inexpressible.

I have been trying to overhaul this, but I haven't yet figured out the right way to implement it all. I suspect that completion needs to be done using contextual callbacks from the shell's interpreter rather than trying to do the work in the Syntax class. It all amounts to a lot of difficult (i.e. hard to get your head around) work.

#3

This patch fixes up java indentation (no tabs, 4 spaces per level), adds copyright blocks, adds some class javadoc and fixes some eclipse compiler warnings.

Please apply this one, and I will work up a fix for the reported problem(s) and create a patch for it. Thanks.

#4

Arghh ... I had unsaved files. Here's the patch again.

#5

Committed.

#6

Here's a patch for the second example; i.e. the one that is easy to fix.

It is not perfect. For instance, I notice that when I try to TAB complete "device restart loopback" it adds an extra space at the end, then a second TAB removes it again. But the code is so convoluted that I fear the attempting to improve it further will break something else.

I had a second look at the other example; i.e. the "feature". Fixing it would be difficult given the current syntax parsing / completion framework. I'd prefer to spend the time on my attempted rewrite ... for now.

#7

Committed. Thank you.

#8

I'm marking this BR closed now. If there are new bugs, please create a new bug report.