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

Allow querying multiple platforms #300

Merged
merged 13 commits into from
Aug 27, 2023

Conversation

jj-style
Copy link
Contributor

Fix for an old issue #45 - to allow specifying multiple platforms on the cli.
Behaviour is to try get the tldr page for each platform given - so if a page doesn't exist for one platform but does for another, you still get the page displayed.

Copy link
Collaborator

@niklasmohrin niklasmohrin left a comment

Choose a reason for hiding this comment

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

Thank you for contributing! I have some change requests below, the main one is passing platforms to the methods that need it and not storing it in the Cache. This also includes handling multiple platforms in these methods instead of running them multiple times. Reviews might take a while here as @dbrgn and I are both relatively busy; feel free to ping us again here if we haven't checked in in a while or if you feel like we forgot you

src/main.rs Outdated Show resolved Hide resolved
src/main.rs Outdated Show resolved Hide resolved
src/main.rs Outdated Show resolved Hide resolved
tests/lib.rs Outdated Show resolved Hide resolved
@jj-style
Copy link
Contributor Author

Thank you for the code review and suggestions! I agree about passing in platform where it's needed and refactoring it out of the Cache.
I'll have a crack at fixing these issues, I'm still somewhat new to rust but hopefully should be doable and will be a good learning experience!

p.s. thanks for the awesome project - it saves my bacon multiple times a day!

@niklasmohrin
Copy link
Collaborator

Feel free to ask about any problems you encounter, I will try to answer without unreasonable delays

@jj-style
Copy link
Contributor Author

jj-style commented Jan 5, 2023

Happy new year! Sorry it's taken me a while to respond to your feedback. I've given it an attempt to remove the platform from the Cache and pass in &[PlatformType] on the methods that need it. It definitely feels better than looping the main program for each platform and creating multiple instances of the cache

Copy link
Collaborator

@niklasmohrin niklasmohrin left a comment

Choose a reason for hiding this comment

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

Thanks, looks good :)

Some of my previous comments are still open, in particular what should happen with --list, and whether we want to guarantee that we respect the order the platforms were given in. For the latter, I think we can always prioritize platforms that came first (as we already do) - so we would just need a test that covers this. @dbrgn Do you have opinions on behavior and whether we want to try to incorporate this into the spec?

src/main.rs Outdated Show resolved Hide resolved
src/main.rs Outdated Show resolved Hide resolved
src/main.rs Outdated Show resolved Hide resolved
src/cache.rs Outdated Show resolved Hide resolved
@jj-style
Copy link
Contributor Author

Thanks for the feedback! I have now implemented the suggestions you have made.

With regards to what should happen with --list when multiple platforms are provided - the current behaviour in cache.rs with the pages.sort().dedup() implies that the order the platforms are given is not important and the combined ordered set of pages should be listed.
I have added a test for this behaviour however, if we decide we want to list the pages grouped in order by the platforms supplied I can make this change

Copy link
Collaborator

@niklasmohrin niklasmohrin left a comment

Choose a reason for hiding this comment

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

Thanks, looks very good now! I have some final remarks, mostly about testing, below.

There is also one comment from before that I think hasn't been addressed yet. A check should be added to make sure that when running tldr --platform linux --platform windows xyz, a page for linux should be preferred, even if xyz exists for both platforms. I think it could be tested in test_multiple_platform_command_search.

I thought about the behavior for --list some more and I think the current version is probably what we want. I am fine with the current behavior and if we ever need to change it, well, we can still change it :^)

tests/lib.rs Show resolved Hide resolved
tests/lib.rs Outdated Show resolved Hide resolved
tests/lib.rs Show resolved Hide resolved
src/cli.rs Outdated Show resolved Hide resolved
@jj-style
Copy link
Contributor Author

jj-style commented Mar 5, 2023

thank you for the continuous feedback and help with this. I have pushed the changes for the testing :)

Copy link
Collaborator

@niklasmohrin niklasmohrin left a comment

Choose a reason for hiding this comment

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

Looks good to me! Thank you for your contribution and sorry for the long wait :)

@niklasmohrin niklasmohrin requested a review from dbrgn April 17, 2023 14:42
Copy link
Collaborator

@niklasmohrin niklasmohrin left a comment

Choose a reason for hiding this comment

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

Sorry for the long wait! Your PR looks good and will be included in the next release. Thanks!

@niklasmohrin niklasmohrin changed the title Specify Multiple OS Allow querying multiple platforms Aug 27, 2023
@niklasmohrin niklasmohrin enabled auto-merge (squash) August 27, 2023 21:47
@niklasmohrin niklasmohrin merged commit 9e1489b into tealdeer-rs:main Aug 27, 2023
9 checks passed
@dbrgn
Copy link
Collaborator

dbrgn commented Feb 4, 2024

Hi, some (very late, I know) follow-up questions @niklasmohrin @jj-style:

  • Was it always clear that the API should be tldr --platform linux --platform windows as opposed to something like tldr --platform linux,windows? Or was that second alternative considered?
  • The client specification does not mention the behavior in case of multiple pages. Niklas asked this in this comment, but I didn't see that it was addressed. Are there any other clients that support specifying multiple platforms? How does their API look like?
  • (Also, the help seems confusing to me now, because it mixes a singular keyword with a plural parameter name. But I can fix that in a separate PR.)

@niklasmohrin
Copy link
Collaborator

  • I dont remember exactly, this is just the default behavior of clap for this. I think I slightly prefer the current version, because it passes multiple platforms via multiple arguments and a parsing error could point directly to which platform is invalid.
  • I thought that the tests assert a reasonable behavior - platforms are checked in the order they are passed - but I dont fully remember and would have to dig in again. If the spec decides something else, we can change it again
  • Agree, this could be improved. Maybe a note that it can be passes multiple times would be better

@jj-style
Copy link
Contributor Author

jj-style commented Feb 8, 2024

I did not check if or how other clients support multiple platforms, sorry.
I agree with @niklasmohrin about using the default clap behaviour but happy to see if there are other ways of doing it in clap that provide a more concise interface.

Happy to update the help text in another PR either way!

@dbrgn
Copy link
Collaborator

dbrgn commented Aug 12, 2024

Help text PR is here: #375

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

Successfully merging this pull request may close these issues.

3 participants