Skip to content

Commit e95389b

Browse files
committed
Generate config file incase nothing is available
1 parent fc36138 commit e95389b

File tree

3 files changed

+59
-11
lines changed

3 files changed

+59
-11
lines changed

README.md

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,28 +36,35 @@ Run the `qc` command. This will open up the interactive TUI (the [config file](#
3636

3737

3838
# Setup
39-
Currently there is no real easy way of installing this tool.
40-
Appimage might work (on linux) but was not tested.
41-
General installing and compiling should work.
39+
Either download the newest [AppImage](#appimage) (see Releases) and run it
40+
or [compile the repo manually](#general) and run it.
4241

4342

44-
## Appimage
43+
## AppImage
4544

46-
* Download the Appimage
45+
* Download the Appimage on the Releases page
4746
* Make it executable `chmod +x <file>`
48-
* For systems that can not run it
47+
* For systems that can not run it (Windows: WSL)
4948
* Extract it with `./<file> --appimage-extract`
5049
* Run the executable in `./squashfs-root/usr/bin/qc`
5150
* Run it
5251

5352

5453
## General
5554

56-
* Currently there is no pre-compiled binaries (ignoring appimage)
55+
* Currently there is no pre-compiled binaries (ignoring [appimage](#appimage))
5756
* To install: have the needed [dependencies](#dependencies) and [compile](#commands) the tool on your machine
57+
* On first run, the application will create (if not already existing) the following:
58+
* Folders for `~/.config/quick-clone/`
59+
* Config file `~/.config/quick-clone/config.json`
60+
* Add example data to the config file
61+
* Only the official gitlab repo works for testing the rest are just example data that will not work
62+
63+
64+
## Config
5865
* Add access token in Gitlab with (at least) API-read permissions
5966
* Can be found in your personal settings under "Access Tokens"
60-
* Create config file at `~/.config/quick-clone/config.json` (_names etc. might change_)
67+
* ~~Create/~~Update config file at `~/.config/quick-clone/config.json` (_names etc. might change_)
6168
* An array structure is used, for the purpose of having multiple git endpoints
6269
* Every element is an objcet inside the array `[{...}, {...}, ...]` with the following
6370
* `name` - Will be shown in the app to identify the selected endpoint

src/data/config.cpp

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
2555
void 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;

src/data/config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class ApiConfigCollection {
2222
ApiConfigCollection();
2323

2424
void init();
25+
void generatePlaceholderConfigFile(std::string path, std::string filename);
2526
};
2627

2728
#endif

0 commit comments

Comments
 (0)