Skip to content

Commit

Permalink
Fix more bugs creating/opening project.
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksi Salmela committed May 2, 2017
1 parent 7715fdd commit a33130f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1648,7 +1648,7 @@ std::string Config::getTaskerData(std::string path, std::string *source)
return "";
}

void Config::setTaskerData(std::string path, std::string source)
void Config::setTaskerData(std::string source, std::string path)
{
mConfig.addRepository(source, path);

Expand Down
2 changes: 1 addition & 1 deletion backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ class Config//< TODO this object should be thread safe
static std::string guessProjectDir(std::string currentWorkDir);
static std::string getSourceDir(std::string taskerPath);
static std::string getTaskerData(std::string path, std::string *source = NULL);
static void setTaskerData(std::string path, std::string source);
static void setTaskerData(std::string source, std::string path);
private:
Config();
~Config();
Expand Down
23 changes: 17 additions & 6 deletions cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include <exception>
#include <unistd.h>

#ifdef _NO_READLINE_
#ifndef _NO_READLINE_
# include <readline/readline.h>
# include <readline/history.h>
#endif
Expand Down Expand Up @@ -143,17 +143,27 @@ bool Main::init(int argc, char **argv)
{
char *cwd_tmp = get_current_dir_name();
std::string cwd = cwd_tmp;
std::string dir = Backend::Config::guessProjectDir(cwd);
free(cwd_tmp);

std::string dir = Backend::Config::getTaskerData(cwd, NULL);
bool knownToExist = !dir.empty();
if(!knownToExist) {
dir = cwd;
}

if(argc >= 2) {
dir = argv[1];
knownToExist = false;
}

mProject = Backend::Project::open(dir);
if(mProject) {
return true;
}
if(knownToExist) {
std::cerr << "The config file contains non-existing project " << dir << "\n";
return false;
}
std::cerr << "Tasker data not found.\n";
while(true) {
std::string prompt = "Create a new tasker repository? [y/n]";
Expand All @@ -164,12 +174,13 @@ bool Main::init(int argc, char **argv)
return false;
}
}
mProject = Backend::Project::create("./");
dir = Main::getLine("Where do you want the issues?");
char *buf = realpath(dir.c_str(), NULL);
dir.assign(buf);
free(buf);
// Ugly way to turn relative path to absolute path
if(dir[0] != '/') {
dir = cwd + "/" + dir;
}

mProject = Backend::Project::create(dir);
Backend::Config::setTaskerData(cwd, dir);
return true;
}
Expand Down

0 comments on commit a33130f

Please sign in to comment.