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

Add a CLI reference page to the docs, inspired by sqlite-utils #1594

Closed
simonw opened this issue Jan 13, 2022 · 3 comments
Closed

Add a CLI reference page to the docs, inspired by sqlite-utils #1594

simonw opened this issue Jan 13, 2022 · 3 comments

Comments

@simonw
Copy link
Owner

simonw commented Jan 13, 2022

Thought of this while posting this comment: #1591 (comment)

I added https://sqlite-utils.datasette.io/en/stable/cli-reference.html to sqlite-utils in simonw/sqlite-utils#383 and I really like it - it's a page showing the --help output of every CLI command for that tool.

It's maintained using cog. One of the benefits is that I get a free commit history of changes to --help at https://github.com/simonw/sqlite-utils/commits/main/docs/cli-reference.rst

@simonw
Copy link
Owner Author

simonw commented Jan 13, 2022

The implementation can be almost exactly the same as this: https://github.com/simonw/sqlite-utils/blame/74586d3cb26fa3cc3412721985ecdc1864c2a31d/docs/cli-reference.rst#L11-L76

I need to do something extra to ensure the output of datasette --help-settings is shown too.

@simonw
Copy link
Owner Author

simonw commented Jan 13, 2022

I went with a simpler pattern that sqlite-utils because Datasette has a lot less commands:

.. [[[cog
from datasette import cli
from click.testing import CliRunner
import textwrap
commands = [
["--help"],
["serve", "--help"],
["serve", "--help-settings"],
["plugins", "--help"],
["publish", "--help"],
["publish", "cloudrun", "--help"],
["publish", "heroku", "--help"],
["package", "--help"],
["inspect", "--help"],
["install", "--help"],
["uninstall", "--help"],
]
for command in commands:
title = "datasette " + " ".join(command)
cog.out(title + "\n")
cog.out(("=" * len(title)) + "\n\n")
cog.out("::\n\n")
result = CliRunner().invoke(cli.cli, command)
output = result.output.replace("Usage: cli ", "Usage: datasette ")
cog.out(textwrap.indent(output, ' '))
cog.out("\n\n")
.. ]]]

@simonw
Copy link
Owner Author

simonw commented Jan 13, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant