diff options
author | Shav Kinderlehrer <[email protected]> | 2023-08-09 13:57:38 -0400 |
---|---|---|
committer | Shav Kinderlehrer <[email protected]> | 2023-08-09 13:57:38 -0400 |
commit | dd5c94c3174cc0fee0cbae4b51d47589894d0e5d (patch) | |
tree | 47c03401b4ca55e8fb4ad75db8f712361aa77c9b /source | |
parent | dfb28899ade840bad0fd24ec636cff65b1b58821 (diff) | |
download | prim-dd5c94c3174cc0fee0cbae4b51d47589894d0e5d.tar.gz prim-dd5c94c3174cc0fee0cbae4b51d47589894d0e5d.zip |
Add getopt
Diffstat (limited to 'source')
-rw-r--r-- | source/app.d | 42 | ||||
-rw-r--r-- | source/prompt/ps1.d | 11 |
2 files changed, 50 insertions, 3 deletions
diff --git a/source/app.d b/source/app.d index c3eec7f..25bb8e9 100644 --- a/source/app.d +++ b/source/app.d @@ -1,6 +1,42 @@ import std.stdio; +import std.getopt; -void main() -{ - writeln("Edit source/app.d to start your project."); +import prompt.ps1; + +struct Opt { + bool ps1; + bool rps1; + + int col; + int row; +} + +void validate(Opt opts) { + if (!opts.col || !opts.row) + throw new Exception("--col and --row required"); +} + +void main(string[] argv) { + Opt opts; + + GetoptResult args = getopt( + argv, + std.getopt.config.bundling, + "ps1|p", "print PS1", &opts.ps1, + "rps1|r", "print RPS1", &opts.rps1, + "col", "terminal width", &opts.col, + "row", "terminal height", &opts.row, + ); + + if (args.helpWanted) { + defaultGetoptPrinter("prim", args.options); + } + + try { + validate(opts); + } catch (Exception e) { + defaultGetoptPrinter(e.msg ~ "\n", args.options); + } + + ps1(opts.col).write(); } diff --git a/source/prompt/ps1.d b/source/prompt/ps1.d new file mode 100644 index 0000000..338afe8 --- /dev/null +++ b/source/prompt/ps1.d @@ -0,0 +1,11 @@ +module prompt.ps1; + +string ps1(int col) { + string ps; + + foreach (i; 0 .. col) { + ps ~= '—'; + } + + return ps; +} |