Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-133934: Improve.help in thesqlite3 CLI#133935

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
tanloong wants to merge3 commits intopython:main
base:main
Choose a base branch
Loading
fromtanloong:sqlite3-cli-help-more-helpful

Conversation

tanloong
Copy link
Contributor

@tanloongtanloong commentedMay 12, 2025
edited
Loading

Make.help in thesqlite3 CLI show a list of available commands, and.help <command> display help for that command. This matches the behavior of the SQLite CLI tool, though the output layout may not be exactly the same.

The new.help output looks like this:

  1. Without arguments, list available commands
sqlite> .help Documented commands (type .help <command>):===========================================help  q  quit  version
  1. With one command name, print help for that command
sqlite> .help help        Usage: .help [-all] [command]                Without argument, print the list of available commands.        With a command name as argument, print help about that command.        With more command names as arguments, only the first one is used.sqlite> .help unknownNo help for 'unknown'
  1. With-all or--all, print help for all commands
sqlite> .help -all.help [-all] [command]        Without argument, print the list of available commands.        With a command name as argument, print help about that command.        With more command names as arguments, only the first one is used..q(uit)        Exit this program..version        Show version of the runtime SQLite library.
  1. If passed with two or more arguments, only use the first one
sqlite> .help version unknown        Usage: .version                Show version of the runtime SQLite library.sqlite> .help unknown versionNo help for 'unknown'

Make `.help` print list of available commands and `.help <command>` prints help for that command
@tanloongtanloong marked this pull request as ready for reviewMay 12, 2025 15:09
Copy link
Contributor

@StanFromIrelandStanFromIreland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Please useprint( ... , file=sys.XXX) and notself.write, you must have not noticed the confusion it caused on your previous pr. You have made a mess with the color logic, with "helper" functions, some functions now using it and some not.

There is also a lot of duplication now with unnecessary PS1/2 definitions etc.

@tanloong
Copy link
ContributorAuthor

Hi@StanFromIreland , thank you for your review!

useprint( ... , file=sys.XXX)

Good point! I agree and will update the code.

You have made a mess with the color logic, with "helper" functions, some functions now using it and some not.

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.

There is also a lot of duplication now with unnecessary PS1/2 definitions etc.

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!

Comment on lines +44 to +45
PS1 = "sqlite> "
PS2 = " ... "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Remove these and usesys.ps1 like before, this would break current behavior.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Theself.PS1 is needed bythis line to get the length of plain prompt string. The length can't be obtained throughsys.ps1 becausesys.ps1 has surrounding control sequences for coloring.

I tested it and it doesn't break current behavior.

def do_version(self, _):
""".version

Show version of the runtime SQLite library.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
ShowversionoftheruntimeSQLitelibrary.
PrintversionoftheruntimeSQLitelibrary.

This is the more common way of describing this. And also this does not need a new function.

Copy link
ContributorAuthor

Choose a reason for 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.

self._print_commands(self.undoc_header, cmds_undoc, 80)
else:
arg = arg.split()[0]
if arg in ("-all", "--all"):
Copy link
Contributor

Choose a reason for 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

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}'")
Copy link
Contributor

Choose a reason for 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

Comment on lines +99 to +104
def do_quit(self, _):
""".q(uit)

Exit this program.
"""
sys.exit(0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Not needed?

Copy link
ContributorAuthor

@tanloongtanloongMay 25, 2025
edited
Loading

Choose a reason for 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 ado_ prefix to mark it as a dot command. That way thequit command is accessible by.help.

do_q = do_quit

def _help_message_from_doc(self, doc):
# copied from Lib/pdb.py#L2544
Copy link
Contributor

Choose a reason for 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

self.write(f"{t.message}{msg}{t.reset}\n")

def _print_commands(self, header, cmds, maxcol):
# copied and modified from Lib/cmd.py#L351
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

ditto

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

ditto

Comment on lines +1 to +2
Make ``.help`` in the :mod:`sqlite3` command-line interface print list of
available commands and ``.help <command>`` prints help for that command.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
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 printalist of
available commands and ``.help <command>``print help for that command.

@serhiy-storchaka
Copy link
Member

I have a feeling you overdid it. We do not want to implement an exact replica of thesqlite3 program. It only implements three commands, and none of them are absolutely necessary (you can quit by pressing Ctrl-D or Ctrl-Z). They are fine when the implementation is one-line.

But the final decision is up to@erlend-aasland.

StanFromIreland reacted with thumbs up emoji

@StanFromIreland
Copy link
Contributor

I have a feeling you overdid it.

+1, IMO a reasonable approach would be non-intrusive and have a much lower diff.

@erlend-aasland
Copy link
Contributor

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.

StanFromIreland reacted with thumbs up emoji

@tanloong
Copy link
ContributorAuthor

Feeling down on this in past few days. I want to explain that the goal of this PR isn't to replicatesqlite3's.help. When I said “this matches the behavior of the SQLite CLI tool,” I meant to show that the.help design in this PR is reasonable. I was worried that the PR might get rejected because people thought the.help design was self-opinioned. The goal is to make.help more helpful, we may have more dot commands in the future and need to list them to users at that time.

Copy link
Member

@serhiy-storchakaserhiy-storchaka left a comment

Choose a reason for 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.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@serhiy-storchakaserhiy-storchakaserhiy-storchaka left review comments

@picnixzpicnixzpicnixz left review comments

@StanFromIrelandStanFromIrelandStanFromIreland requested changes

@berkerpeksagberkerpeksagAwaiting requested review from berkerpeksagberkerpeksag is a code owner

@erlend-aaslanderlend-aaslandAwaiting requested review from erlend-aaslanderlend-aasland is a code owner

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

5 participants
@tanloong@serhiy-storchaka@StanFromIreland@erlend-aasland@picnixz

[8]ページ先頭

©2009-2025 Movatter.jp