Page MenuHomePhabricator

Add --help docs to fresh-node commands
Closed, ResolvedPublic

Description

As part of working on T424859: The `og:image` tag for the wikipedia.org portal leads to a broken image thumbnail, I wanted to test my changes locally before pushing them to Gerrit.

I first ran fresh-node in the directory of the repo I was working within for that task (wikimedia/portals), and then followed (most of) the instructions in that repo's CONTRIBUTING.md file in order to try and get that repo running locally:

  • npm install
  • npm run build-all-portals
  • npm run start --portal=wikipedia.org

After running the last command, I tried visiting http://localhost:8000/src/wikipedia.org/ (as stated in the CONTRIBUTING.md file), but nothing was loading.

I then searched for tasks under the Fresh Phab project containing the word localhost (I guess, in case there were any tasks that'd been filed about not being able to connect on localhost to a server running within Fresh) and found the task T272316: `fresh-node -env -net` not working on macOS 10.15. This task was what first informed me about Fresh's -net option.

After finding out about the -net option, I then ran fresh-node -net within the same directory (after exiting the current Fresh session).
I ran the commands listed above within my new fresh-node -net session, and....... I still couldn't connect to http://localhost:8000.

The source code behind Fresh's -net option links to https://docs.docker.com/network/network-tutorial-host/, so that was my next port of call. Annoyingly, though, a page at that URL no longer seems to exist (obviously it's not a cool URI :/), so I then found an archived copy of the page from February 2025 on the Wayback Machine.
Among other things, that (archived) page includes a notice that:

The host networking driver only works on Linux hosts, and as an opt-in feature in Docker Desktop version 4.34 and later. To enable this feature in Docker Desktop, navigate to the Resources tab in Settings, and then under Network select Enable host networking.

From what I can see, Fresh - in response to the -net option - sends the additional argument --network host to the Docker command that it runs.
I therefore enabled that option within my Docker Desktop app, and tried attempting the above steps again...

....and it now worked - I was now able to access http://localhost:8000 from my machine :D


So I guess, this is probably a long way of asking -- if possible, please can Fresh's -net option (and what is needed to be enabled in order to use it) be officially documented somewhere? :)

Details

Related Changes in Gerrit:

Event Timeline

Krinkle renamed this task from Document how to use the -net option in Fresh to Add --help docs to fresh-node commands.Apr 29 2026, 6:01 PM

(FWIW, I was also thinking that docs could be added in the README (probably under 'Usage'); & in addition to docs on what the options themselves do, maybe a pointer for folks using Docker Desktop to enable the 'Enable host networking' option)

edit: apparently I had the wrong idea of what -net was meant to achieve :p (IRC logs)

The -net option is documented in the same way all other options are documented, which is to say, it documented, but hard to reach. We should address that!

All options are currently documented in two places:

  • Usage string when invoking the CLI.
  • Option documentation, in the repo.
Usage string
usage: fresh-node20 [-env-mw] [-env-bs] [-env-sauce] [env=PREFIX] [-net] [-root] [-podman] [-- command]
to run a command in the container, pass it after --
Option documentation
# Option: -env-mw
#   Forward `MW_*` and `MEDIAWIKI_*` environment variables from the host machine
#   to the Fresh container. This is designed for use with MediaWiki tests.
#   If an `.env` file exists in the current directory, its `MW_*` and `MEDIAWIKI_` entries
#   will also be read and forwarded to the container.
#   Note that the variables set in via `.env` take precedence over variables set at
#   runtime e.g. from `export` commands in `.bashrc`.# Option: -net
#   This exposes network ports from the host machine to the Fresh container.
#   For example, to enable access to a MediaWiki web server.
#   https://docs.docker.com/network/network-tutorial-host/

Fresh is meant to be given zero trust. The security goal behind it means I expect users to audit it and make it feel their own when installing it. This is why the Fresh source is minimal, simple, human-readable, and self-contained. The readme encourages users to read the source.

The doc blocks shown above are specifically written for the end-user, and intentionally placed near the top of the file. (They're not inline comments about code, or otherwise aimed at maintainers.)

But.. there's a couple of flaws with this.

  1. This usage string is only printed after you make a mistake, like fresh-node --whatever. That shouldn't be required for discovery of documentation. This is kind of true for most CLIs, and if you stab in the dark and run fresh-node --help, that does technically work and prints the usage string (albeit it alongside an error saying that "help" is not a valid option.) We should make --help a recognised option so that the error isn't printed there, and remind people in the README that --help exists.
  1. Once you know which option you're likely interested in, it's not clear where to go. The usage string only mentions which options exist, not what they do in detail. I choose the names to be descriptive and clear enough to let you find what you're interested in. However, assuming you reviewed the code once in the past and were satisfied it couldn't do anything undesirable, that doesn't mean you'll remember forever what it does, or remember that it contains documentation for options you didn't know you'd want until later.

Documentation shouldn't be hard, and should surface itself within the tool. So, yeah... make a proper --help option!.

I suggest:

  • Move the docblocks to the usage string.
  • Recognise --help as a valid option (i.e. remove unknown option: --help from the --help output).
  • Mention the --help option in the README so that you can easily (re-)discover it.
LazyShrey subscribed.

Hey i would like to work on this issue, i will publish a patch soon, please just let me know if that looks good :)

Change #1287901 had a related patch set uploaded (by LazyShrey; author: LazyShrey):

[fresh@master] fresh-node: Add proper --help docs

https://gerrit.wikimedia.org/r/1287901

I’ve submitted a patch to Gerrit for T424867:
https://gerrit.wikimedia.org/r/c/fresh/+/1287901

This adds a proper --help option for fresh-node, makes -h/--help recognized options, and adds a README note for discoverability.

Change #1287901 merged by jenkins-bot:

[fresh@master] fresh-node: Add proper --help docs

https://gerrit.wikimedia.org/r/1287901