From d320f7b9d2b6d97a7a54dcc63004473dff72df80 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Wed, 5 Aug 2020 20:17:02 +0200 Subject: [PATCH] Userland: Use Core::ArgsParser for 'tr' --- Userland/tr.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/Userland/tr.cpp b/Userland/tr.cpp index 6b5daa1020..22fb68ac15 100644 --- a/Userland/tr.cpp +++ b/Userland/tr.cpp @@ -27,18 +27,23 @@ #include #include #include +#include #include #include int main(int argc, char** argv) { - if (argc != 3) { - printf("usage: tr "); - return 0; - } + const char* from_chars = nullptr; + const char* to_chars = nullptr; - char from = argv[1][0]; - char to = argv[2][0]; + Core::ArgsParser args_parser; + args_parser.add_positional_argument(from_chars, "Character to translate from", "from"); + args_parser.add_positional_argument(to_chars, "Character to translate to", "to"); + args_parser.parse(argc, argv); + + // TODO: Support multiple characters to translate from and to + auto from = from_chars[0]; + auto to = to_chars[0]; for (;;) { char ch = fgetc(stdin);