Skip to content
This repository was archived by the owner on Jun 12, 2019. It is now read-only.

Commit bf427f7

Browse files
author
Caroline Twigg
authored
Merge pull request #43 from MetisMachine/jt-remote-info-fix
fix for remote info bug
2 parents d026de1 + 2a7e91f commit bf427f7

1 file changed

Lines changed: 19 additions & 15 deletions

File tree

src/project/project.cpp

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -173,33 +173,37 @@ void Project::remote_add(string project_token){
173173
std::string selected_org;
174174
std::string err;
175175

176-
Json json = Json::parse(Request::organization_info().body, err);
177-
auto list = json["data"].array_items();
176+
RestClient::Response req = Request::my_organizations();
177+
Json json = Json::parse(req.body, err);
178+
auto list = json.array_items();
178179

179180
string list_size = std::to_string(list.size());
180181

181182
if(stoi(list_size) == 1){
182183
selected_org = list[0]["id"].string_value();
183184
} else{
184185
cout << "Please select the organization for the project." << endl;
185-
int opt_iter = 1;
186-
for(auto i : list) {
187-
std::string org_id = Json(i)["display_name"].string_value();
186+
int opt_iter = 1;
187+
for(auto i : list) {
188+
auto j = Json(i);
189+
std::string org_id = j["display_name"].string_value();
188190

189-
org_id.erase(std::remove(org_id.begin(), org_id.end(), '"'), org_id.end());
190-
cout << std::to_string(opt_iter) << ". "+ org_id << endl;
191-
opt_iter++;
192-
}
193-
string opt_select;
191+
org_id.erase(std::remove(org_id.begin(), org_id.end(), '"'), org_id.end());
192+
cout << std::to_string(opt_iter) << ". "+ org_id << endl;
193+
opt_iter++;
194+
}
194195
cout << "Enter your choice and press return: ";
195-
while(!(cin >> opt_select) && std::stoi(opt_select) - 1 < list.size()) {
196+
string opt_select;
197+
cin >> opt_select;
198+
auto idx = stoi(opt_select) - 1;
199+
if(idx >= list.size()) {
196200
cin.clear();
197201
cin.ignore(1, '\n');
198-
cout << "Invalid choice. Valid numbers are [1-" << list_size << "]. Try again: ";
202+
cout << "Invalid choice. Valid numbers are [1-" << list_size << "].";
203+
return;
204+
} else {
205+
selected_org = list[idx]["id"].string_value();
199206
}
200-
201-
int index = std::stoi(opt_select) - 1;
202-
selected_org = list[index]["id"].string_value();
203207
}
204208
console::info("To add a new remote, copy the git remote add skafos command below and run it on the terminal.\n");
205209
console::info("$ git remote add skafos " + VASI_URL + selected_org + "/" + project_token + "\n");

0 commit comments

Comments
 (0)