nyx-cmd/nyx_cmd_query_command.cpp
int NyxCmdQueryCommand::resolveArguments(int argc, char **argv)
{
	int retVal = RESOLVE_ARGS_INVALID;
	int c = 0;

	// reset errors and prevent from outputting
	opterr = 0;

	static struct option long_options[] =
	{
		{"format", required_argument, 0, 'f' },
		{"list", no_argument, 0, 'l' },
		{0, 0, 0, 0 }
	};

	while (1)
	{
		int option_index = 0;

		c = getopt_long(argc, argv, "lf:", long_options, &option_index);

		if (c == -1)
		{
			break;
		}

		switch (c)
		{
			// format is a long option only and in index 0
			case 'f':
				output = NyxCmdOutput::createNyxCmdOutput(optarg);

				if (NULL == output)
				{
					retVal = RESOLVE_ARGS_FAILED;
				}

				break;

			case 'l':
				retVal = RESOLVE_ARGS_LIST_ALL_QUERIES;
				break;

			// all that are not recognized make the function fail
			default:
				retVal = RESOLVE_ARGS_FAILED;
				break;
		}
	}

	if (RESOLVE_ARGS_INVALID == retVal)
	{
		// check if there is still arguments left
		// there wasn't so it's a query for all
		if (0 == (argc - optind))
		{
			retVal = RESOLVE_ARGS_EXECUTE_ALL_QUERIES;
		}
		else
		{
			retVal = optind;
		}
	}

	return retVal;
}
/*
* Parses the command line arguments and resolves them to proper variables.
*
* RESOLVE_ARGS_INVALID              Resolving arguments not done
* RESOLVE_ARGS_FAILED               Resolving arguments failed
* RESOLVE_ARGS_LIST_ALL_QUERIES     Resolving arguments succeeded with list
*                                   all queries action
* RESOLVE_ARGS_EXECUTE_ALL_QUERIES  Resolving arguments succeeded with
*                                   execute all queries action
* >0                                Resolving arguments succeeded and
*                                   contains valid index from argv where
*                                   to start parsing queries
*/
Parses the command line arguments and resolves them to proper variables.
RESOLVE_ARGS_INVALID              Resolving arguments not done
RESOLVE_ARGS_FAILED               Resolving arguments failed
RESOLVE_ARGS_LIST_ALL_QUERIES     Resolving arguments succeeded with list
all queries action
RESOLVE_ARGS_EXECUTE_ALL_QUERIES  Resolving arguments succeeded with
execute all queries action
>0                                Resolving arguments succeeded and
contains valid index from argv where
to start parsing queries
Parses the command line arguments and resolves them to proper variables . RESOLVE_ARGS_INVALID Resolving arguments not done RESOLVE_ARGS_FAILED Resolving arguments failed RESOLVE_ARGS_LIST_ALL_QUERIES Resolving arguments succeeded with list all queries action RESOLVE_ARGS_EXECUTE_ALL_QUERIES Resolving arguments succeeded with execute all queries action > 0 Resolving arguments succeeded and contains valid index from argv where to start parsing queries
int NyxCmdQueryCommand::resolveArguments(int argc, char **argv)
{
	int retVal = RESOLVE_ARGS_INVALID;
	int c = 0;
	opterr = 0;
	static struct option long_options[] =
	{
		{"format", required_argument, 0, 'f' },
		{"list", no_argument, 0, 'l' },
		{0, 0, 0, 0 }
	};
	while (1)
	{
		int option_index = 0;
		c = getopt_long(argc, argv, "lf:", long_options, &option_index);
		if (c == -1)
		{
			break;
		}
		switch (c)
		{
			case 'f':
				output = NyxCmdOutput::createNyxCmdOutput(optarg);
				if (NULL == output)
				{
					retVal = RESOLVE_ARGS_FAILED;
				}
				break;
			case 'l':
				retVal = RESOLVE_ARGS_LIST_ALL_QUERIES;
				break;
			default:
				retVal = RESOLVE_ARGS_FAILED;
				break;
		}
	}
	if (RESOLVE_ARGS_INVALID == retVal)
	{
		if (0 == (argc - optind))
		{
			retVal = RESOLVE_ARGS_EXECUTE_ALL_QUERIES;
		}
		else
		{
			retVal = optind;
		}
	}
	return retVal;
}
int NyxCmdQueryCommand :: resolveArguments ( int argc , char * * argv ) { int retVal = RESOLVE_ARGS_INVALID ; int c = 0 ; opterr = 0 ; static struct option long_options [ ] = { { " " , required_argument , 0 , ' ' } , { " " , no_argument , 0 , ' ' } , { 0 , 0 , 0 , 0 } } ; while ( 1 ) { int option_index = 0 ; c = getopt_long ( argc , argv , " " , long_options , & option_index ) ; if ( c == -1 ) { break ; } switch ( c ) { case ' ' : output = NyxCmdOutput :: createNyxCmdOutput ( optarg ) ; if ( NULL == output ) { retVal = RESOLVE_ARGS_FAILED ; } break ; case ' ' : retVal = RESOLVE_ARGS_LIST_ALL_QUERIES ; break ; default : retVal = RESOLVE_ARGS_FAILED ; break ; } } if ( RESOLVE_ARGS_INVALID == retVal ) { if ( 0 == ( argc - optind ) ) { retVal = RESOLVE_ARGS_EXECUTE_ALL_QUERIES ; } else { retVal = optind ; } } return retVal ; }
Parses the command line arguments and resolves them to proper variables.
Parses the command line arguments and resolves them to proper variables .
// reset errors and prevent from outputting // format is a long option only and in index 0 // all that are not recognized make the function fail // check if there is still arguments left // there wasn't so it's a query for all