Universal help for terminal commands

Viewed 29

When I look for help for a terminal command, I usually go for man <command> or <command> -h (usually a short hand for <command> --help).

I'm writing a little Python function to get help/docs for terminal commands, but not sure how to make it "universal". Here are a few of the problems I've encountered so far.

A man page doesn't always exist. Here, for 2to3 command, 2to3 -h and 2to3 --help work, but man 2to3 doesn't:

$ man 2to3
No manual entry for 2to3

man doesn't always point to the "right" (as in "given by which") command. With pack (a wads script) I get this:

$ which pack
.../dev/unix_scripts/pack
$ pack -h
usage: pack.py [-h]
               {generate-and-publish-docs,current-configs,increment-configs-version,current-configs-version,twine-upload-dist,read-and-resolve-setup-configs,update-setup-cfg,go,goo,check-in,get-name-from-configs,run-setup,current-pypi-version,validate-pkg-dir,git-commit-and-push,process-missing-module-docstrings}
...
$ man pack                                                                                                                                  LIBPACK(3)

NAME
       libpack - support for connected components
...

This means that I can't even rely on a logic like;

# if man page is found, use that
# else try --help
# else etc.

And of course, neither -h nor --help are universal (and -h can even clash with some arguments (e.g. ls -h).

I'm looking for a solution for unix-flavored systems (team works with linux and mac), but an even more universal solution working in DOS would be welcome!

0 Answers
Related