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

Better Argument Parsing for handlers #10

Open
SakiiR opened this issue Aug 26, 2017 · 0 comments
Open

Better Argument Parsing for handlers #10

SakiiR opened this issue Aug 26, 2017 · 0 comments

Comments

@SakiiR
Copy link

SakiiR commented Aug 26, 2017

In Fact a better Argument parsing would be better.

https://docs.python.org/3/library/argparse.html

Il would be great if thoses kind of part use argparse:

def jabber_cmd_jabber(data, buffer, args):
    """ Command '/jabber'. """
    global jabber_servers, jabber_config_option
    if args == "" or args == "list":
        jabber_list_servers_chats("")
    else:
        argv = args.split(" ")
        argv1eol = ""
        pos = args.find(" ")
        if pos > 0:
            argv1eol = args[pos+1:]
        if argv[0] == "list":
            jabber_list_servers_chats(argv[1])
        elif argv[0] == "add":
            if len(argv) >= 4:
                server = jabber_search_server_by_name(argv[1])
                if server:
                    weechat.prnt("", "jabber: server '%s' already exists" % argv[1])
                else:
                    kwargs = {'jid': argv[2], 'password': argv[3]}
                    if len(argv) > 4:
                        conn_server, _, conn_port = argv[4].partition(':')
                        if conn_port and not conn_port.isdigit():
                            weechat.prnt("", "jabber: error, invalid port, digits only")
                            return weechat.WEECHAT_RC_OK
                        if conn_server: kwargs['server'] = conn_server
                        if conn_port: kwargs['port'] = conn_port
                    server = Server(argv[1], **kwargs)
                    jabber_servers.append(server)
                    weechat.prnt("", "jabber: server '%s' created" % argv[1])
            else:
                weechat.prnt("", "jabber: unable to add server, missing arguments")
                weechat.prnt("", "jabber: usage: /jabber add name jid password [server[:port]]")
        elif argv[0] == "alias":
            alias_command = AliasCommand(buffer, argv=argv[1:])
            alias_command.run()
        elif argv[0] == "connect":
# [...]
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