int parse_options()

in configuration/src/config.cpp [55:126]


int parse_options( int argc, const char* argv[], Daemon& cf_daemon )
{
    try
    {
        std::string domainless_gmsa_field( "CREDENTIALS_FETCHER_SECRET_NAME_FOR_DOMAINLESS_GMSA" );
        struct option long_options[] = { { "help", no_argument, nullptr, 'h' },
                                         { "self_test", no_argument, nullptr, 't' },
                                         { "verbosity", required_argument, nullptr, 'v' },
                                         { "aws_sm_secret_name", required_argument, nullptr, 's' },
                                         { "version", no_argument, nullptr, 'n' },
                                         { "healthcheck", no_argument, nullptr, 'c' },
                                         { nullptr, 0, nullptr, 0 } };
        std::map<std::string, std::string> options_descriptions{
            { "help", "produce help message" },
            { "self_test", "Run tests such as utf16 decode" },
            { "verbosity", "set verbosity level" },
            { "aws_sm_secret_name", "Name of secret containing username/password in AWS Secrets "
                                    "Manager (in same region)" },
            { "healthcheck", "health of credentials-fetcher" },
            { "version", "Version of credentials-fetcher" } };
        int option;
        int healthCheckResponse;
        while ( ( option = getopt_long( argc, (char* const*)argv, "htv:s:n", long_options, nullptr ) ) != -1 )
        {
            switch ( option )
            {
            case 'h':
                print_help( long_options, options_descriptions );
                return EXIT_FAILURE;
            case 't':
                std::cout << "run diagnostic set" << std::endl;
                cf_daemon.run_diagnostic = true;
                break;
            case 'v':
                break;
            case 's':
                cf_daemon.aws_sm_secret_name = optarg;
                break;
            case 'n':
                std::cout << CMAKE_PROJECT_VERSION << std::endl;
                return EXIT_FAILURE;
            case 'c':
                healthCheckResponse = HealthCheck("test");
                std::cout << healthCheckResponse << std::endl;
                if(healthCheckResponse != 0)
                {
                    exit(EXIT_FAILURE);
                }
                else
                {
                    exit(EXIT_SUCCESS);
                }

            default:
                std::cout << "Run with --help to see options" << std::endl;
                return EXIT_FAILURE;
            }
        }

        if ( cf_daemon.aws_sm_secret_name.empty() )
        {
            cf_daemon.aws_sm_secret_name = Util::retrieve_variable_from_ecs_config(domainless_gmsa_field);
        }
    }
    catch ( const std::exception& ex )
    {
        std::cout << "Run with --help to see options" << std::endl;
        return EXIT_FAILURE;
    }

    return EXIT_SUCCESS;
}