summaryrefslogtreecommitdiff
path: root/Userland/Shell/Builtin.cpp
diff options
context:
space:
mode:
authorAli Mohammad Pur <ali.mpfard@gmail.com>2023-02-16 09:50:57 +0330
committerAli Mohammad Pur <Ali.mpfard@gmail.com>2023-02-18 06:55:46 +0330
commita5e4bc4fafc182c12384b71c724429426508777d (patch)
treee6762ca1fd6e8600ba7bc885c4a2e73d3ec1adcb /Userland/Shell/Builtin.cpp
parent4efc632e159f2bc27e989de7a0fdea965296649f (diff)
downloadserenity-a5e4bc4fafc182c12384b71c724429426508777d.zip
Shell: Add a '--posix' mode to the 'dump' builtin
Diffstat (limited to 'Userland/Shell/Builtin.cpp')
-rw-r--r--Userland/Shell/Builtin.cpp12
1 files 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 <AK/DeprecatedString.h>
#include <AK/LexicalPath.h>
@@ -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<char**>(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;
}