Skip to content

Commit

Permalink
Support -h/--help for all programs (#1620)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rangi42 authored Jan 22, 2025
1 parent 157826b commit d9654b7
Show file tree
Hide file tree
Showing 16 changed files with 54 additions and 20 deletions.
1 change: 1 addition & 0 deletions contrib/bash_compl/_rgbasm.bash
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ _rgbasm_completions() {
# See the `state` variable below for info about `state_after`
declare -A opts=(
[V]="version:normal"
[h]="help:normal"
[E]="export-all:normal"
[v]="verbose:normal"
[w]=":normal"
Expand Down
1 change: 1 addition & 0 deletions contrib/bash_compl/_rgbfix.bash
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ _rgbfix_completions() {
# See the `state` variable below for info about `state_after`
declare -A opts=(
[V]="version:normal"
[h]="help:normal"
[j]="non-japanese:normal"
[s]="sgb-compatible:normal"
[v]="validate:normal"
Expand Down
1 change: 1 addition & 0 deletions contrib/bash_compl/_rgbgfx.bash
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ _rgbgfx_completions() {
# See the `state` variable below for info about `state_after`
declare -A opts=(
[V]="version:normal"
[h]="help:normal"
[C]="color-curve:normal"
[m]="mirror-tiles:normal"
[O]="group-outputs:normal"
Expand Down
1 change: 1 addition & 0 deletions contrib/bash_compl/_rgblink.bash
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ _rgblink_completions() {
# See the `state` variable below for info about `state_after`
declare -A opts=(
[V]="version:normal"
[h]="help:normal"
[d]="dmg:normal"
[t]="tiny:normal"
[v]="verbose:normal"
Expand Down
5 changes: 3 additions & 2 deletions contrib/zsh_compl/_rgbasm
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ _rgbasm_warnings() {
}

local args=(
# Arguments are listed here in the same order as in the manual, except for the version
'(- : * options)'{-V,--version}'[Print version number]'
# Arguments are listed here in the same order as in the manual, except for the version and help
'(- : * options)'{-V,--version}'[Print version number and exit]'
'(- : * options)'{-h,--help}'[Print help text and exit]'

'(-E --export-all)'{-E,--export-all}'[Export all symbols]'
'(-v --verbose)'{-v,--verbose}'[Print additional messages regarding progression]'
Expand Down
5 changes: 3 additions & 2 deletions contrib/zsh_compl/_rgbfix
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ _mbc_names() {
}

local args=(
# Arguments are listed here in the same order as in the manual, except for the version
'(- : * options)'{-V,--version}'[Print version number]'
# Arguments are listed here in the same order as in the manual, except for the version and help
'(- : * options)'{-V,--version}'[Print version number and exit]'
'(- : * options)'{-h,--help}'[Print help text and exit]'

'(-C --color-only -c --color-compatible)'{-C,--color-only}'[Mark ROM as GBC-only]'
'(-C --color-only -c --color-compatible)'{-c,--color-compatible}'[Mark ROM as GBC-compatible]'
Expand Down
5 changes: 3 additions & 2 deletions contrib/zsh_compl/_rgbgfx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ _depths() {
}

local args=(
# Arguments are listed here in the same order as in the manual, except for the version
'(- : * options)'{-V,--version}'[Print version number]'
# Arguments are listed here in the same order as in the manual, except for the version and help
'(- : * options)'{-V,--version}'[Print version number and exit]'
'(- : * options)'{-h,--help}'[Print help text and exit]'

'(-a --attr-map -A --auto-attr-map)'{-A,--auto-attr-map}'[Shortcut for -a <file>.attrmap]'
'(-C --color-curve)'{-C,--color-curve}'[Generate palettes using GBC color curve]'
Expand Down
5 changes: 3 additions & 2 deletions contrib/zsh_compl/_rgblink
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#compdef rgblink

local args=(
# Arguments are listed here in the same order as in the manual, except for the version
'(- : * options)'{-V,--version}'[Print version number]'
# Arguments are listed here in the same order as in the manual, except for the version and help
'(- : * options)'{-V,--version}'[Print version number and exit]'
'(- : * options)'{-h,--help}'[Print help text and exit]'

'(-d --dmg)'{-d,--dmg}'[Enable DMG mode (-w + no VRAM banking)]'
'(-t --tiny)'{-t,--tiny}'[Enable tiny mode, disabling ROM banking]'
Expand Down
4 changes: 3 additions & 1 deletion man/rgbasm.1
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
.Nd Game Boy assembler
.Sh SYNOPSIS
.Nm
.Op Fl EVvw
.Op Fl EhVvw
.Op Fl b Ar chars
.Op Fl D Ar name Ns Op = Ns Ar value
.Op Fl g Ar chars
Expand Down Expand Up @@ -67,6 +67,8 @@ Export all labels, including unreferenced and local labels.
.It Fl g Ar chars , Fl \-gfx-chars Ar chars
Change the four characters used for gfx constants.
The defaults are 0123.
.It Fl h , Fl \-help
Print help text for the program and exit.
.It Fl I Ar path , Fl \-include Ar path
Add a new
.Dq include path ;
Expand Down
4 changes: 3 additions & 1 deletion man/rgbfix.1
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
.Nd Game Boy header utility and checksum fixer
.Sh SYNOPSIS
.Nm
.Op Fl jOsVv
.Op Fl hjOsVv
.Op Fl C | c
.Op Fl f Ar fix_spec
.Op Fl i Ar game_id
Expand Down Expand Up @@ -91,6 +91,8 @@ Fix the global checksum
.It Cm G
Trash the global checksum.
.El
.It Fl h , Fl \-help
Print help text for the program and exit.
.It Fl i Ar game_id , Fl \-game-id Ar game_id
Set the game ID string
.Pq Ad 0x13F Ns \(en Ns Ad 0x142
Expand Down
4 changes: 3 additions & 1 deletion man/rgbgfx.1
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
.Nd Game Boy graphics converter
.Sh SYNOPSIS
.Nm
.Op Fl CmOuVXYZ
.Op Fl CmhOuVXYZ
.Op Fl v Op Fl v No ...
.Op Fl a Ar attrmap | Fl A
.Op Fl b Ar base_ids
Expand Down Expand Up @@ -165,6 +165,8 @@ for a list of formats and their descriptions.
.It Fl d Ar depth , Fl \-depth Ar depth
Set the bit depth of the output tile data, in bits per pixel (bpp), either 1 or 2 (the default).
This changes how tile data is output, and the maximum number of colors per palette (2 and 4 respectively).
.It Fl h , Fl \-help
Print help text for the program and exit.
.It Fl i Ar input_tiles , Fl \-input-tileset Ar input_tiles
Use the specified input tiles in addition to having
.Nm
Expand Down
4 changes: 3 additions & 1 deletion man/rgblink.1
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
.Nd Game Boy linker
.Sh SYNOPSIS
.Nm
.Op Fl dMtVvwx
.Op Fl dhMtVvwx
.Op Fl l Ar linker_script
.Op Fl m Ar map_file
.Op Fl n Ar sym_file
Expand Down Expand Up @@ -67,6 +67,8 @@ Enable DMG mode.
Prohibit the use of sections that doesn't exist on a DMG, such as VRAM bank 1.
This option automatically enables
.Fl w .
.It Fl h , Fl \-help
Print help text for the program and exit.
.It Fl l Ar linker_script , Fl \-linkerscript Ar linker_script
Specify a linker script file that tells the linker how sections must be placed in the ROM.
The attributes assigned in the linker script must be consistent with any assigned in the code.
Expand Down
9 changes: 7 additions & 2 deletions src/asm/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ static std::string make_escape(std::string &str) {
}

// Short options
static char const *optstring = "b:D:Eg:I:M:o:P:p:Q:r:s:VvW:wX:";
static char const *optstring = "b:D:Eg:hI:M:o:P:p:Q:r:s:VvW:wX:";

// Variables for the long-only options
static int depType; // Variants of `-M`
Expand All @@ -69,6 +69,7 @@ static option const longopts[] = {
{"include", required_argument, nullptr, 'I'},
{"dependfile", required_argument, nullptr, 'M'},
{"MG", no_argument, &depType, 'G'},
{"help", no_argument, nullptr, 'h'},
{"MP", no_argument, &depType, 'P'},
{"MT", required_argument, &depType, 'T'},
{"warning", required_argument, nullptr, 'W'},
Expand All @@ -88,7 +89,7 @@ static option const longopts[] = {

static void printUsage() {
fputs(
"Usage: rgbasm [-EVvw] [-b chars] [-D name[=value]] [-g chars] [-I path]\n"
"Usage: rgbasm [-EhVvw] [-b chars] [-D name[=value]] [-g chars] [-I path]\n"
" [-M depend_file] [-MG] [-MP] [-MT target_file] [-MQ target_file]\n"
" [-o out_file] [-P include_file] [-p pad_value] [-Q precision]\n"
" [-r depth] [-s features:state_file] [-W warning] [-X max_errors]\n"
Expand Down Expand Up @@ -169,6 +170,10 @@ int main(int argc, char *argv[]) {
errx("Must specify exactly 4 characters for option 'g'");
break;

case 'h':
printUsage();
exit(0);

case 'I':
fstk_AddIncludePath(musl_optarg);
break;
Expand Down
9 changes: 7 additions & 2 deletions src/fix/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ static_assert(UNSPECIFIED > 0xFF, "UNSPECIFIED should not be in byte range!");
static constexpr off_t BANK_SIZE = 0x4000;

// Short options
static char const *optstring = "Ccf:i:jk:L:l:m:n:Op:r:st:Vv";
static char const *optstring = "Ccf:hi:jk:L:l:m:n:Op:r:st:Vv";

/*
* Equivalent long options
Expand All @@ -39,6 +39,7 @@ static option const longopts[] = {
{"color-only", no_argument, nullptr, 'C'},
{"color-compatible", no_argument, nullptr, 'c'},
{"fix-spec", required_argument, nullptr, 'f'},
{"help", no_argument, nullptr, 'h'},
{"game-id", required_argument, nullptr, 'i'},
{"non-japanese", no_argument, nullptr, 'j'},
{"new-licensee", required_argument, nullptr, 'k'},
Expand All @@ -58,7 +59,7 @@ static option const longopts[] = {

static void printUsage() {
fputs(
"Usage: rgbfix [-jOsVv] [-C | -c] [-f <fix_spec>] [-i <game_id>] [-k <licensee>]\n"
"Usage: rgbfix [-hjOsVv] [-C | -c] [-f <fix_spec>] [-i <game_id>] [-k <licensee>]\n"
" [-L <logo_file>] [-l <licensee_byte>] [-m <mbc_type>]\n"
" [-n <rom_version>] [-p <pad_value>] [-r <ram_size>] [-t <title_str>]\n"
" <file> ...\n"
Expand Down Expand Up @@ -1281,6 +1282,10 @@ int main(int argc, char *argv[]) {
}
break;

case 'h':
printUsage();
exit(0);

case 'i':
gameID = musl_optarg;
len = strlen(gameID);
Expand Down
8 changes: 6 additions & 2 deletions src/gfx/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void Options::verbosePrint(uint8_t level, char const *fmt, ...) const {
}

// Short options
static char const *optstring = "-Aa:b:Cc:d:i:L:mN:n:Oo:Pp:Qq:r:s:Tt:U:uVvXx:YZ";
static char const *optstring = "-Aa:b:Cc:d:hi:L:mN:n:Oo:Pp:Qq:r:s:Tt:U:uVvXx:YZ";

/*
* Equivalent long options
Expand All @@ -127,6 +127,7 @@ static option const longopts[] = {
{"color-curve", no_argument, nullptr, 'C'},
{"colors", required_argument, nullptr, 'c'},
{"depth", required_argument, nullptr, 'd'},
{"help", no_argument, nullptr, 'h'},
{"input-tileset", required_argument, nullptr, 'i'},
{"slice", required_argument, nullptr, 'L'},
{"mirror-tiles", no_argument, nullptr, 'm'},
Expand Down Expand Up @@ -155,7 +156,7 @@ static option const longopts[] = {

static void printUsage() {
fputs(
"Usage: rgbgfx [-r stride] [-CmOuVXYZ] [-v [-v ...]] [-a <attr_map> | -A]\n"
"Usage: rgbgfx [-r stride] [-ChmOuVXYZ] [-v [-v ...]] [-a <attr_map> | -A]\n"
" [-b <base_ids>] [-c <colors>] [-d <depth>] [-i <tileset_file>]\n"
" [-L <slice>] [-N <nb_tiles>] [-n <nb_pals>] [-o <out_file>]\n"
" [-p <pal_file> | -P] [-q <pal_map> | -Q] [-s <nb_colors>]\n"
Expand Down Expand Up @@ -430,6 +431,9 @@ static char *parseArgv(int argc, char *argv[]) {
options.bitDepth = 2;
}
break;
case 'h':
printUsage();
exit(0);
case 'i':
if (!options.inputTileset.empty())
warning("Overriding input tileset file %s", options.inputTileset.c_str());
Expand Down
8 changes: 6 additions & 2 deletions src/link/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ void argErr(char flag, char const *fmt, ...) {
}

// Short options
static char const *optstring = "dl:m:Mn:O:o:p:S:tVvWwx";
static char const *optstring = "dhl:m:Mn:O:o:p:S:tVvWwx";

/*
* Equivalent long options
Expand All @@ -144,6 +144,7 @@ static char const *optstring = "dl:m:Mn:O:o:p:S:tVvWwx";
*/
static option const longopts[] = {
{"dmg", no_argument, nullptr, 'd'},
{"help", no_argument, nullptr, 'h'},
{"linkerscript", required_argument, nullptr, 'l'},
{"map", required_argument, nullptr, 'm'},
{"no-sym-in-map", no_argument, nullptr, 'M'},
Expand All @@ -162,7 +163,7 @@ static option const longopts[] = {

static void printUsage() {
fputs(
"Usage: rgblink [-dMtVvwx] [-l script] [-m map_file] [-n sym_file]\n"
"Usage: rgblink [-dhMtVvwx] [-l script] [-m map_file] [-n sym_file]\n"
" [-O overlay_file] [-o out_file] [-p pad_value]\n"
" [-S spec] <file> ...\n"
"Useful options:\n"
Expand Down Expand Up @@ -327,6 +328,9 @@ int main(int argc, char *argv[]) {
isDmgMode = true;
isWRAM0Mode = true;
break;
case 'h':
printUsage();
exit(0);
case 'l':
if (linkerScriptName)
warnx("Overriding linker script %s", linkerScriptName);
Expand Down

0 comments on commit d9654b7

Please sign in to comment.