update
This commit is contained in:
213
app.c
213
app.c
@@ -1,4 +1,5 @@
|
|||||||
#include "time.h"
|
#include "time.h"
|
||||||
|
#define DJSTD_BASIC_ENTRY
|
||||||
#include "djstdlib/core.c"
|
#include "djstdlib/core.c"
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
@@ -586,144 +587,84 @@ int32 cmd_dispatch(Arena *arena, StringList args, BasicCommandList cmds) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int djstd_entry(Arena *arena, StringList args) {
|
||||||
initialiseDjStdCore();
|
BasicCommandList cmds = AsList(BasicCommandList, {
|
||||||
Arena *arena = arenaAlloc(Megabytes(64));
|
|
||||||
StringList args = getArgs(arena, argc, argv);
|
|
||||||
|
|
||||||
CmdOptionArg cmdStatusOptArgs[] = {
|
|
||||||
{
|
{
|
||||||
.charName = '\0',
|
.name = s("status"),
|
||||||
.name = s("all"),
|
.description = s("Shows the currently recorded exercises. Default displays the current day."),
|
||||||
.description = s("Displays the full recorded history since day zero."),
|
.posArgs = EmptyList(),
|
||||||
.type = CmdArgType_BOOL
|
.optArgs = AsList(CmdOptionArgList, {
|
||||||
},
|
{
|
||||||
{
|
.charName = '\0',
|
||||||
.charName = 'd',
|
.name = s("all"),
|
||||||
.name = s("days"),
|
.description = s("Displays the full recorded history since day zero."),
|
||||||
.description = s("Displays the history for a previous number of days."),
|
.type = CmdArgType_BOOL
|
||||||
.type = CmdArgType_INT,
|
},
|
||||||
}
|
{
|
||||||
};
|
.charName = 'd',
|
||||||
BasicCommand cmdStatus = {
|
.name = s("days"),
|
||||||
.name = s("status"),
|
.description = s("Displays the history for a previous number of days."),
|
||||||
.description = s("Shows the currently recorded exercises. Default displays the current day."),
|
.type = CmdArgType_INT,
|
||||||
.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
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}),
|
||||||
|
.command = gymTrackerStatus,
|
||||||
if (icmd.optArgs.length > 0) {
|
},
|
||||||
print("\tOptions:\n");
|
{
|
||||||
}
|
.name = s("do"),
|
||||||
|
.description = s("Records an exercise with weight and reps"),
|
||||||
int statusCode = 0;
|
.posArgs = AsList(CmdPositionalArgList, {
|
||||||
|
{
|
||||||
if (statusCode == 0) {
|
.name = s("exercise"),
|
||||||
string cmd = args.data[0];
|
.type = CmdArgType_STRING,
|
||||||
list<string> argsRest = ListSlice(args, 1);
|
},
|
||||||
|
{
|
||||||
if (strEql(s("status"), cmd)) {
|
.name = s("weight"),
|
||||||
statusCode = gymTrackerStatus(arena, argsRest);
|
.description = s("Weight moved for one repetition"),
|
||||||
} else if (strEql(s("do"), cmd)) {
|
.type = CmdArgType_FLOAT,
|
||||||
statusCode = gymTrackerDo(arena, argsRest);
|
},
|
||||||
} else if (strEql(s("delete"), cmd)) {
|
{
|
||||||
statusCode = gymTrackerDeleteEntries(arena, argsRest);
|
.name = s("reps"),
|
||||||
} else if (strEql(s("list"), cmd)) {
|
.description = s("Number of repetitions performed"),
|
||||||
statusCode = gymTrackerListExercises(arena, argsRest);
|
.type = CmdArgType_INT,
|
||||||
} else if (strEql(s("add"), cmd)) {
|
}
|
||||||
statusCode = gymTrackerAddExercise(arena, argsRest);
|
}),
|
||||||
} else {
|
.optArgs = EmptyList(),
|
||||||
print("Unknown command \"%S\"\n", args.data[0]);
|
.command = gymTrackerDo,
|
||||||
statusCode = 1;
|
},
|
||||||
|
{
|
||||||
|
.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