MCPcopy Index your code
hub / github.com/python/cpython / cli

Function cli

Lib/pydoc.py:2752–2836  ·  view source on GitHub ↗

Command-line interface (looks at sys.argv to decide what to do).

()

Source from the content-addressed store, hash-verified

2750
2751
2752def cli():
2753 """Command-line interface (looks at sys.argv to decide what to do)."""
2754 import getopt
2755 class BadUsage(Exception): pass
2756
2757 _adjust_cli_sys_path()
2758
2759 try:
2760 opts, args = getopt.getopt(sys.argv[1:], 'bk:n:p:w')
2761 writing = False
2762 start_server = False
2763 open_browser = False
2764 port = 0
2765 hostname = 'localhost'
2766 for opt, val in opts:
2767 if opt == '-b':
2768 start_server = True
2769 open_browser = True
2770 if opt == '-k':
2771 apropos(val)
2772 return
2773 if opt == '-p':
2774 start_server = True
2775 port = val
2776 if opt == '-w':
2777 writing = True
2778 if opt == '-n':
2779 start_server = True
2780 hostname = val
2781
2782 if start_server:
2783 browse(port, hostname=hostname, open_browser=open_browser)
2784 return
2785
2786 if not args: raise BadUsage
2787 for arg in args:
2788 if ispath(arg) and not os.path.exists(arg):
2789 print('file %r does not exist' % arg)
2790 sys.exit(1)
2791 try:
2792 if ispath(arg) and os.path.isfile(arg):
2793 arg = importfile(arg)
2794 if writing:
2795 if ispath(arg) and os.path.isdir(arg):
2796 writedocs(arg)
2797 else:
2798 writedoc(arg)
2799 else:
2800 help.help(arg, is_cli=True)
2801 except (ImportError, ErrorDuringImport) as value:
2802 print(value)
2803 sys.exit(1)
2804
2805 except (getopt.error, BadUsage):
2806 cmd = os.path.splitext(os.path.basename(sys.argv[0]))[0]
2807 print("""pydoc - the Python documentation tool
2808
2809{cmd} <name> ...

Callers 3

pydoc.pyFile · 0.85
_do_testMethod · 0.85
run_cliMethod · 0.85

Calls 15

_adjust_cli_sys_pathFunction · 0.85
aproposFunction · 0.85
browseFunction · 0.85
ispathFunction · 0.85
importfileFunction · 0.85
writedocsFunction · 0.85
writedocFunction · 0.85
splitextMethod · 0.80
existsMethod · 0.45
exitMethod · 0.45
isfileMethod · 0.45
isdirMethod · 0.45

Tested by 2

_do_testMethod · 0.68
run_cliMethod · 0.68