Opened 4 months ago

Last modified 4 months ago

#28398 new New feature

Allow management command invocation to suggest commands for mistyped commands

Reported by: Vlada Macek Owned by: nobody
Component: Core (Management commands) Version: 1.11
Severity: Normal Keywords:
Cc: Shai Berger, Tom Forbes Triage Stage: Someday/Maybe
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

Too often I can't remember the full mgmt command name, but can remember a part of it.

A little enhancement would save me time.

Attaching a screenshot and a patch. Thanks.

Attachments (2)

autocomplete.png (4.8 KB) - added by Vlada Macek 4 months ago.
screenshot
candidate-commands.diff (1.2 KB) - added by Vlada Macek 4 months ago.
a patch

Download all attachments as: .zip

Change History (7)

Changed 4 months ago by Vlada Macek

Attachment: autocomplete.png added

screenshot

Changed 4 months ago by Vlada Macek

Attachment: candidate-commands.diff added

a patch

comment:1 Changed 4 months ago by Tim Graham

Easy pickings: unset
Patch needs improvement: set
Summary: manage.py should offer candidate commands via substring searchAllow management command invocation to suggest commands for mistyped commands
Triage Stage: UnreviewedSomeday/Maybe

I wonder if we could do something smarter than a substring search. Perhaps there are other libraries we could borrow ideas from. It would be appropriate to write the DevelopersMailingList to get feedback.

I wonder if this isn't somewhat redundant to the bash completion script though.

comment:2 Changed 4 months ago by Vlada Macek

Thanks for considering. I don't see this feature to require a considerable planning to be completed on first shot. It could evolve.
I was thinking about similarity string search etc., but ended up with the simplest change possible, a substring search. This version would start to help me.
Okay, adding colors wasn't the simplest, but just nice and can be removed.
I like simple clever hints to the user like this.
Bash completion is neat, but not always available and installed.

comment:3 Changed 4 months ago by Tim Graham

Since all features have development and maintenance costs, I'd like for others to confirm it's worth the effort before we commit to doing it.

comment:4 Changed 4 months ago by Shai Berger

Cc: Shai Berger added

I think Django should not try to be a shell helper -- shell completions do a pretty good job, and the use case you describe seems to be answered by

$ ./manage.py help | grep passw

That said, I can see why people would like to have such functionality -- or even more sophisticated options -- built into their manage.py. And it's a bit of a shame that they have to patch Django to do that. So, in my opinion, instead of taking the current simple patch, we should think how to make command invocation extensible.

And having written that, I just thought of this:

Step 1: Add a new management command enhanced_manage which takes all its arguments and options, does whatever it likes (e.g. make sure the first arg is actually the name of an existing command, and if not suggests alternatives), and if all is well ends with call_command() to execute the command given; so that you can get your functionality by running manage.py enhanced_manage passw, or run the full command as manage.py enhanced_manage changepassword username

Step 2: In your project, edit the file manage.py; replace the line

    execute_from_command_line(sys.argv)

with

    execute_from_command_line(['enhanced_manage'] + sys.argv)

And - tada! extensible command execution, no Django patching required. I suppose this way has some limitations I haven't thought about, and it may seem like a lot of work compared to your simple patch, but as Tim said (and you agreed) such features tend to evolve and become more complicated, and this way makes it possible for them to evolve outside of core, without even waiting for the next Django release.

comment:5 Changed 4 months ago by Tom Forbes

Cc: Tom Forbes added

I think this is definitely worth pursuing - it's not that complicated to add and it helps out beginners who are new to the whole manage.py experience. I think people are perhaps over-thinking this: providing 'did you mean' suggestions for typos has a lot of prior art including git, pip and the default bash on Ubuntu and shouldn't be complicated or require any interaction.

Simply printing out potential candidate commands when the user makes a typo is a quick and easy win IMO. Yes, users could use grep, but that assumes that they are familiar with such tools and are on a system that provides them. Plus learning a new tool like manage.py can be quite hard at the beginning and there is definitely a selection bias here of people who are familiar with Django and unix tooling in general. I wouldn't find this feature useful at all, but someone who is starting out with Django may.

For the completion suggestions, difflib.get_close_matches seems to be a good candidate rather than substring matching or rolling our own - plus it's in the stdlib.

Last edited 4 months ago by Tom Forbes (previous) (diff)
Note: See TracTickets for help on using tickets.
Back to Top