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

cmd: Implement httpie plugins interface #1200

Merged
merged 19 commits into from
Nov 30, 2021

Conversation

isidentical
Copy link
Contributor

@isidentical isidentical commented Nov 7, 2021

Resolves #566.

Remaining stuff:

  • Fix windows (apparently some sysconfig issues)
  • Docs
  • More tests (and possibly some functional tests for error scenerios)
  • Playing with real world plugins (not part of the PR, but we should test them and ensure they are working both ways)
  • Improving UI for errors (e.g PermissionError)

@isidentical
Copy link
Contributor Author

The testing bit took a lot more than I thought, but I think it worths it (since it simplifies workflow by a lot). Now focusing on docs / remaining smaller tests.

@codecov-commenter
Copy link

codecov-commenter commented Nov 7, 2021

Codecov Report

Merging #1200 (f2dfda0) into master (4d7d6b6) will decrease coverage by 0.59%.
The diff coverage is 94.36%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1200      +/-   ##
==========================================
- Coverage   97.28%   96.68%   -0.60%     
==========================================
  Files          67       78      +11     
  Lines        4235     5158     +923     
==========================================
+ Hits         4120     4987     +867     
- Misses        115      171      +56     
Impacted Files Coverage Δ
tests/test_auth.py 100.00% <ø> (ø)
tests/test_binary.py 100.00% <ø> (ø)
httpie/compat.py 31.11% <27.90%> (-68.89%) ⬇️
tests/conftest.py 77.14% <58.33%> (-9.82%) ⬇️
tests/test_ssl.py 91.01% <66.66%> (-3.93%) ⬇️
httpie/manager/__main__.py 82.35% <82.35%> (ø)
httpie/models.py 94.73% <83.33%> (-2.64%) ⬇️
httpie/output/formatters/colors.py 92.66% <83.33%> (-0.92%) ⬇️
httpie/manager/core.py 92.85% <92.85%> (ø)
httpie/manager/plugins.py 93.45% <93.45%> (ø)
... and 47 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ef62fc1...f2dfda0. Read the comment docs.

@isidentical isidentical force-pushed the httpie-plugins branch 11 times, most recently from 74d10e0 to ed4425e Compare November 13, 2021 17:34
@isidentical isidentical marked this pull request as ready for review November 13, 2021 22:12
@isidentical isidentical requested a review from jkbrzt November 13, 2021 22:12
@isidentical
Copy link
Contributor Author

I'll take a look at the package builds at last, but I feel like it should be easy to resolve.

@isidentical
Copy link
Contributor Author

Here is the UI demo for the current version;
asciicast

@isidentical isidentical force-pushed the httpie-plugins branch 2 times, most recently from 3f332e1 to e82fe74 Compare November 22, 2021 09:49
@isidentical
Copy link
Contributor Author

I think I need to send a pull request to https://src.fedoraproject.org/rpms/httpie/blob/rawhide/f/httpie.spec after this gets merged since packit uses that file for the package configuration.

Copy link
Member

@jkbrzt jkbrzt left a comment

Choose a reason for hiding this comment

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

I’m yet to dive to the nitty-gritty, but overall it looks pretty solid 👍🏻

One thing we should definitely improve though is the UX of when the management httpie command gets invoked without args or with invalid args:

The thing is that many people (my guess would be ~50%+, i.e., higher thousands a month) will, after running x install httpie, run httpie.

We need to anticipate that and give them a crystal clear indication about the command/project name mismatch and help them get towards sending their first request; the mismatch is highly unintuitive. (The docs could also be more clear in this sense.) And the ability to direct people to the correct command is actually an extremely valuable side-benefit of the new httpie command.

The default argparse output is not helpful in this sense at all:

$ httpie
usage: httpie [-h] [--debug] [--traceback] {plugins} ...
httpie: error: please specify one of these: 'plugins'

We should also handle the following scenario. Here we could print the same as above, but also print the correct command (http POST pie.dev/post hello=world) so that the user can just copy/paste/re-run it with the correct command name this time:

$ httpie POST pie.dev/post hello=world
usage: httpie [-h] [--debug] [--traceback] {plugins} ...
httpie: error: argument action: invalid choice: 'POST' (choose from 'plugins')

This is slightly better:

$ httpie --help
usage: httpie [-h] [--debug] [--traceback] {plugins} ...

Managing interface for the HTTPie itself. <https://httpie.io/docs#manager>

Be aware that you might be looking for http/https commands for sending
HTTP requests. This command is only available for managing the HTTTPie
plugins and the configuration around it.

positional arguments:
  {plugins}

optional arguments:
  -h, --help
      show this help message and exit

  --debug
      Prints the exception traceback should one occur, as well as other
      information useful for debugging HTTPie itself and for reporting bugs.

  --traceback
      Prints the exception traceback should one occur.

@isidentical
Copy link
Contributor Author

@jakubroztocil I've implemented 2 different suggestions. First one is when you simply run httpie:

$ httpie                                                                                                                                            1,021s
usage: httpie [-h] [--debug] [--traceback] {plugins} ...
httpie: error: Please specify one of these: "plugins"

This command is for managing HTTPie plugins.
Perhaps you are looking for http/https commands, e.g:
    http POST pie.dev/post hello=world

It gives the actual description / error message, but also mentions about http/https commands (with a random example). The second is the case for POST blahblah.com/dev A=B:

 $ httpie POST pie.dev/post hello=world                                                                                                               576ms
usage: httpie [-h] [--debug] [--traceback] {plugins} ...
invalid choice: 'POST' (choose from 'plugins')

This command is for managing HTTPie plugins.
You probably meant one of the following: 
    http POST pie.dev/post hello=world
    https POST pie.dev/post hello=world

We try to parse the arguments as if it was parsed by http/https and if we succeed, we display that extra paragraph with the full examples.

@jkbrzt
Copy link
Member

jkbrzt commented Nov 25, 2021

@isidentical thanks. I’ll play with it and tweak the copy a bit more. We got a failing test it seems: https://github.com/httpie/httpie/runs/4322055556?check_suite_focus=true#step:5:226

@isidentical
Copy link
Contributor Author

Yep, seems like the API I depend on is only available 3.9+. Trying to overcome that at the moment.

Copy link

@Shivansh-007 Shivansh-007 left a comment

Choose a reason for hiding this comment

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

Some comments, I am new to this lib (as a dev) so not really sure whether some of my comments are against the design.

Copy link
Member

@jkbrzt jkbrzt left a comment

Choose a reason for hiding this comment

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

Added a few last comments. Let’s merge it afterward, and we can always continue to polish in master 🚀

@isidentical isidentical merged commit 245cede into httpie:master Nov 30, 2021
@isidentical isidentical deleted the httpie-plugins branch December 8, 2021 08:52
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.

Brew installed version doesn't work with plugins
4 participants