Skip to content
15 changes: 8 additions & 7 deletions snekbox/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,19 @@ def parse_args() -> argparse.Namespace:
)
parser.add_argument("code", help="the Python code to evaluate")
parser.add_argument(
"nsjail_args",
action="store_const",
const=[],
"--nsjail-args",
nargs="*",
default=[],
dest="nsjail_args",
Comment on lines +16 to +19
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does the help output look like now?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Old:

root@snekbox-6c47cc4bf5-9gchm:/snekbox# python -m snekbox --help
usage: snekbox [-h] code [nsjail_args ...] [--- py_args ...]

positional arguments:
  code         the Python code to evaluate
  nsjail_args  override configured NsJail options (default: [])
  py_args      arguments to pass to the Python process (default: ['-c'])

options:
  -h, --help   show this help message and exit

New:

root@a7cdb21501e0 /snekbox
❯ python -m snekbox --help
usage: snekbox [-h] code [nsjail_args ...] [--- py_args ...]

positional arguments:
  code                  the Python code to evaluate

options:
  -h, --help            show this help message and exit
  --nsjail-args [NSJAIL_ARGS ...]
                        override configured NsJail options (default: []) (default: [])
  --py-args [PY_ARGS ...]
                        arguments to pass to the Python process (default: ['-c']) (default: ['-c'])

I can try find a solution that brings them closer together, they are functionally the same (hence no updates in the test cases) but the help is presented differently.

Copy link
Member

@MarkKoz MarkKoz Oct 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the default shown twice now?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They're now options rather than positional arguments. That's confusing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the default shown twice now?

We hard-coded it previously but now switching it from store_const appears to display it again, we can remove our hardcoding.

They're now options rather than positional arguments. That's confusing.

Yeah, I'll be honest I'd just updated it to maintain functionality because argparse in 3.14 broke it, hadn't looked at how it changed the help command.

I'll have a play around to see if I can maintain behaviour on 3.14 and keep the help command useful.

help="override configured NsJail options (default: [])",
)
parser.add_argument(
"py_args",
action="store_const",
const=["-c"],
"--py-args",
nargs="*",
default=["-c"],
dest="py_args",
help="arguments to pass to the Python process (default: ['-c'])",
)

# nsjail_args and py_args are just dummies for documentation purposes.
# Their actual values come from all the unknown arguments.
# There doesn't seem to be a better solution with argparse.
Expand Down