Opened 7 years ago

Closed 7 years ago

#28398 closed New feature (fixed)

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: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
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 7 years ago.
screenshot
candidate-commands.diff (1.2 KB ) - added by Vlada Macek 7 years ago.
a patch

Download all attachments as: .zip

Change History (10)

by Vlada Macek, 7 years ago

Attachment: autocomplete.png added

screenshot

by Vlada Macek, 7 years ago

Attachment: candidate-commands.diff added

a patch

comment:1 by Tim Graham, 7 years ago

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 by Vlada Macek, 7 years ago

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 by Tim Graham, 7 years ago

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 by Shai Berger, 7 years ago

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 by Tom Forbes, 7 years ago

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 7 years ago by Tom Forbes (previous) (diff)

comment:7 by Carlton Gibson, 7 years ago

Patch needs improvement: unset
Triage Stage: Someday/MaybeReady for checkin

Tom's new PR looks great.

comment:8 by Tim Graham <timograham@…>, 7 years ago

Resolution: fixed
Status: newclosed

In 33ac036a:

Fixed #28398 -- Added suggestions for mistyped management commands.

Note: See TracTickets for help on using tickets.
Back to Top