From a8d7cd5a156b87fae5322817642b3ff939fd48c1 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Wed, 5 Aug 2020 16:39:55 +0200 Subject: [PATCH] HackStudio: Open project or file from argv[1] if given When HackStudio is invoked with one or more arguments it will attempt to treat the first argument as a project or source file and open it accordingly. --- DevTools/HackStudio/main.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/DevTools/HackStudio/main.cpp b/DevTools/HackStudio/main.cpp index 11888d7423..4177cd3adb 100644 --- a/DevTools/HackStudio/main.cpp +++ b/DevTools/HackStudio/main.cpp @@ -189,7 +189,14 @@ int main(int argc, char** argv) if (!make_is_available()) GUI::MessageBox::show(g_window, "The 'make' command is not available. You probably want to install the binutils, gcc, and make ports from the root of the Serenity repository.", "Error", GUI::MessageBox::Type::Error); - open_project("/home/anon/little/little.hackstudio"); + String argument_absolute_path; + if (argc >= 2) + argument_absolute_path = Core::File::real_path_for(argv[1]); + + if (!argument_absolute_path.is_empty() && argument_absolute_path.ends_with(".hackstudio")) + open_project(argument_absolute_path); + else + open_project("/home/anon/little/little.hackstudio"); auto& toolbar_container = widget.add(); auto& toolbar = toolbar_container.add(); @@ -684,7 +691,10 @@ int main(int argc, char** argv) g_open_file = open_file; - open_file(g_project->default_file()); + if (!argument_absolute_path.is_empty() && !argument_absolute_path.ends_with(".hackstudio")) + open_file(argument_absolute_path); + else + open_file(g_project->default_file()); update_actions(); return app->exec();