diff options
author | Shav Kinderlehrer <[email protected]> | 2023-08-10 11:55:20 -0400 |
---|---|---|
committer | Shav Kinderlehrer <[email protected]> | 2023-08-10 11:55:20 -0400 |
commit | 36c8b4d2d776db3e1e4e84f6b0a8eb1f00f198d1 (patch) | |
tree | 103035b329b5f38bb8e175547031184f99b5180c | |
parent | 49768a38a7662dab13f2e6efa9561fbdcb06d83c (diff) | |
download | prim-36c8b4d2d776db3e1e4e84f6b0a8eb1f00f198d1.tar.gz prim-36c8b4d2d776db3e1e4e84f6b0a8eb1f00f198d1.zip |
Catch flag parse error
-rw-r--r-- | source/app.d | 48 |
1 files changed, 29 insertions, 19 deletions
diff --git a/source/app.d b/source/app.d index 4669b5d..76f64b5 100644 --- a/source/app.d +++ b/source/app.d @@ -19,33 +19,43 @@ Opts defaultOpts() { return opts; } +void printHelp(GetoptResult args) { + defaultGetoptPrinter("prim prompt:\n", args.options); + writeln("\nEnvironment:\n", + "\tNO_COLOR\tsee https://no-color.org"); +} + void main(string[] argv) { Opts opts = defaultOpts(); - GetoptResult args = getopt( - argv, - std.getopt.config.bundling, - "ps1|p", "print PS1", &opts.ps1, - "rps1|r", "print RPS1", &opts.rps1, - "preexec|x", "print preexec", &opts.preexec, + try { + + GetoptResult args = getopt( + argv, + std.getopt.config.bundling, + "ps1|p", "print PS1", &opts.ps1, + "rps1|r", "print RPS1", &opts.rps1, + "preexec|x", "print preexec", &opts.preexec, - std.getopt.config.required, - "col", "terminal width", &opts.col, + std.getopt.config.required, + "col", "terminal width", &opts.col, - std.getopt.config.required, - "row", "terminal height", &opts.row, + std.getopt.config.required, + "row", "terminal height", &opts.row, - std.getopt.config.required, - "status", "previous command exit code", &opts.status, + std.getopt.config.required, + "status", "previous command exit code", &opts.status, - "pathlen", "set length of displayed path", &opts.pathlen, - "pchar", "override default prompt character", &opts.pchar, - ); + "pathlen", "set length of displayed path", &opts.pathlen, + "pchar", "override default prompt character", &opts.pchar, + ); - if (args.helpWanted) { - defaultGetoptPrinter("prim prompt:\n", args.options); - writeln("\nEnvironment:\n", - "\tNO_COLOR\tsee https://no-color.org"); + if (args.helpWanted) { + printHelp(args); + } + } catch (Exception e) { + writeln(e.msg); + writeln("try '--help' for more information"); } dorun(opts); |