-
Notifications
You must be signed in to change notification settings - Fork 2
Argument parser
This page describes functions that interact with argument parser from libddos2
. To use them in your module you need to do: #include <ddos2/arguments.h>
You could use the following argument types:
-
ARG_BOOL
– set to check whether argument is present inargv
-
ARG_INT
– requires anint64_t
number after it -
ARG_STR
– requires a string after it which would be represented aschar*
after parsing.
void arguments_begin(hashtable* _arguments)
This function is used by ddos2_begin
. It initialises argument system.
void argument_add_compulsory(char* name, char* description, argtype type)
Creates argument that must be set unless help argument is set.
-
name
– Name of argument. E.g.--my-very-important-arg
-
description
– short description of what your argument does. -
type
– type of argument(ARG_BOOL
,ARG_INT
,ARG_STR
).
void argument_add(char* name, char* description, argtype type, argvalue _default, bool has_default_value, bool is_help)
-
name
– Name of argument. E.g.--my-very-important-arg
-
description
– short description of what your argument does. -
type
– type of argument(ARG_BOOL
,ARG_INT
,ARG_STR
). -
_default
– default value of an argument. If it there is no default value, use stub:argbool(false)
orargint(0)
-
has_default_value
– set to true if your function has default value -
is_help
– set to true if this argument should be hand
void argument_add_array(char* name, char* description, argtype type, bool compulsory)
-
name
– Name of argument. E.g.--my-very-important-arg
-
description
– short description of what your argument does. -
type
– type of argument(ARG_INT
orARG_STR
). -
_default
– default value of an argument. If it there is no default value, use stub:argbool(false)
orargint(0)
-
compulsory
– whether argument requires at least one value to be passed into arraybool argument_check(char *name)
Checks whether argument withname
was present. -
name
– name of the argument
argvalue argument_value_get(char *name)
Gets value of the argument with name
.
-
name
– name of the argument
argvalue argument_value_get_s(char *name, argtype type)
Gets value of argument and do check type of the argument. This function should be used while working with string arguments, so no pointer will lead to memory corruption.
-
name
– name of the argument -
type
– expected type of value returned
bool argument_check(char* name)
Checks that argument was supplied in the command line.
-
name
– name of the argument