[Python-checkins] gh-101313: Add -h and --help arguments to the webbrowser module (gh-101374)

corona10 webhook-mailer at python.org
Wed Mar 22 08:20:00 EDT 2023


https://github.com/python/cpython/commit/3d7eb66c963c0c86021738271483bef27c425b17
commit: 3d7eb66c963c0c86021738271483bef27c425b17
branch: main
author: Icelain <xerneas965 at gmail.com>
committer: corona10 <donghee.na92 at gmail.com>
date: 2023-03-22T21:19:52+09:00
summary:

gh-101313: Add -h and --help arguments to the webbrowser module (gh-101374)

files:
A Misc/NEWS.d/next/Library/2023-01-27-14-51-07.gh-issue-101313.10AEXh.rst
M Lib/webbrowser.py

diff --git a/Lib/webbrowser.py b/Lib/webbrowser.py
index a56ff33dbbdc..4336597e68f6 100755
--- a/Lib/webbrowser.py
+++ b/Lib/webbrowser.py
@@ -713,11 +713,12 @@ def open(self, url, new=0, autoraise=True):
 
 def main():
     import getopt
-    usage = """Usage: %s [-n | -t] url
+    usage = """Usage: %s [-n | -t | -h] url
     -n: open new window
-    -t: open new tab""" % sys.argv[0]
+    -t: open new tab
+    -h, --help: show help""" % sys.argv[0]
     try:
-        opts, args = getopt.getopt(sys.argv[1:], 'ntd')
+        opts, args = getopt.getopt(sys.argv[1:], 'ntdh',['help'])
     except getopt.error as msg:
         print(msg, file=sys.stderr)
         print(usage, file=sys.stderr)
@@ -726,6 +727,9 @@ def main():
     for o, a in opts:
         if o == '-n': new_win = 1
         elif o == '-t': new_win = 2
+        elif o == '-h' or o == '--help': 
+            print(usage, file=sys.stderr)
+            sys.exit()
     if len(args) != 1:
         print(usage, file=sys.stderr)
         sys.exit(1)
diff --git a/Misc/NEWS.d/next/Library/2023-01-27-14-51-07.gh-issue-101313.10AEXh.rst b/Misc/NEWS.d/next/Library/2023-01-27-14-51-07.gh-issue-101313.10AEXh.rst
new file mode 100644
index 000000000000..63d0a7286920
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2023-01-27-14-51-07.gh-issue-101313.10AEXh.rst
@@ -0,0 +1 @@
+Added -h and --help arguments to the webbrowser CLI



More information about the Python-checkins mailing list