mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-28 23:39:02 +00:00
Shell: Add support for ARGV (and $*, $#)
This patchset also adds the 'shift' builtin, as well as the usual tests. closes #2948.
This commit is contained in:
parent
192b2383ac
commit
12af65c1c9
Notes:
sideshowbarker
2024-07-19 04:20:03 +09:00
Author: https://github.com/alimpfard
Commit: 12af65c1c9
Pull-request: https://github.com/SerenityOS/serenity/pull/2984
Issue: https://github.com/SerenityOS/serenity/issues/2948
Reviewed-by: https://github.com/awesomekling
8 changed files with 79 additions and 1 deletions
|
@ -159,12 +159,14 @@ int main(int argc, char** argv)
|
|||
|
||||
const char* command_to_run = nullptr;
|
||||
const char* file_to_read_from = nullptr;
|
||||
Vector<const char*> script_args;
|
||||
bool skip_rc_files = false;
|
||||
|
||||
Core::ArgsParser parser;
|
||||
parser.add_option(command_to_run, "String to read commands from", "command-string", 'c', "command-string");
|
||||
parser.add_positional_argument(file_to_read_from, "File to read commands from", "file", Core::ArgsParser::Required::No);
|
||||
parser.add_option(skip_rc_files, "Skip running shellrc files", "skip-shellrc", 0);
|
||||
parser.add_positional_argument(file_to_read_from, "File to read commands from", "file", Core::ArgsParser::Required::No);
|
||||
parser.add_positional_argument(script_args, "Extra argumets to pass to the script (via $* and co)", "argument", Core::ArgsParser::Required::No);
|
||||
|
||||
parser.parse(argc, argv);
|
||||
|
||||
|
@ -181,6 +183,13 @@ int main(int argc, char** argv)
|
|||
run_rc_file(Shell::local_init_file_path);
|
||||
}
|
||||
|
||||
{
|
||||
Vector<String> args;
|
||||
for (auto* arg : script_args)
|
||||
args.empend(arg);
|
||||
shell->set_local_variable("ARGV", *new AST::ListValue(move(args)));
|
||||
}
|
||||
|
||||
if (command_to_run) {
|
||||
dbgprintf("sh -c '%s'\n", command_to_run);
|
||||
shell->run_command(command_to_run);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue