# Buggy code
def run(self):
    results = None
    if self.args.action in ["start", "restart", "stop", "status"]:
        if self.args.parameter:
            method_name = "bot_" + self.args.action
            call_method = getattr(self, method_name)
            results = call_method(self.args.parameter)
        else:
            method_name = "botnet_" + self.args.action
            call_method = getattr(self, method_name)
            results = call_method()
    elif self.args.action == "run":
        if self.args.parameter and len(self.args.parameter) == 1:
            self.bot_run(self.args.parameter[0])
        else:
            print("Exactly one bot-id must be given for run.")
            exit(2)
    elif self.args.action == "list":
        if self.args.parameter[0] not in ["bots", "queues"]:
            print("Second argument must be 'bots' or 'queues'.")
            exit(2)
        method_name = "list_" + self.args.parameter[0]
        call_method = getattr(self, method_name)
        results = call_method()
    elif self.args.action == "log":
        if not self.args.parameter:
            print("You must give parameters for 'log'.")
            exit(2)
        results = self.read_log(*self.args.parameter)
    elif self.args.action == "clear":
        if not self.args.parameter:
            print("Queue name not given.")
            exit(2)
        results = self.clear_queue(self.args.parameter)

    if self.args.type == "json":
        print(json.dumps(results))


# Traceback (IndexError)
$ intelmqctl list
Traceback (most recent call last):
File "/usr/bin/intelmqctl", line 9, in <module>
load_entry_point('intelmq==1.0.0.dev4', 'console_scripts', 'intelmqctl')()
File "/usr/lib/python3/dist-packages/intelmq/bin/intelmqctl.py", line 522, in main
x.run()
File "/usr/lib/python3/dist-packages/intelmq/bin/intelmqctl.py", line 262, in run
if self.args.parameter[0] not in ['bots', 'queues']:
IndexError: list index out of range

# Fixed code
def run(self):
    results = None
    if self.args.action in ["start", "restart", "stop", "status"]:
        if self.args.parameter:
            call_method = getattr(self, "bot_" + self.args.action)
            results = call_method(self.args.parameter[0])
        else:
            call_method = getattr(self, "botnet_" + self.args.action)
            results = call_method()
    elif self.args.action == "run":
        if self.args.parameter and len(self.args.parameter) == 1:
            self.bot_run(self.args.parameter[0])
        else:
            print("Exactly one bot-id must be given for run.")
            self.parser.print_help()
            exit(2)
    elif self.args.action == "list":
        if not self.args.parameter or self.args.parameter[0] not in ["bots", "queues"]:
            print("Second argument for list must be 'bots' or 'queues'.")
            self.parser.print_help()
            exit(2)
        method_name = "list_" + self.args.parameter[0]
        call_method = getattr(self, method_name)
        results = call_method()
    elif self.args.action == "log":
        if not self.args.parameter:
            print("You must give parameters for 'log'.")
            self.parser.print_help()
            exit(2)
        results = self.read_log(*self.args.parameter)
    elif self.args.action == "clear":
        if not self.args.parameter:
            print("Queue name not given.")
            self.parser.print_help()
            exit(2)
        results = self.clear_queue(self.args.parameter[0])

    if self.args.type == "json":
        print(json.dumps(results))