Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli: adds \d, \dt, \du, \l metacommands to sql shell #39141

Merged
merged 1 commit into from
Jul 29, 2019

Conversation

kenliu
Copy link

@kenliu kenliu commented Jul 28, 2019

Also tweaked shell welcome message to mention “\q” instead of “CTRL + D” (doesn’t work on Windows, and isn’t primary command)

Release note: added \d, \dt, \du, \l metacommands to cli shell

@kenliu kenliu requested a review from a team as a code owner July 28, 2019 03:27
@kenliu kenliu requested a review from a team July 28, 2019 03:27
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@kenliu kenliu changed the title Add cli metacommands cli: adds \d, \dt, \du, \l metacommands to cli shell Jul 28, 2019
@kenliu kenliu changed the title cli: adds \d, \dt, \du, \l metacommands to cli shell [WIP] cli: adds \d, \dt, \du, \l metacommands to cli shell Jul 28, 2019
@kenliu kenliu added the first-pr Use to mark the first PR sent by a contributor / team member. Reviewers should be mindful of this. label Jul 28, 2019
@kenliu kenliu force-pushed the add-cli-metacommands branch 3 times, most recently from 6c37c61 to 255b83a Compare July 29, 2019 13:50
@kenliu kenliu changed the title [WIP] cli: adds \d, \dt, \du, \l metacommands to cli shell [WIP] cli: adds \d, \dt, \du, \l metacommands to sql shell Jul 29, 2019
@kenliu kenliu changed the title [WIP] cli: adds \d, \dt, \du, \l metacommands to sql shell cli: adds \d, \dt, \du, \l metacommands to sql shell Jul 29, 2019
@kenliu
Copy link
Author

kenliu commented Jul 29, 2019

lint errors, running again locally

Copy link
Member

@jordanlewis jordanlewis left a comment

Choose a reason for hiding this comment

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

Generally :lgtm:! A couple of small comments within.

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @jordanlewis and @kenliu)


pkg/cli/sql.go, line 48 at r1 (raw file):

# Welcome to the CockroachDB SQL shell.
# All statements must be terminated by a semicolon.
# To exit, type: \q.

Maybe To exit, CTRL + D or type \q.? (ctrl+d still works, after all.)


pkg/cli/sql.go, line 1040 at r1 (raw file):

	case `\d`:
		if len(cmd) > 1 {

Seems like we might want to make this == 1? Otherwise, you could type \d foo bar and it would give you columns from foo and ignore the second parameter completely.

@jordanlewis jordanlewis requested a review from knz July 29, 2019 15:34
@kenliu
Copy link
Author

kenliu commented Jul 29, 2019

@jordanlewis I got this lint error, not sure how to resolve pkg/cli/sql.go:1043:10: if block ends with a return statement, so drop this else and outdent its block

@jordanlewis
Copy link
Member

It's saying that the else block is irrelevant here:

	case `\d`:
		if len(cmd) > 1 {
			c.concatLines = `SHOW COLUMNS FROM ` + cmd[1]
			return cliRunStatement
		} else {
			return c.invalidSyntax(errState, `%s. Try \? for help.`, c.lastInputLine)
		}

It wants it to become:

	case `\d`:
		if len(cmd) > 1 {
			c.concatLines = `SHOW COLUMNS FROM ` + cmd[1]
			return cliRunStatement
		}
		return c.invalidSyntax(errState, `%s. Try \? for help.`, c.lastInputLine)

@jordanlewis
Copy link
Member

(Or vice versa, which IMO might look cleaner, but doesn't really matter)

Copy link
Author

@kenliu kenliu left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @jordanlewis and @knz)


pkg/cli/sql.go, line 48 at r1 (raw file):

Previously, jordanlewis (Jordan Lewis) wrote…

Maybe To exit, CTRL + D or type \q.? (ctrl+d still works, after all.)

It turns out that CTRL-D doesn't work on Windows (I tried it) and our help message shows \q as the primary command to exit. There are many others (and it turns out there are undocumented ones) so I thought it best to show just the one here and if someone wants to look for the others they'll figure it out.


pkg/cli/sql.go, line 1040 at r1 (raw file):

Previously, jordanlewis (Jordan Lewis) wrote…

Seems like we might want to make this == 1? Otherwise, you could type \d foo bar and it would give you columns from foo and ignore the second parameter completely.

good call

Copy link
Contributor

@knz knz left a comment

Choose a reason for hiding this comment

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

LGTM but I stand behind jordan's request on if len(cmd) == 1 for the \d case

Reviewed 3 of 3 files at r1.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @jordanlewis)

Copy link
Author

@kenliu kenliu left a comment

Choose a reason for hiding this comment

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

addressed comments. added an additional test to catch this case too.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @jordanlewis and @knz)

Copy link
Author

@kenliu kenliu left a comment

Choose a reason for hiding this comment

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

also fixed lint error

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @jordanlewis and @knz)

Copy link
Member

@jordanlewis jordanlewis left a comment

Choose a reason for hiding this comment

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

Nice tests, too! :lgtm: - please make sure to squash your commits before merging. (as a side note, avoiding this final squash step is why I like to keep amending PRs rather than pushing small new commits :)

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @knz)

@kenliu
Copy link
Author

kenliu commented Jul 29, 2019

makes sense, although isn't it easier for the reviewer to see the delta between the last review and and the set of review fixes? Could always squash at the very end.

- adds support for `\l`, `\dt`, `\du`, and ‘\d <table>`
- tweak welcome message for consistency
- fix welcome message to show `\q` instead of `CTRL + D` since that doesn’t work on Windows, and isn’t the primary documented way to quit from the shell

Release note: added \d, \dt, \du, \l metacommands to cli shell
@jordanlewis
Copy link
Member

makes sense, although isn't it easier for the reviewer to see the delta between the last review and and the set of review fixes? Could always squash at the very end.

This problem is why we use the Reviewable tool, which does a decent job of showing you the delta between the last review and the set of review fixes, even if you amend your commit. (It lets you view a diff between 2 versions of the same commit.)

@kenliu
Copy link
Author

kenliu commented Jul 29, 2019

ohh I see, makes sense.

@kenliu
Copy link
Author

kenliu commented Jul 29, 2019

bors r+

craig bot pushed a commit that referenced this pull request Jul 29, 2019
39141: cli: adds \d, \dt, \du, \l metacommands to sql shell r=kenliu a=kenliu

Also tweaked shell welcome message to mention “\q” instead of “CTRL + D” (doesn’t work on Windows, and isn’t primary command)

Release note: added \d, \dt, \du, \l metacommands to cli shell

Co-authored-by: Kenneth Liu <ken@cockroachlabs.com>
@craig
Copy link
Contributor

craig bot commented Jul 29, 2019

Build succeeded

@craig craig bot merged commit 8fa961c into cockroachdb:master Jul 29, 2019
@knz
Copy link
Contributor

knz commented Aug 9, 2019

@kenliu nit for next time: the release note generation program wants to know the category of the release note, so instead of this

Release note: added \d, \dt, \du, \l metacommands to cli shell

you can do this:

Release note (cli change): added \d, \dt, \du, \l metacommands to cli shell

and it's also good to add some explanatory context for users, to motivate the change, for example:

Release note (cli change): `cockroch sql` and `cockroach demo` now support 
the client-side commands `\d`, `\dt`, `\du`, `\l`, for compatibility with, 
and to ease adoption by, users of `psql`.

@kenliu
Copy link
Author

kenliu commented Aug 9, 2019

Sounds good, thanks. Is there documentation to explain how the release note process works? I didn't really have any idea if these notes were doing to be user facing or if the docs team was going to edit them further.

@knz
Copy link
Contributor

knz commented Aug 9, 2019

  1. the CONTRIBUTING.md file at the top level mentions release notes contains a (partially broken link) to https://wiki.crdb.io/wiki/spaces/CRDB/pages/73072807/Git+Commit+Messages

The particular section on release notes is here: https://wiki.crdb.io/wiki/spaces/CRDB/pages/73072807/Git+Commit+Messages#GitCommitMessages-Releasenotes

  1. The commit message template also includes guidance as a comment at the bottom. Does your editor not show this to you?
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# Commit message recommendation:
#
#     ---
#     <pkg>: <short description>
#
#     <long description>
#
#     Release note (category): <release note description>
#     ---
#
# Wrap long lines! 72 columns is best.
#
# The release note must be present if your commit has user-facing
# changes. Leave the default above if not.
#
# Categories for release notes:
#     - cli change
#     - sql change
#     - admin ui change
#     - general change (e.g., change of required Go version)
#     - build change (e.g., compatibility with older CPUs)
#     - enterprise change (e.g., change to backup/restore)
#     - backwards-incompatible change
#     - performance improvement
#     - bug fix

@knz
Copy link
Contributor

knz commented Aug 9, 2019

Note that even though the doc team edits them further, they are very much appreciative of text that gives them enough context to understand what's going on.

@kenliu
Copy link
Author

kenliu commented Aug 9, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
first-pr Use to mark the first PR sent by a contributor / team member. Reviewers should be mindful of this.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants