Skip to content

Commit 3475adf

Browse files
committed
Fixed: Bug where invalid arguments were silently returned
1 parent 03eda61 commit 3475adf

File tree

2 files changed

+69
-45
lines changed

2 files changed

+69
-45
lines changed

source/app.d

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ string formatError(string err)
3737
*/
3838
int main(string[] args)
3939
{
40+
import std.getopt;
4041
try
4142
{
4243
if(args.length == 1)
@@ -105,6 +106,15 @@ int main(string[] args)
105106
version(Developer) throw e;
106107
return 1;
107108
}
109+
catch(GetOptException e)
110+
{
111+
import std.stdio;
112+
setLogLevel(LogLevel.error);
113+
errorTitle("Argument Error: ", e.msg);
114+
writeln(getHelpInfo);
115+
version(Developer) throw e;
116+
return 1;
117+
}
108118
catch(Exception e)
109119
{
110120
errorTitle("Internal Error: ", e.msg);

source/redub/api.d

Lines changed: 59 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -566,51 +566,7 @@ ArgsDetails resolveArguments(string[] args, bool isDescribeOnly = false)
566566
if(res.helpWanted)
567567
{
568568
import std.getopt;
569-
string newCommands =
570-
`
571-
USAGE: redub [--version] [<command>] [<options...>] [-- [<application arguments...>]]
572-
573-
Manages the redub project in the current directory. If the command is omitted,
574-
redub will default to "run". When running an application, "--" can be used to
575-
separate redub options from options passed to the application.
576-
577-
Run "redub <command> --help" to get help for a specific command.
578-
579-
Available commands
580-
==================
581-
582-
Package creation
583-
----------------
584-
init [<directory> [<dependency>...]]
585-
Initializes an empty package skeleton
586-
587-
Build, test and run
588-
-------------------
589-
run [<package>[@<version-spec>]]
590-
Builds and runs a package (default command)
591-
build [<package>[@<version-spec>]]
592-
Builds a package (uses the main package in the current
593-
working directory by default)
594-
test [<package>[@<version-spec>]]
595-
Executes the tests of the selected package
596-
describe [<package>[@<version-spec>]]
597-
Prints a description of the specified --data files
598-
clean [<package>] Removes intermediate build files and cached build
599-
results
600-
601-
Additions to redub commands --
602-
603-
update
604-
Usage: redub update
605-
Description: Updates with 'git pull' redub if the current redub is a git repository. If it is not, it will download the newest git tag from redub
606-
repository. After updating the source, it will also optimally rebuild redub and replace the current one with the new build.
607-
build-universal
608-
Usage: redub build-universal
609-
Description:
610-
Builds a package in non OSX (uses the main package in the current working directory by default)
611-
On OSX, generates a single binary using arm64 and x86_64 architectures
612-
`;
613-
defaultGetoptPrinter(RedubVersionShort~" build information: \n\t"~newCommands, res.options);
569+
defaultGetoptPrinter(RedubVersionShort~" build information: \n\t"~baseHelpInfo, res.options);
614570
return ArgsDetails.init;
615571
}
616572

@@ -926,4 +882,62 @@ private string getSubPackage(ref string pkg)
926882
string ret = pkg[subPackIndex+1..$];
927883
pkg = pkg[0..subPackIndex];
928884
return ret;
885+
}
886+
887+
immutable baseHelpInfo =
888+
`
889+
USAGE: redub [--version] [<command>] [<options...>] [-- [<application arguments...>]]
890+
891+
Manages the redub project in the current directory. If the command is omitted,
892+
redub will default to "run". When running an application, "--" can be used to
893+
separate redub options from options passed to the application.
894+
895+
Run "redub <command> --help" to get help for a specific command.
896+
897+
Available commands
898+
==================
899+
900+
Package creation
901+
----------------
902+
init [<directory> [<dependency>...]]
903+
Initializes an empty package skeleton
904+
905+
Build, test and run
906+
-------------------
907+
run [<package>[@<version-spec>]]
908+
Builds and runs a package (default command)
909+
build [<package>[@<version-spec>]]
910+
Builds a package (uses the main package in the current
911+
working directory by default)
912+
test [<package>[@<version-spec>]]
913+
Executes the tests of the selected package
914+
describe [<package>[@<version-spec>]]
915+
Prints a description of the specified --data files
916+
clean [<package>] Removes intermediate build files and cached build
917+
results
918+
919+
Additions to redub commands --
920+
921+
update
922+
Usage: redub update
923+
Description: Updates with 'git pull' redub if the current redub is a git repository. If it is not, it will download the newest git tag from redub
924+
repository. After updating the source, it will also optimally rebuild redub and replace the current one with the new build.
925+
build-universal
926+
Usage: redub build-universal
927+
Description:
928+
Builds a package in non OSX (uses the main package in the current working directory by default)
929+
On OSX, generates a single binary using arm64 and x86_64 architectures
930+
`;
931+
932+
string getHelpInfo()
933+
{
934+
import std.getopt;
935+
import std.array;
936+
string[2] fakeArgs;
937+
string[] args = fakeArgs;
938+
DubArguments dub;
939+
GetoptResult res = betterGetopt(args, dub);
940+
Appender!string ret;
941+
defaultGetoptFormatter(&ret, RedubVersionShort~" build information: \n\t"~baseHelpInfo, res.options);
942+
return ret.data;
929943
}

0 commit comments

Comments
 (0)