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

Update arg parsing to clap v3 #1717

Merged
merged 4 commits into from
Jan 23, 2022
Merged

Update arg parsing to clap v3 #1717

merged 4 commits into from
Jan 23, 2022

Conversation

tranzystorekk
Copy link
Contributor

@tranzystorekk tranzystorekk commented Jan 3, 2022

IMPORTANT: Please do not create a Pull Request adding a new feature without discussing it first.

The place to discuss new features is the forum: https://zola.discourse.group/
If you want to add a new feature, please open a thread there first in the feature requests section.

Switches arg parsing to the modern derive style via the newly released clap 3.0.0

Important/to discuss:

  • Now the help is colored by default
  • The base_path/base_url parameters for the check subcommand were read from ArgMatches but never defined in the clap app, so I set them to None for now

Sanity check:

  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?

Code changes

(Delete or ignore this section for documentation changes)

  • Are you doing the PR on the next branch?

If the change is a new feature or adding to/changing an existing one:

  • Have you created/updated the relevant documentation page(s)?

Copy link
Collaborator

@Keats Keats left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

src/cli.rs Show resolved Hide resolved
src/cli.rs Outdated Show resolved Hide resolved
let root_dir = cli
.root
.canonicalize()
.unwrap_or_else(|_| panic!("Cannot find root directory: {}", cli.root.display()));
Copy link
Collaborator

Choose a reason for hiding this comment

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

that's not handling the . case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here cli.root already has the . value if it wasn't specified on the command line, so we handle only the canonicalize operation result, which I think should work for .

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not entirely sure it does work on all platforms, I'd like to be certain before changing it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I built a small program to verify that canonicalizing . works on windows, but if we wanted to be extra careful, there's the normpath crate that seems to be saner (also personally confirmed that it works).

Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's keep like you have for now, we'll see if it causes an issue

src/main.rs Outdated Show resolved Hide resolved
src/main.rs Show resolved Hide resolved
/// Include drafts when loading the site
#[clap(long)]
drafts: bool,
},
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we be explicit with all the default values as well? eg set false for drafts etc. I guess Subcommand relies on default but I'd like to be able to see the full set of option values at a glance

Copy link
Contributor Author

@tranzystorekk tranzystorekk Jan 4, 2022

Choose a reason for hiding this comment

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

I've looked at the documentation, but especially for bool flags this is neither elegant to write nor widely accepted style to specify the default explicitly.

Copy link
Collaborator

Choose a reason for hiding this comment

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

oh :(
Just passing true/false to default doesn't work? It's kind of weird that non bool gets to have their default value in the struct but not bool since there are only 2 possible values...

Copy link
Contributor Author

@tranzystorekk tranzystorekk Jan 4, 2022

Choose a reason for hiding this comment

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

Did a quick check and clap protests with a "default value is meaningless for bool" error.

I'm guessing the rationale is that bool flags are simple on-off switches and don't require any special handling.

@@ -13,14 +13,15 @@ keywords = ["static", "site", "generator", "blog"]
include = ["src/**/*", "LICENSE", "README.md"]

[build-dependencies]
clap = "2"
clap = "3"
clap_complete = "3"
Copy link
Collaborator

Choose a reason for hiding this comment

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

what does this do and where is it used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In v3 the completion functionality has been split off to the separate clap_complete package, I noticed that there is some completion code in build.rs that is commented out, so admittedly this is a bit preemptive.

I guess we could instead add it in a separate PR focused on bringing back completion

@tranzystorekk
Copy link
Contributor Author

tranzystorekk commented Jan 10, 2022

The remaining issue is that clap v3 uses the include_str! macro to add README.md contents to its docs, which effectively makes it MSRV 1.54, while linux-pinned uses 1.52

@Keats
Copy link
Collaborator

Keats commented Jan 10, 2022

Bumping the MSRV is not an issue but can that feature be disabled as it wouldn't be used anyway?

@tranzystorekk
Copy link
Contributor Author

but can that feature be disabled as it wouldn't be used anyway?

I'm afraid building docs for dependencies can only be disabled in cargo doc, and the error occurs in cargo build in general.

@Keats
Copy link
Collaborator

Keats commented Jan 10, 2022

I'm afraid building docs for dependencies can only be disabled in cargo doc, and the error occurs in cargo build in general.

Oh I see, I thought clap was somehow pulling the readme in the built cli. This makes more sense.

@Keats Keats force-pushed the next branch 2 times, most recently from 189c37d to 6238b36 Compare January 23, 2022 13:38
@Keats
Copy link
Collaborator

Keats commented Jan 23, 2022

Can you resolve the conflicts? Or i'll do it later today

@tranzystorekk tranzystorekk changed the base branch from next to master January 23, 2022 14:56
@tranzystorekk tranzystorekk changed the base branch from master to next January 23, 2022 15:00
@Keats Keats merged commit c9b2d35 into getzola:next Jan 23, 2022
@Keats
Copy link
Collaborator

Keats commented Jan 23, 2022

Thanks!

@tranzystorekk tranzystorekk deleted the clap-v3 branch January 23, 2022 19:40
Keats pushed a commit that referenced this pull request Feb 14, 2022
* Update arg parsing to clap v3
mwcz pushed a commit to mwcz/zola that referenced this pull request Mar 7, 2022
* Update arg parsing to clap v3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants