8000 gh-68583: webbrowser: replace `getopt` with `argparse`, add long options by hugovk · Pull Request #117047 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-68583: webbrowser: replace getopt with argparse, add long options #117047

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

Merged
merged 17 commits into from
Apr 13, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Simplify using action='store_const' and a common dest
  • Loading branch information
hugovk committed Apr 10, 2024
commit 9cf39cdab823da46339140a4b829514bb8c2987c
14 changes: 5 additions & 9 deletions Lib/webbrowser.py
Original file line number Diff line number Diff line change
Expand Up @@ -682,9 +682,11 @@ def parse_args(arg_list: list[str] | None):
parser.add_argument("url", help="URL to open")

group = parser.add_mutually_exclusive_group()
group.add_argument("-n", "--new-window", action="store_true",
group.add_argument("-n", "--new-window", action="store_const",
const=1, dest="new_win",
help="open new window")
group.add_argument("-t", "--new-tab", action="store_true",
group.add_argument("-t", "--new-tab", action="store_const",
const=2, dest="new_win",
help="open new tab")

args = parser.parse_args(arg_list)
Expand All @@ -695,13 +697,7 @@ def parse_args(arg_list: list[str] | None):
def main(arg_list: list[str] | None = None):
args = parse_args(arg_list)

new_win = 0
if args.new_window:
new_win = 1
elif args.new_tab:
new_win = 2

open(args.url, new_win)
open(args.url, args.new_win)

print("\a")

Expand Down
0