typst / svg2pdf

Converts SVG files to PDF.
Apache License 2.0
273 stars 32 forks source link

Extract CLI crate and add shell completion and man page #42

Closed mrgalopes closed 10 months ago

mrgalopes commented 10 months ago

Closes #27.

Adapted from the main typst repo. It only outputs the completions and the man page when the cli feature is enabled. A downside is that it always fetches and compiles the dependencies. Any suggestions are appreciated. 😄

laurmaedje commented 10 months ago

I think having clap as a build dependency unconditionally is unfortunate. If we want to do this, maybe the CLI should be extracted into its own crate like in Typst.

cc: @reknih

LaurenzV commented 10 months ago

Yeah, I actually also extracted it when I did the rewrite initially, but I didn't know whether that was what you wanted so I ended up reverting to using a cli feature. I also think having them separate would be nicer.

laurmaedje commented 10 months ago

Originally, I liked this setup, but I've come to prefer the more flexible two-crate setup since.

mrgalopes commented 10 months ago

Yeah, extracting the CLI into its own crate should be nicer, you're right. I will update the PR in the following days with this setup. Thank you for the feedback!

mrgalopes commented 10 months ago

I separated the crates inspired by the structure of typst, and also rebased on main. Let me know what you think.

mrgalopes commented 10 months ago

Apologies for the delay. I've been looking for alternatives to add the completions but couldn't find any that were ideal. The way that this was done mirrors the typst-cli, where the nix flake installs the completion after the build. Without nix, this would have to be done manually. From what I could find, crates.io doesn't let you install arbitrary files, like completion files. This is how I've done for zsh:

  1. Update the .zshrc to include a folder that looks for completions and to autoload them
    
    fpath+=~/.zfunc

autoload -Uz compinit compinit

2. Copy the completion artifact corresponding to zsh and bash to the ~/.zfunc folder, and restart the shell
```sh
cp target/release/artifacts/_svg2pdf ~/.zfunc
laurmaedje commented 10 months ago

Thank you!