No dependencies to install for the library or the tests:
git clone https://github.com/saeed205/netprobe-cli
cd netprobe-cli
python -m unittest discover -s tests -vOnly the linter needs installing:
pip install ruff
ruff check .Commands self-register, so nothing in the argument parser needs editing.
-
Create
netprobe/yourcommand.py. -
Write the logic as plain functions that take and return data - no printing, no
argparsetypes in the signature. That is what makes it testable without a network. -
Add a
_handle(args)that calls those functions and hands the rows tooutput.emit(). -
Register the parser:
from .cli import register @register def _add_parser(subparsers): p = subparsers.add_parser("yourcommand", help="one line of help") p.add_argument("target") p.set_defaults(handler=_handle)
-
Import the module in
netprobe/commands.pyand add it to_MODULES, keeping both alphabetical.
- Standard library only. A diagnostics tool that cannot be installed on a locked-down jump box is not much use. A dependency needs a strong argument.
- Python 3.9 is the floor. Typing-module spellings (
Dict,Optional) are used deliberately - see the comment inruff.tomlbefore "modernising" them. - Exit status is an interface.
0success,1the check failed,2usage error. People put these commands in monitoring checks; do not return0for a failed probe. - Never print from a helper. Rendering belongs in
output.pyso that--jsonkeeps working everywhere for free.
Plain unittest. Anything that opens a socket does not belong in the suite -
CI runs on sandboxed runners with no egress. Test the parsing, the arithmetic
and the precedence rules; those are where the bugs actually live.
Worth testing explicitly: boundary values (/31, /32, empty input, single
element), and anything where a plausible-looking implementation gives a wrong
answer.
Say what changed and why. If you made a non-obvious choice, put the reasoning in the description - that is the part nobody can reconstruct from the diff six months later.