Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Help: Display arguments for each command #325

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
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
25 changes: 24 additions & 1 deletion pymine/logic/cmds/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

import inspect
import os

from pymine.server import server
Expand All @@ -37,4 +38,26 @@ async def help(uuid: str):
for name, command in server.api.commands._commands.items():
func, node = command
doc = getattr(func, "__doc__")
server.console.info(f"{name}: {'A command.' if doc is None else doc}")
server.console.info(f"{name}: {'Documentation missing.' if doc is None else doc}")

if func.__code__.co_argcount > 1:
server.console.info(" Arguments:")
argspec = inspect.getfullargspec(func)

# XXX: Causes errors / incorrect behaviour if you introduce other mandatory arguments
for arg in argspec.args[1:]: # Skipping the first 'uuid'
# look at this mess
ann = (
(
": "
+ (
argspec.annotations[arg].__name__
if hasattr(argspec.annotations[arg], "__name__")
else argspec.annotations[arg].__class__.__name__
)
)
if arg in argspec.annotations.keys()
else ""
)

server.console.info(" - " + arg + ann)