private function createCode($name, \ReflectionMethod $method)
    {
        return function (InputInterface $input, OutputInterface $output) use ($name, $method) {
            $client = new Client([], null, $output);

            if ($input->getOption('token')) {
                $client->authorize($input->getOption('token'));
            }

            $methodName = $method->getName();
            $api = $client->api(strtolower($name));
            $args = (new NamedArgumentsResolver($method))->resolve(array_merge($input->getOptions(), $input->getArguments()));
            $outputClass = $this->generateOutputClassFromApiClass($api);

            $response = call_user_func_array([$api, $methodName], $args);

            if (method_exists($outputClass, $methodName) && false === $input->getOption('debug') && $response->getStatusCode() < 400) {
                (new $outputClass())->{$methodName}($output, $response);
            } elseif (!method_exists($outputClass, $methodName) || true === $input->getOption('debug')) {
                $output->writeln("Headers:\n" . print_r($response->getHeaders(), true) . "Body:\n" . print_r((string) $response->getBody(), true));
            }
        };
    }