-
Notifications
You must be signed in to change notification settings - Fork 223
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
feat: Add man page for prqlc #2033
Conversation
Thanks @vanillajonathan ! My main concern here is with maintaining it — how do we know whether it's current? I'd favor merging this if there were a test to confirm it's mostly correct; that way we can at least know we're not shipping something incorrect. Is that possible? Looking for something that would be easier to maintain / auto-generated:
|
We wouldn't know if its current unless we actively maintain it and update it when This There is also Pandoc which can be used to convert documentation in one format from another, it may be more developer-friendly than groff syntax. |
OK. I'm very open to those. I would gate merging this on some way of ensuring these don't fall out of date — it's worse to have out-of-date docs than no docs, I do think that That could be a test, or a way of auto-generating it, or open to other ideas... |
I cannot imagine any way of adding tests, but auto-generating it could definitely be an alternative solution, however I believe it is a more limiting alternative as clap likely won't know too much about things other than what is strictly needed the command-line parsing. A dedicated manual page may include things such as return status codes, examples, in-depth explanations, etc. |
Here's the man page from the playground — it does look good! @vanillajonathan WDYT about attempting this with the clap plugin? I agree it's difficult to test — if there were examples here, then maybe we could test those. I definitely expect there will be changes, and I don't have a good visualization of how we'd maintain this. Would we not merge any changes to Does this make sense? I'm trying to balance the benefits of this against the long-term maintenance costs. An alternative is to merge this and then just remove it when it gets out of date. But I'd be concerned about the expectations that sets around removing folks' hard work at the first sign of staleness, and that it crowds out potentially better solutions, like the |
I looked at the clap plugin and it sounds good, but I wasn't able to get it working. The prqlc uses a different way to setup clap, it seems the plugin expects clap to be configured using Dust uses this clap plugin but also does it together with the So that |
This is great! Does this work or does it also require the builder plugin? I guess a separate issue from the man page but would be cool to have this too. |
Great, I asked re derive vs builder over at clap-rs/clap#4749 |
The clap_complete page at cargo.rs says "Generate shell completion scripts for your clap::Command". So I assume it only works with |
We do have one of those though! prql/prql-compiler/prqlc/src/cli.rs Line 34 in 246cee9
|
Oh, we do! I haven't been able to get it to work though. You would probably have better luck. |
OK, I had a go for 10 minutes but couldn't figure this out — we can open an issue and see if someone who knows diff --git a/prql-compiler/prqlc/Cargo.toml b/prql-compiler/prqlc/Cargo.toml
index 40b0ced3..ae9cd009 100644
--- a/prql-compiler/prqlc/Cargo.toml
+++ b/prql-compiler/prqlc/Cargo.toml
@@ -28,3 +28,10 @@ walkdir = "^2.3.2"
[target.'cfg(not(target_family="wasm"))'.dev-dependencies]
insta = {version = "1.28", features = ["colors", "glob", "yaml"]}
+
+[build-dependencies]
+clap = {version = "4.1.1", features = ["derive"]}
+clap_mangen = "0.2.9"
+
+[dependencies]
+clap_complete = "4.1.4"
diff --git a/prql-compiler/prqlc/src/cli.rs b/prql-compiler/prqlc/src/cli.rs
index 41db7dc8..05143ccb 100644
--- a/prql-compiler/prqlc/src/cli.rs
+++ b/prql-compiler/prqlc/src/cli.rs
@@ -1,6 +1,6 @@
use anyhow::Result;
use ariadne::Source;
-use clap::{Parser, Subcommand};
+use clap::{CommandFactory, Parser, Subcommand};
use clio::{Input, Output};
use itertools::Itertools;
use std::io::{Read, Write};
@@ -14,12 +14,27 @@
use crate::watch;
+use clap::Command as ClapCommand;
+use clap_complete::{generate, Generator, Shell};
+use std::io;
+
/// Entrypoint called by [crate::main]
pub fn main() -> color_eyre::eyre::Result<()> {
env_logger::builder().format_timestamp(None).init();
color_eyre::install()?;
let mut cli = Cli::parse();
+ let matches = Cli::command().get_matches();
+
+ if let Some(generator) = dbg!(matches).get_one::<Shell>("compile").copied() {
+ dbg!(generator);
+ let mut cmd = Cli::command();
+ eprintln!("Generating completion file for {}...", generator);
+ print_completions(generator, &mut cmd);
+ } else {
+ dbg!("No generator");
+ }
+
if let Err(error) = cli.command.run() {
eprintln!("{error}");
exit(1)
@@ -28,7 +43,12 @@ pub fn main() -> color_eyre::eyre::Result<()> {
Ok(())
}
+fn print_completions<G: Generator>(gen: G, cmd: &mut ClapCommand) {
+ generate(gen, cmd, cmd.get_name().to_string(), &mut io::stdout());
+}
+
#[derive(Parser, Debug, Clone)]
+#[command(about = "hello")]
struct Cli {
#[command(subcommand)]
command: Command,
@@ -65,6 +85,7 @@ enum Command {
/// Watch a directory and compile .prql files to .sql files
Watch(watch::WatchArgs),
+ // Generate,
}
#[derive(clap::Args, Default, Debug, Clone)]
|
Hmm, I wanted to rename this branch but it seems GitHub closed it. 😢️ |
Man pages for Unix-like systems such as Linux, BSD and macOS.
You can live preview this on https://roperzh.github.io/grapse/
Here is the documentation for
groff
which explains the syntax https://manpages.debian.org/testing/groff/groff_mdoc.7.en.htmlI haven't written any manual pages before so I don't know if this is semantically idiomatic but it is a start.