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

Can module argument be optional with --http? #36

Closed
KyleKing opened this issue Feb 24, 2019 · 2 comments
Closed

Can module argument be optional with --http? #36

KyleKing opened this issue Feb 24, 2019 · 2 comments
Labels
question Not a bug, but a FAQ entry

Comments

@KyleKing
Copy link
Contributor

In pdoc, pdoc --http would create a summary of all modules in that environment.

However, in pdoc3, the same command pdoc3 --http returns an error that no module was specified (and no argument no http), so you launch with something like pdoc3 csv --http localhost:8000 and have to navigate to http://localhost:8000/csv/

Three questions:

  1. Could pdoc3 have the same behavior as pdoc3 to render the documentation for all available modules if no argument provided?
  2. Could pdoc3 use the default localhost:8000 if no arguments are provided to --http?
  3. If a module name is always required, could pdoc3 return the full URL to the specified module (see below)
(base) 05:20 [PDOC] ¿ pdoc csv --http localhost:8000
Starting pdoc server on localhost:8000
pdoc server ready at http://localhost:8000/csv/
# ^ instead of "pdoc server ready at http://localhost:8000/"
@KyleKing KyleKing changed the title HTTP Can module argument be optional with --http? Feb 24, 2019
@kernc kernc added the question Not a bug, but a FAQ entry label Feb 24, 2019
@kernc
Copy link
Member

kernc commented Feb 24, 2019

  1. Could pdoc3 have the same behavior as pdoc 0.3.2 to render the documentation for all available modules if no argument provided?

This was disabled intentionally and should remain thus at least for non---http modes (e.g. text, HTML out and PDF modes). If you'd like to look into making specifying the module optional for --http mode, welcome. But I suppose this won't work so well in complex Python environments as all modules will have to be loaded to fetch the docstrings (slow, error prone) and the caching mechanics have been purged (slower).

  1. Could pdoc3 use the default localhost:8000 if no arguments are provided to --http?

I don't think it can be made optional for as long as the type is set to the checking function:

pdoc/pdoc/cli.py

Lines 93 to 109 in 24a561c

def _check_host_port(s):
if s and ':' not in s:
raise argparse.ArgumentTypeError(
"'{}' doesn't match '[HOST]:[PORT]'. "
"Specify `--http :` to use default hostname and port.".format(s))
return s
aa(
"--http",
default='',
type=_check_host_port,
metavar='HOST:PORT',
help="When set, pdoc will run as an HTTP server providing documentation "
"for specified modules. If you just want to use the default hostname "
"and port ({}:{}), set the parameter to :.".format(DEFAULT_HOST, DEFAULT_PORT),
)

There simply is no way of knowing whether the user intended a switch parameter or the next argument. That said, pdoc uses the default if simply : is passed to --http, as documented.

This was introduced in stead of a flood of separate switches for as little used a feature. At the time, I thought --http : was not too bad to type out, particularly as most command-line shells today offer readline/history ().

  1. If a module name is always required, could pdoc3 return the full URL to the specified module (see below)

More than one module can be specified. What then? It isn't that hard to click through another hyperlink. Or even just leave the tab in development open.

@KyleKing
Copy link
Contributor Author

Thanks for the feedback. I missed the shortcut on just passing :. I think you answered all my questions and I'll close this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Not a bug, but a FAQ entry
Development

No branches or pull requests

2 participants