Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

mcli with --command specified doesn't work #16

Open
gsgleason opened this issue Aug 20, 2024 · 0 comments
Open

mcli with --command specified doesn't work #16

gsgleason opened this issue Aug 20, 2024 · 0 comments

Comments

@gsgleason
Copy link

gsgleason commented Aug 20, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant