Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

☂️ Move Rome CLI to use bpaf #4397

Closed
8 tasks done
ematipico opened this issue Apr 21, 2023 · 6 comments
Closed
8 tasks done

☂️ Move Rome CLI to use bpaf #4397

ematipico opened this issue Apr 21, 2023 · 6 comments
Labels
A-CLI Area: CLI good first issue Good for newcomers Help wanted Help would be really appreciated umbrella Issue to track a collection of other issues

Comments

@ematipico
Copy link
Contributor

ematipico commented Apr 21, 2023

Description

I have been experimenting with some possible CLI libraries (more potent than pico_args), and I find bpaf really pleasant to work with!

I did a small PoC and it seems that it can work inside the Rome code base, although there are some restrictions and compromises that we have to make:

  • we can't use our internal markup! for the help section;
  • error handling will be different, and we have to rely on bpaf error messages when the parsing of an argument fails;

I am happy to accept the trade-off! bpaf allows to define arguments in two ways: combinatoric or derive. For Rome, the derive feature works better. The combinatoric way forces you to define every type inside a struct, which differs from what we're looking for inside Rome.

Although, before moving everything to bpaf, some more work needs to be done to lay off the foundations and make the migration smoother.

Below the list of things that we need to do:

First batch:

Second batch:

  • Move global options to their own struct
  • format subcommand via bpaf
  • check subcommand via bpaf
  • ci subcommand via bpaf
  • rage subcommand via bpaf
@ematipico ematipico added umbrella Issue to track a collection of other issues good first issue Good for newcomers Help wanted Help would be really appreciated A-CLI Area: CLI labels Apr 21, 2023
@Conaclos
Copy link
Contributor

Which other candidates did you review?

@ematipico
Copy link
Contributor Author

Which other candidates did you review?

Another option is clap but it's super heavy and I'd prefer to avoid it.

Another one was argh but it has less features.

Here's a great community project that compares some libraries: https://github.com/rosetta-rs/argparse-rosetta-rs

I like bpaf because:

  • it has multiple styles for composing the parsing of arguments
  • it has third party auto completion in case we want to opt-in
  • it's actively maintained

@Boshen
Copy link
Contributor

Boshen commented Apr 21, 2023

I agree with your conclusion on clap and argh.

Can't wait to see bpaf being used. Maybe I'll convert it in Oxc before Rome does, if I get the time 😁

@pacak
Copy link

pacak commented May 14, 2023

we can't use our internal markup! for the help section;

Can you tell me a bit more what makes markup! macro great or where can I read about it? I'm looking into changing help/documentation generation so might be able to make it more compatible...

@ematipico
Copy link
Contributor Author

we can't use our internal markup! for the help section;

Can you tell me a bit more what makes markup! macro great or where can I read about it? I'm looking into changing help/documentation generation so might be able to make it more compatible...

Hi @pacak , thank you for reaching out! :)

The markup! macro is an internal macro that accepts a string HTML-like:

markup!{
	"Something"<Emphasis>"bold"</Emphasis>" or "<Dim>"dimmed"</Dim>
}

This macro creates MarkupElements with an internal implementation of rome_console::fmt::Display. Then, we have different writers based on where we want to write this elements. We have a Terminal writer and an HTML writer.

Here's some internal, useful links:

@pacak
Copy link

pacak commented May 16, 2023

I see. I'm adding something similar with goals to write to terminal, markdown (well, technically a mix of html and markdown) and manpages, there should be a way to get those two to talk to each other :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A-CLI Area: CLI good first issue Good for newcomers Help wanted Help would be really appreciated umbrella Issue to track a collection of other issues
Projects
None yet
Development

No branches or pull requests

4 participants