Re: Adding code and methods to a class dynamically



Sarir Khamsi wrote:
Thanks, this is amazingly more simple than what I had. This works
fine but I'm looking at the code for cmd and don't really see how you
get completion to work on the new alias.

I'm not sure what "completion" means in this case, and I'm not aware of any "command-line completion" support in cmd.Cmd though it may well be there, so I can't say. Certainly there is nothing in any way different about the new attribute created by the alias code, as both it and the original attribute are bound to exactly the same method.


Also, I would like the alias to have arguments:
alias newName existingName arg1 arg2 ...

Currying comes to mind, but I haven't tried it yet. Thanks again for
the help.

It sounds like currying, but I'd suggest implementing such a thing with a completely separate layer on top of the existing Cmd stuff, probably through overriding .default() and doing a lookup in a dictionary, then building a command line with the original command and maybe executing it with .onecmd() if that can work from within the .cmdloop(). Lots of possibilities there; haven't tried any myself.


-Peter
.



Relevant Pages

  • Re: What FREQS for VHF Packet?
    ... Yes we still have a dedicated TheNet packet vhf ... on top of Mt Haleakala on MAUI island, also on MT Maunaloa on the big ... c mloa (which then connects to the alias MLOA so that covers most ... someone os actually send tfc via the talk cmd if a host is available. ...
    (rec.radio.amateur.digital.misc)
  • Re: OT: the rm bug hit me again
    ... And the -f in the rm command it to stop the "Confirm delete?" ... My rm is set to confirm all deletes using alias. ... the reason is to help prevent those type human errors when you are root ... I personally like the prompt because it reminds me that I am running as ...
    (Fedora)
  • Re: Def alias error in RACF
    ... to define an Alias in a RACF environment with z/OS V1.7 release? ... At the moment to send the request in command line (through the RACF ... Actually, that's a TSO command, not a RACF command. ...
    (bit.listserv.ibm-main)
  • Re: OT: the rm bug hit me again
    ... And the -f in the rm command it to stop the "Confirm delete?" ... That's not a good idea as it teaches you to expect to be prompted, and you'll be bitten badly some time when the alias isn't present. ... the reason is to help prevent those type human errors when you are root ... A user who expects rm to prompt will only delete their own files if it doesn't, a root user who expects rm to prompt can delete the entire system if it doesn't. ...
    (Fedora)
  • TCPIP glitch wih aliases
    ... I needed to move the cluster alias IP from an alpha to a vax. ... Turns out the above command disabled all IPs on the WE0 interface, AND zapped the permanent routes from the active database. ... doing IFCONFIG WE0 10.0.0.11 up seemed to work, but it did not restor the routes so that node had no way to reach IPs outside its subnet. ...
    (comp.os.vms)