GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — gh-133934: Improve `.help` in the `sqlite3` CLI by tanloong · Pull Request #133935 · python/cpython Conversation
|
|
Hi @StanFromIreland , thank you for your review!
Good point! I agree and will update the code.
I'm not quite clear about which parts you find problematic. It would be very helpful if you could point out specific examples where the color logic is inconsistent or where the helper functions are misused or neglected. That way, I can address the issues precisely.
I have reviewed the current changes and didn't find any redundant definitions. If you could indicate the exact locations where you see this duplication, I'll take another close look and make improvements. Thank your again for your help! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| PS1 = "sqlite> " | ||
| PS2 = " ... " |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Remove these and use sys.ps1 like before, this would break current behavior.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The self.PS1 is needed by this line to get the length of plain prompt string. The length can't be obtained through sys.ps1 because sys.ps1 has surrounding control sequences for coloring.
I tested it and it doesn't break current behavior.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| def do_version(self, _): | ||
| """.version | ||
|
|
||
| Show version of the runtime SQLite library. |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| Show version of the runtime SQLite library. | |
| Print version of the runtime SQLite library. |
This is the more common way of describing this. And also this does not need a new function.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Just as explained at #133935 (comment), we do need a function here.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
| self._print_commands(self.undoc_header, cmds_undoc, 80) | ||
| else: | ||
| arg = arg.split()[0] | ||
| if arg in ("-all", "--all"): |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
We should not have both. Please only keep the -- option, we could have -a too but it is unnecessary IMO
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| if (method := getattr(self, "do_" + arg, None)) is not None: | ||
| print(self._help_message_from_doc(method.__doc__)) | ||
| else: | ||
| self._error(f"No help for '{arg}'") |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Just use print and add the theme normally IMO
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| def do_quit(self, _): | ||
| """.q(uit) | ||
|
|
||
| Exit this program. | ||
| """ | ||
| sys.exit(0) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Not needed?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Although it's just a one-liner we still need to put it in a function with a do_ prefix to mark it as a dot command. That way the quit command is accessible by .help.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| do_q = do_quit | ||
|
|
||
| def _help_message_from_doc(self, doc): | ||
| # copied from Lib/pdb.py#L2544 |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This will change, we don't need it anyway for inter-stdlib copies
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| self.write(f"{t.message}{msg}{t.reset}\n") | ||
|
|
||
| def _print_commands(self, header, cmds, maxcol): | ||
| # copied and modified from Lib/cmd.py#L351 |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
ditto
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| Each column is only as wide as necessary. | ||
| Columns are separated by two spaces (one was not legible enough). | ||
| """ | ||
| # copied and modified from Lib/cmd.py#L359 |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
ditto
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| Make ``.help`` in the :mod:`sqlite3` command-line interface print list of | ||
| available commands and ``.help <command>`` prints help for that command. |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| Make ``.help`` in the :mod:`sqlite3` command-line interface print list of | |
| available commands and ``.help <command>`` prints help for that command. | |
| Make ``.help`` in the :mod:`sqlite3` command-line interface print a list of | |
| available commands and ``.help <command>`` print help for that command. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I have a feeling you overdid it. We do not want to implement an exact replica of the But the final decision is up to @erlend-aasland. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
+1, IMO a reasonable approach would be non-intrusive and have a much lower diff. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I did not have a chance to look at this PR yet, but I'll add that we do not want to replicate the SQLite shell. When we initially added the sqlite3 CLI, we had in mind that the code would be easy to read and well commented, so it could be used as a kind of tutorial for how to use the interactive console class. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Feeling down on this in past few days. I want to explain that the goal of this PR isn't to replicate |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Currently we have just 3 simple commands (none of them are strictly necessary). Their implementation takes like 13 lines. This PR doubles the size of __main__.py. It improves .help, but it was not necessary, and it spends too much code for this.
If we had 20 commands, with arguments, then this would be the right way.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Another approach to implementing this, #135224, has been merged. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.