69 lines
1.7 KiB
C
69 lines
1.7 KiB
C
|
/*
|
||
|
YAAP - Yet Another Argument Parser
|
||
|
|
||
|
Copyright (C) 2018 Dominik Meyer
|
||
|
|
||
|
This program is free software: you can redistribute it and/or modify
|
||
|
it under the terms of the GNU General Public License as published by
|
||
|
the Free Software Foundation, either version 3 of the License, or
|
||
|
(at your option) any later version.
|
||
|
|
||
|
This program is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
GNU General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU General Public License
|
||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||
|
*/
|
||
|
|
||
|
/**
|
||
|
* @file example1.c
|
||
|
* @brief brief example on using YAAP
|
||
|
* @author Dominik Meyer <dmeyer@federationhq.de>
|
||
|
* @copyright 2018 by Dominik Meyer
|
||
|
*/
|
||
|
|
||
|
#include "../src/argparse.h"
|
||
|
#include <stdio.h>
|
||
|
|
||
|
/*
|
||
|
* @brief example command
|
||
|
*/
|
||
|
int test1(int argc, char **argv)
|
||
|
{
|
||
|
printf("Test\n");
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
|
||
|
/*
|
||
|
* @brief main function for this example
|
||
|
*/
|
||
|
int main (int argc, char **argv)
|
||
|
// initialize the parsing context
|
||
|
{
|
||
|
struct arg_parse_ctx *argparse_ctx = argparse_init();
|
||
|
|
||
|
// create a command argument
|
||
|
struct arg_parse_cmd test_cmd= {
|
||
|
{0,1,0}, // 1 = mandatory element
|
||
|
0,
|
||
|
"test", // command name
|
||
|
"simple test", // command description
|
||
|
&test1 // if found call this function
|
||
|
};
|
||
|
|
||
|
/// add the argument command to context
|
||
|
argparse_add_command(argparse_ctx, &test_cmd);
|
||
|
|
||
|
/// parse the commandline
|
||
|
int ret=argparse_parse(argparse_ctx, argc, argv);
|
||
|
|
||
|
/// free context
|
||
|
argparse_free(argparse_ctx);
|
||
|
|
||
|
return ret;
|
||
|
|
||
|
}
|