@@ -22,13 +22,53 @@ ApiConfigCollection::ApiConfigCollection() {
2222 this ->selected = 0 ;
2323}
2424
25+ void ApiConfigCollection::generatePlaceholderConfigFile (std::string path, std::string filename) {
26+ std::string createFolder = " mkdir -p " + path;
27+ std::system (createFolder.c_str ());
28+
29+ std::string configFilePath = path + " /" + filename;
30+ std::ofstream outfile (configFilePath);
31+
32+ std::string configExampleString =
33+ " [\n "
34+ " {\n "
35+ " \" name\" : \" Official Gitlab\" ,\n "
36+ " \" access_token\" : \"\" ,\n "
37+ " \" url\" : \" https://gitlab.com/api/v4/projects\"\n "
38+ " },\n "
39+ " {\n "
40+ " \" name\" : \" Your Work Repository Manager (see README for configuration)\" ,\n "
41+ " \" access_token\" : \" replace-with-token-see-README\" ,\n "
42+ " \" url\" : \" https://your-work-endpoint.com/path/to/api\"\n "
43+ " },\n "
44+ " {\n "
45+ " \" name\" : \" Your Private Repository Manager (config at: '" + configFilePath + " ')\" ,\n "
46+ " \" access_token\" : \" replace-with-token-see-README\" ,\n "
47+ " \" url\" : \" https://your-private-endpoint.com/path/to/api\"\n "
48+ " }\n "
49+ " ]" ;
50+
51+ outfile << configExampleString << std::endl;
52+ outfile.close ();
53+ }
54+
2555void ApiConfigCollection::init () {
2656 std::string homeDir = std::getenv (" HOME" );
27- std::string configDir = homeDir + " /.config/quick-clone/config.json" ;
28- std::ifstream file (configDir);
57+ std::string configDir = homeDir + " /.config/quick-clone" ;
58+ std::string configFileName = " config.json" ;
59+ std::string configFilePath = configDir + " /" + configFileName;
60+ std::ifstream file;
61+ file.open (configFilePath);
2962
3063 // user could have forgotten the config file
31- if (!file) throw std::string (" Config file is missing: \" " + configDir + " \" " );
64+ // generate a basic one so that it at least shows the working app
65+ if (!file) {
66+ file.close ();
67+ this ->generatePlaceholderConfigFile (configDir, configFileName);
68+
69+ // reload the file
70+ file.open (configFilePath);
71+ }
3272
3373 // build array of missing config parts, to display to the user
3474 std::vector<std::string> errorList;
0 commit comments