From a5e4bc4fafc182c12384b71c724429426508777d Mon Sep 17 00:00:00 2001 From: Ali Mohammad Pur Date: Thu, 16 Feb 2023 09:50:57 +0330 Subject: [PATCH] Shell: Add a '--posix' mode to the 'dump' builtin --- Userland/Shell/Builtin.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Userland/Shell/Builtin.cpp b/Userland/Shell/Builtin.cpp index 1c7268c938..ad9c03c7a0 100644 --- a/Userland/Shell/Builtin.cpp +++ b/Userland/Shell/Builtin.cpp @@ -6,6 +6,7 @@ #include "AST.h" #include "Formatter.h" +#include "PosixParser.h" #include "Shell.h" #include #include @@ -32,10 +33,17 @@ int Shell::builtin_noop(int, char const**) int Shell::builtin_dump(int argc, char const** argv) { - if (argc != 2) + bool posix = false; + StringView source; + + Core::ArgsParser parser; + parser.add_positional_argument(source, "Shell code to parse and dump", "source"); + parser.add_option(posix, "Use the POSIX parser", "posix", 'p'); + + if (!parser.parse(argc, const_cast(argv), Core::ArgsParser::FailureBehavior::PrintUsage)) return 1; - Parser { StringView { argv[1], strlen(argv[1]) } }.parse()->dump(0); + (posix ? Posix::Parser { source }.parse() : Parser { source }.parse())->dump(0); return 0; }