update
This commit is contained in:
213
app.c
213
app.c
@@ -1,4 +1,5 @@
|
||||
#include "time.h"
|
||||
#define DJSTD_BASIC_ENTRY
|
||||
#include "djstdlib/core.c"
|
||||
|
||||
typedef enum {
|
||||
@@ -586,144 +587,84 @@ int32 cmd_dispatch(Arena *arena, StringList args, BasicCommandList cmds) {
|
||||
return result;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
initialiseDjStdCore();
|
||||
Arena *arena = arenaAlloc(Megabytes(64));
|
||||
StringList args = getArgs(arena, argc, argv);
|
||||
|
||||
CmdOptionArg cmdStatusOptArgs[] = {
|
||||
int djstd_entry(Arena *arena, StringList args) {
|
||||
BasicCommandList cmds = AsList(BasicCommandList, {
|
||||
{
|
||||
.charName = '\0',
|
||||
.name = s("all"),
|
||||
.description = s("Displays the full recorded history since day zero."),
|
||||
.type = CmdArgType_BOOL
|
||||
},
|
||||
{
|
||||
.charName = 'd',
|
||||
.name = s("days"),
|
||||
.description = s("Displays the history for a previous number of days."),
|
||||
.type = CmdArgType_INT,
|
||||
}
|
||||
};
|
||||
BasicCommand cmdStatus = {
|
||||
.name = s("status"),
|
||||
.description = s("Shows the currently recorded exercises. Default displays the current day."),
|
||||
.posArgs = EmptyList(CmdPositionalArgList),
|
||||
.optArgs = ArrayAsList(CmdOptionArgList, cmdStatusOptArgs),
|
||||
.command = gymTrackerStatus,
|
||||
};
|
||||
|
||||
CmdPositionalArg cmdDoPosArgs[] = {
|
||||
{
|
||||
.name = s("exercise"),
|
||||
.type = CmdArgType_STRING,
|
||||
},
|
||||
{
|
||||
.name = s("weight"),
|
||||
.description = s("Weight moved for one repetition"),
|
||||
.type = CmdArgType_FLOAT,
|
||||
},
|
||||
{
|
||||
.name = s("reps"),
|
||||
.description = s("Number of repetitions performed"),
|
||||
.type = CmdArgType_INT,
|
||||
}
|
||||
};
|
||||
BasicCommand cmdDo = {
|
||||
.name = s("do"),
|
||||
.description = s("Records an exercise with weight and reps"),
|
||||
.posArgs = ArrayAsList(CmdPositionalArgList, cmdDoPosArgs),
|
||||
.optArgs = EmptyList(CmdOptionArgList),
|
||||
.command = gymTrackerDo,
|
||||
};
|
||||
|
||||
CmdPositionalArg cmdDeletePosArgs[] = {
|
||||
{
|
||||
.name = s("count"),
|
||||
.description = s("The number of entries to pop off the end of the record."),
|
||||
.type = CmdArgType_INT,
|
||||
}
|
||||
};
|
||||
BasicCommand cmdDelete = {
|
||||
.name = s("delete"),
|
||||
.description = s("Deletes the last given number of entries."),
|
||||
.posArgs = ArrayAsList(CmdPositionalArgList, cmdDeletePosArgs),
|
||||
.optArgs = EmptyList(CmdOptionArgList),
|
||||
.command = gymTrackerDeleteEntries,
|
||||
};
|
||||
|
||||
BasicCommand cmdList = {
|
||||
.name = s("list"),
|
||||
.description = s("Lists all available exercises in the database."),
|
||||
.posArgs = EmptyList(CmdPositionalArgList),
|
||||
.optArgs = EmptyList(CmdOptionArgList),
|
||||
.command = gymTrackerListExercises,
|
||||
};
|
||||
|
||||
CmdPositionalArg cmdAddPosArgs[] = {
|
||||
{
|
||||
.name = s("name"),
|
||||
.description = s("The name of the exercise to be added."),
|
||||
.type = CmdArgType_STRING,
|
||||
},
|
||||
};
|
||||
BasicCommand cmdAdd = {
|
||||
.name = s("add"),
|
||||
.description = s("Adds a new exercise name to the database."),
|
||||
.posArgs = ArrayAsList(CmdPositionalArgList, cmdAddPosArgs),
|
||||
.optArgs = EmptyList(CmdOptionArgList),
|
||||
.command = gymTrackerAddExercise,
|
||||
};
|
||||
|
||||
BasicCommand commands[] = {
|
||||
cmdStatus,
|
||||
cmdDo,
|
||||
cmdDelete,
|
||||
cmdList,
|
||||
cmdAdd,
|
||||
};
|
||||
|
||||
return cmd_dispatch(arena, args, ArrayAsList(BasicCommandList, commands));
|
||||
|
||||
/*
|
||||
if (icmd.posArgs.length > 0) {
|
||||
print("\tPositional arguments:\n");
|
||||
for (EachIn(icmd.posArgs, j)) {
|
||||
CmdPositionalArg arg = icmd.posArgs.data[j];
|
||||
print("\t- %S: (%S) %S\n",
|
||||
arg.name,
|
||||
cmdArgTypeFmt(arg.type),
|
||||
arg.description
|
||||
);
|
||||
.name = s("status"),
|
||||
.description = s("Shows the currently recorded exercises. Default displays the current day."),
|
||||
.posArgs = EmptyList(),
|
||||
.optArgs = AsList(CmdOptionArgList, {
|
||||
{
|
||||
.charName = '\0',
|
||||
.name = s("all"),
|
||||
.description = s("Displays the full recorded history since day zero."),
|
||||
.type = CmdArgType_BOOL
|
||||
},
|
||||
{
|
||||
.charName = 'd',
|
||||
.name = s("days"),
|
||||
.description = s("Displays the history for a previous number of days."),
|
||||
.type = CmdArgType_INT,
|
||||
}
|
||||
}
|
||||
|
||||
if (icmd.optArgs.length > 0) {
|
||||
print("\tOptions:\n");
|
||||
}
|
||||
|
||||
int statusCode = 0;
|
||||
|
||||
if (statusCode == 0) {
|
||||
string cmd = args.data[0];
|
||||
list<string> argsRest = ListSlice(args, 1);
|
||||
|
||||
if (strEql(s("status"), cmd)) {
|
||||
statusCode = gymTrackerStatus(arena, argsRest);
|
||||
} else if (strEql(s("do"), cmd)) {
|
||||
statusCode = gymTrackerDo(arena, argsRest);
|
||||
} else if (strEql(s("delete"), cmd)) {
|
||||
statusCode = gymTrackerDeleteEntries(arena, argsRest);
|
||||
} else if (strEql(s("list"), cmd)) {
|
||||
statusCode = gymTrackerListExercises(arena, argsRest);
|
||||
} else if (strEql(s("add"), cmd)) {
|
||||
statusCode = gymTrackerAddExercise(arena, argsRest);
|
||||
} else {
|
||||
print("Unknown command \"%S\"\n", args.data[0]);
|
||||
statusCode = 1;
|
||||
}),
|
||||
.command = gymTrackerStatus,
|
||||
},
|
||||
{
|
||||
.name = s("do"),
|
||||
.description = s("Records an exercise with weight and reps"),
|
||||
.posArgs = AsList(CmdPositionalArgList, {
|
||||
{
|
||||
.name = s("exercise"),
|
||||
.type = CmdArgType_STRING,
|
||||
},
|
||||
{
|
||||
.name = s("weight"),
|
||||
.description = s("Weight moved for one repetition"),
|
||||
.type = CmdArgType_FLOAT,
|
||||
},
|
||||
{
|
||||
.name = s("reps"),
|
||||
.description = s("Number of repetitions performed"),
|
||||
.type = CmdArgType_INT,
|
||||
}
|
||||
}),
|
||||
.optArgs = EmptyList(),
|
||||
.command = gymTrackerDo,
|
||||
},
|
||||
{
|
||||
.name = s("delete"),
|
||||
.description = s("Deletes the last given number of entries."),
|
||||
.posArgs = AsList(CmdPositionalArgList, {
|
||||
{
|
||||
.name = s("count"),
|
||||
.description = s("The number of entries to pop off the end of the record."),
|
||||
.type = CmdArgType_INT,
|
||||
}
|
||||
}),
|
||||
.optArgs = EmptyList(),
|
||||
.command = gymTrackerDeleteEntries,
|
||||
},
|
||||
{
|
||||
.name = s("list"),
|
||||
.description = s("Lists all available exercises in the database."),
|
||||
.posArgs = EmptyList(),
|
||||
.optArgs = EmptyList(),
|
||||
.command = gymTrackerListExercises,
|
||||
},
|
||||
{
|
||||
.name = s("add"),
|
||||
.description = s("Adds a new exercise name to the database."),
|
||||
.posArgs = AsList(CmdPositionalArgList, {
|
||||
{
|
||||
.name = s("name"),
|
||||
.description = s("The name of the exercise to be added."),
|
||||
.type = CmdArgType_STRING,
|
||||
},
|
||||
}),
|
||||
.optArgs = EmptyList(),
|
||||
.command = gymTrackerAddExercise,
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return statusCode;
|
||||
*/
|
||||
return cmd_dispatch(arena, args, cmds);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user