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

load HTTP Prompt environment from command line #131

Closed
tardypad opened this issue Aug 31, 2017 · 2 comments
Closed

load HTTP Prompt environment from command line #131

tardypad opened this issue Aug 31, 2017 · 2 comments

Comments

@tardypad
Copy link
Contributor

It would be convenient to be able to load a HTTP Prompt environment from the command line so as to launch http-prompt with a predefined context without requiring any manual input within http-prompt. Currently the only way to fully load such an environment is to execute exec /path/to/project.hp interactively.
Loading an environment in such a way would allow the creation of aliases

I'm thinking of 2 different ways to do this:

  • Option 1:
    add a --env cli parameter to would take the environment file to load as parameter
    http-prompt --env /path/to/project.hp
  • Option 2:
    support receiving data from stdin
    cat /path/to/project.hp | http-prompt

Each of these option would make it possible to create aliases:

  • Option 1
    alias http_project_prod='http-prompt --env /path/to/project_prod.hp
    alias http_project_test='http-prompt --env /path/to/project_test.hp
  • Option 2
    alias http_project_prod='cat /path/to/project_prod.hp | http-prompt'
    alias http_project_test='cat /path/to/project_test.hp | http-prompt'

Please let me know what you think of it
I'm willing to implement it myself if

@tardypad
Copy link
Contributor Author

I did a bit of research already and the option 2 might turn to be more tricky.

The prompt-toolkit doesn't support piping (see prompt-toolkit/python-prompt-toolkit#502) and will actually "crash" in such a case

We could surely use the snippet mentioned in that previous issue

if not sys.stdin.isatty():
    data = sys.stdin.read()

and load the context from this data but the prompt still exits (from https://github.com/jonathanslenders/python-prompt-toolkit/blob/master/prompt_toolkit/input.py#L67), unless we overwrite stdin afterwards sys.stdin = sys.stdout
It looks hacky and I don't know if that would cause issues...

Probably the other option would be not to use the prompt shortcut but to build our own CommandLineInterface instance (as mentioned in http://python-prompt-toolkit.readthedocs.io/en/master/pages/reference.html#module-prompt_toolkit.shortcuts)

So if you're ok with the option 1 of the --env cli parameter, it should be much easier to implement I believe

@eliangcs
Copy link
Contributor

eliangcs commented Sep 1, 2017

I tried it before, piping data to from stdin to a prompt-toolkit app is indeed not an easy thing to do. So I think we can add a --env option in the cli. Free feel the implement it. Thanks!

tardypad added a commit to tardypad/http-prompt that referenced this issue Sep 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants