mctools
mctools copied to clipboard
mcli with --command specified doesn't work
The docs at https://mctools.readthedocs.io/en/master/mcli.html#examples state that multiple commands can be specified, followed by the password as a final positional argument.
This doesn't work when using nargs="+" for the argument "command" since that allows an ambiguous number of arguments which must be terminated by either another argument or "--"
For example, take the example from the docs: mcli mc.server.net rcon --command 'msg ILoveCraft Minecraft loves you too!' craft
Given the code in main.py:
rcon_parser.add_argument('-c', '--command', action='append', nargs='+',
help='Command to send to the RCON server. May specify multiple.', required=False)
With action="append" and nargs=+, this is accepting an ambiguous number of values for --command, which gets created as a list of args within another list:
command=[['msg ILoveCraft Minecraft loves you too!', 'craft']]
And the parser ends up with no password.
I've made some updates to make it work like the documentation, removing the nargs of "+", which allows one command per instance of "--command" followed by a final positional argument for the password.
Tell me what you think.
% diff __main__.py __main__.py.new
290c290
< rcon_parser.add_argument('-c', '--command', action='append', nargs='+',
---
> rcon_parser.add_argument('-c', '--command', action='append',
434c434
< "# Executing user command: '§2{}§r' ...".format(' '.join(com)))
---
> "# Executing user command: '§2{}§r' ...".format(com))
436c436
< val = rcon.command(' '.join(com))
---
> val = rcon.command(com)
441c441
< "# Done executing command: '§2{}§r'!".format(' '.join(com)))
---
> "# Done executing command: '§2{}§r'!".format(com))
I created a local branch and committed a fix, but I can't create a new branch here in order to make a pull request.