From f78733fec9a19c57713cd9817ef3b56f8a1b5000 Mon Sep 17 00:00:00 2001 From: Sergey Rubanov Date: Mon, 25 Sep 2023 22:42:17 +0200 Subject: [PATCH] feat(src/cli/cli.cc): add --name option to ssc init --- src/cli/cli.cc | 13 +++++++++++-- src/cli/templates.hh | 21 +++++++++++---------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/cli/cli.cc b/src/cli/cli.cc index f131fc42d5..e04471fd5d 100644 --- a/src/cli/cli.cc +++ b/src/cli/cli.cc @@ -1806,7 +1806,10 @@ optionsAndEnv parseCommandLineOptions ( } int main (const int argc, const char* argv[]) { - defaultTemplateAttrs = {{ "ssc_version", SSC::VERSION_FULL_STRING }}; + defaultTemplateAttrs = { + { "ssc_version", SSC::VERSION_FULL_STRING }, + { "project_name", "beepboop" } + }; if (argc < 2) { printHelp("ssc"); exit(0); @@ -2139,14 +2142,20 @@ int main (const int argc, const char* argv[]) { // first flag indicating whether option is optional // second flag indicating whether option should be followed by a value Options initOptions = { - { { "--config" }, true, false } + { { "--config" }, true, false }, + { { "--name" }, true, true } }; createSubcommand("init", initOptions, false, [&](Map optionsWithValue, std::unordered_set optionsWithoutValue) -> void { auto isCurrentPathEmpty = fs::is_empty(fs::current_path()); auto configOnly = optionsWithoutValue.find("--config") != optionsWithoutValue.end(); + auto projectName = optionsWithValue["--name"]; + if (fs::exists(targetPath / "socket.ini")) { log("socket.ini already exists in " + targetPath.string()); } else { + if (projectName.size() > 0) { + defaultTemplateAttrs["project_name"] = projectName; + } SSC::writeFile(targetPath / "socket.ini", tmpl(gDefaultConfig, defaultTemplateAttrs)); log("socket.ini created in " + targetPath.string()); } diff --git a/src/cli/templates.hh b/src/cli/templates.hh index 17b3bd656c..7c5a82cebb 100644 --- a/src/cli/templates.hh +++ b/src/cli/templates.hh @@ -79,6 +79,7 @@ usage: options: --config only create the config file + --name project name )TEXT"; constexpr auto gHelpTextInstallApp = R"TEXT( @@ -1406,7 +1407,7 @@ flags = -O3 headless = false ; The name of the program and executable to be output. Can't contain spaces or special characters. Required field. -name = "beepboop" +name = "{{project_name}}" ; The binary output path. It's recommended to add this path to .gitignore. ; default value: "build" @@ -1440,13 +1441,13 @@ flags = "-g" ; A unique ID that identifies the bundle (used by all app stores). ; It's required when `[meta] type` is not `"extension"`. ; It should be in a reverse DNS notation https://developer.apple.com/documentation/bundleresources/information_property_list/cfbundleidentifier#discussion -bundle_identifier = "com.beepboop" +bundle_identifier = "com.{{project_name}}" ; A string that gets used in the about dialog and package meta info. -copyright = "(c) Beep Boop Corp. 1985" +; copyright = "(c) Beep Boop Corp. 1985" ; A short description of the app. -description = "A UI for the beep boop network" +; description = "A UI for the beep boop network" ; Set the limit of files that can be opened by your process. file_limit = 1024 @@ -1455,10 +1456,10 @@ file_limit = 1024 lang = "en-us" ; A String used in the about dialog and meta info. -maintainer = "Beep Boop Corp." +; maintainer = "Beep Boop Corp." ; The title of the app used in metadata files. This is NOT a window title. Can contain spaces and special characters. Defaults to name in a [build] section. -title = "Beep Boop" +title = "{{project_name}}" ; Builds an extension when set to "extension". ; default value: "" @@ -1512,7 +1513,7 @@ simulator_device = "iPhone 14" categories = "Developer Tools" ; The command to execute to spawn the "back-end" process. -cmd = "beepboop" +; cmd = "node backend/index.js" ; The icon to use for identifying your app in Linux desktop environments. icon = "src/icon.png" @@ -1527,7 +1528,7 @@ appstore_icon = "src/icons/icon.png" category = "" ; The command to execute to spawn the "back-end" process. -cmd = "" +; cmd = "node backend/index.js" ; The icon to use for identifying your app on MacOS. icon = "" @@ -1552,7 +1553,7 @@ headers = native-module1.hh [win] ; The command to execute to spawn the “back-end” process. -cmd = "beepboop.exe" +; cmd = "node backend/index.js" ; The icon to use for identifying your app on Windows. icon = "" @@ -1564,7 +1565,7 @@ logo = "src/icons/icon.png" pfx = "certs/cert.pfx" ; The signing information needed by the appx api. -publisher = "CN=Beep Boop Corp., O=Beep Boop Corp., L=San Francisco, S=California, C=US" +; publisher = "CN=Beep Boop Corp., O=Beep Boop Corp., L=San Francisco, S=California, C=US" [window]