offset idx to accommodate point at which options occur
idx = objc
no options
gnocl::device
idx = 1
no subcommand but with options
gnocl::device -option AAA -option AAA...
idx = 2
subcommand with options
gnocl::device cmdName -option AAA -option AAA...
idx = 3
gnocl::device cmdName string -option AAA -option AAA...
gnoclParseCommandOptions
/**
\brief Command Template.
**/
int gnoclTemplateCmd ( ClientData data, Tcl_Interp *interp, int objc, Tcl_Obj * const objv[] )
{
static const char *description = "description";
static GnoclCommand commands[] = {
{ "cmdName", "args", "description", "default" },
{ NULL }
};
static GnoclOption options[] = {
/* command/widget specfic options */
{
"-option", GNOCL_STRING, NULL, NULL,
"default",
"description",
GNOCL_OPTIONS_IMAGE
},
{ NULL }
};
if ( gnoclGetDocumentation ( interp, objc, objv, description, commands, options ) == TCL_OK ) {
return TCL_OK;
}
enum cmdIdx { CmdNameIdx };
enum optIdx { OptIdx };
gint idx;
if ( gnoclParseCommandOptions ( interp, 2, objc, objv, options ) != TCL_OK ) {
gnoclClearOptions ( options );
return TCL_ERROR;
}
if ( Tcl_GetIndexFromObjStruct ( interp, objv[1], ( char ** ) &commands[0].cmdName, sizeof ( GnoclCommand ), "command", TCL_EXACT, &idx ) != TCL_OK ) {
return TCL_ERROR;
}
switch ( idx ) {
case CmdNameIdx: {
GNOCL_DEBUG_LINE
if ( options[OptIdx].status == GNOCL_STATUS_CHANGED ) {
GNOCL_DEBUG_MSG( "YAY! It's working!!!" )
GNOCL_DEBUG_MSG (options[OptIdx].val.str)
}
}; break;
case 1: {
GNOCL_DEBUG_LINE
}; break;
default: {
GNOCL_DEBUG_LINE
};
}
return TCL_OK;
}
Comments