#include <stdio.h>
#include <unistd.h>
#include <getopt.h>
#include <cjson/cJSON.h>

#include "compile.h"

/**
 * @brief  应用程序主函数
 * @param  argc       输入参数个数
 * @param  argv       输入参数详细内容
 * @return 0
 */
int main(int argc, char **argv)
{
    int c, optidx = 0;

    cJSON *root = cJSON_CreateObject();

    static const struct option long_opts[] = {
        { "help", no_argument, NULL, 'h' },
        { "version", no_argument, NULL, 'v' },
        // TODO 添加其它需要处理的参数配置
        {NULL, 0, NULL, 0}
    };

    cJSON_Delete(root);
    while((c = getopt_long(argc, argv, "hv", long_opts, &optidx)) != -1)
    {
        switch (c)
        {
        case 'v':
            fprintf(stdout, "User demo version: %s(%s)\n", sGATE_GIT_TAGS, sGATE_GIT_VERS);
            break;
        //TODO 添加其它必要处理参数过程

        case '?':
        case 'h':
            fprintf(stdout, "Usage: %s [-h] [-v] ...\n", argv[0]);
            fprintf(stdout, "options:\n");
            fprintf(stdout, "\t-v, --version show program version\n");
            fprintf(stdout, "\t-h, --help    print this message\n");
            break;
        }
    }

    return 0;
}