Thanks for your help.<br><br><br>thanks,<br>yuanzheng.<br><br>2011/3/8 Dave Angel <span dir="ltr"><<a href="mailto:davea@ieee.org">davea@ieee.org</a>></span><br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div><div></div><div class="h5">On 01/-10/-28163 02:59 PM, yuan zheng wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Hello, everyone:<br>
<br>
I encouter a question when implementing a commmand line(shell).<br>
I have implemented some commands, such as "start", "stop", "quit",<br>
they are easily implemented by "do_start", "do_stop" and "do_quit".<br>
there are no troubles.<br>
But I want to implement some commands like these "list-modules",<br>
"show-info". There is a character "-" among the string. So I can't easily<br>
use "do_list-modules", because the name is invalid. I attempt another<br>
ways, add a sentense in function "cmd.onecmd":<br>
-------------------------------------------------------<br>
def onecmd(self, line):<br>
line = line.replace("-", "_") # I add<br>
...<br>
-------------------------------------------------------<br>
Then, I can use "do_list_modules" to mach "list-modules" command. But in<br>
this way, completion cannot work correctly. If I input "list-", and then<br>
"tab",<br>
it would not complete.<br>
<br>
If my way is correct when encoutering commands with "-" ?<br>
If it's correct, how can I implement completion to work correctly?<br>
<br>
<br>
<br>
thanks,<br>
yuanzheng.<br>
<br>
</blockquote>
<br></div></div>
The problem with the replace() is that if there are any other dashes in the command, you'll replace them as well. Further, there are lots of other characters that are legal in program names that are not legal in variable names.<br>
<br></blockquote><div>My commands have just one '-', so I don't worry this problem.<br> <br></div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
It isn't clear why you care that the do_show_info function has a name that is transformable from the show-info command string. A shell has a few builtin commands, but most of them are simply names of external files, and it's those which would have dashes or other awkward characters. Are you planning to have a separate function for every one of those possible external programs?<br>
<br></blockquote><div>The reason I use this ways is that, some commands often use this feature and they are all use python to implement. So I think there is sth.<br>wrong with my program or sth I don't know about python.<br>
</div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
As for tab-completion, you haven't given us any clue about your environment (Linux, OS/MFT, ...), nor how the tab completion is caused currently. Ideally, on a shell, the tab completion algorithm would be much different than it would for normal programmatic access. In particular, when completing the first name on the line, tab completion should use the PATH, and when completing other names, it should escape characters like space, tab and backslash.<br>
<br></blockquote><div>Enviroment: Linux 2.6.35-23-generic x86_64 GNU/Linux , ubuntu 10.10.<br> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
DaveA<br>
</blockquote></div><br>