Skip to content

Commit

Permalink
Add help documentation for sub-commands
Browse files Browse the repository at this point in the history
  • Loading branch information
bvisness committed Jan 3, 2024
1 parent f35fad2 commit 3ed7c32
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/tool/bundle.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ int bundle(int argc, char** argv)
Flag_Context c;
flag_init_context(&c);

flag_help(&c, "Packages a WebAssembly module into a standalone Orca application, along with any required assets.");

char** name = flag_str(&c, "n", "name", "out", "the app's name");
char** icon = flag_str(&c, "i", "icon", NULL, "an image file to use as the application's icon");
char** version = flag_str(&c, NULL, "version", "0.0.0", "a version number to embed in the application bundle");
Expand Down
17 changes: 17 additions & 0 deletions src/tool/flag.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ typedef struct

typedef struct
{
const char* help;

Flag flags[FLAGS_CAP];
size_t flags_count;
Flag_Positional positionals[FLAGS_CAP];
Expand All @@ -116,6 +118,7 @@ typedef struct

void flag_init_context(Flag_Context* c);
char* flag_name(void* val);
void flag_help(Flag_Context* c, const char* help);
bool* flag_bool(Flag_Context* c, const char* shortName, const char* longName, bool def, const char* desc);
uint64_t* flag_uint64(Flag_Context* c, const char* shortName, const char* longName, uint64_t def, const char* desc);
char** flag_str(Flag_Context* c, const char* shortName, const char* longName, const char* def, const char* desc);
Expand Down Expand Up @@ -171,6 +174,11 @@ char* flag_name(void* val)
return flag->longName;
}

void flag_help(Flag_Context* c, const char* help)
{
c->help = help;
}

bool* flag_bool(Flag_Context* c, const char* shortName, const char* longName, bool def, const char* desc)
{
Flag* flag = flag_new(c, FLAG_BOOL, shortName, longName, desc);
Expand Down Expand Up @@ -646,6 +654,15 @@ void flag_print_usage(Flag_Context* c, const char* cmd, FILE* f)
flag_wrap_fnewline(f, &w);
}

// Extra help
oc_str8 help = OC_STR8(c->help);
if(help.len > 0)
{
flag_wrap_fnewline(f, &w);
flag_wrap_fprint_autowrap(f, &w, a, help);
flag_wrap_fnewline(f, &w);
}

// Positional arguments
if(c->positionals_count > 0)
{
Expand Down
2 changes: 2 additions & 0 deletions src/tool/sdk_path.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ int sdkPath(int argc, char** argv)
Flag_Context c;
flag_init_context(&c);

flag_help(&c, "Prints the path to the installed Orca SDK. For use in scripts, e.g. `-I $(orca sdk-path)/src`.");

// TODO: version selection

if(!flag_parse(&c, argc, argv))
Expand Down

0 comments on commit 3ed7c32

Please sign in to comment.