- Task offers to create a sample ~/.taskrc file if one is not found.

- Task offers to create a ~/.task directory if one is not found.
This commit is contained in:
Paul Beckingham 2008-05-17 22:08:50 -04:00
parent a8fa293695
commit 42493dbdee
5 changed files with 81 additions and 7 deletions

View file

@ -10,6 +10,11 @@
------ reality -----------------------------------
0.9.7
5/17/2008
+ Task offers to create a sample ~/.taskrc file if one is not found.
+ Task offers to create a ~/.task directory if one is not found.
0.9.6
5/13/208
+ Replaced color management code.

View file

@ -91,7 +91,7 @@ Config.o Config.o: Config.cpp /usr/include/c++/4.0.0/iostream \
/usr/include/c++/4.0.0/bits/istream.tcc /usr/include/c++/4.0.0/fstream \
/usr/include/c++/4.0.0/i686-apple-darwin9/bits/basic_file.h \
/usr/include/c++/4.0.0/bits/fstream.tcc /usr/include/c++/4.0.0/sstream \
/usr/include/c++/4.0.0/bits/sstream.tcc task.h \
/usr/include/c++/4.0.0/bits/sstream.tcc /usr/include/sys/stat.h task.h \
/usr/include/c++/4.0.0/vector /usr/include/c++/4.0.0/bits/stl_vector.h \
/usr/include/c++/4.0.0/bits/stl_bvector.h \
/usr/include/c++/4.0.0/bits/vector.tcc /usr/include/c++/4.0.0/map \
@ -366,6 +366,8 @@ Config.o Config.o: Config.cpp /usr/include/c++/4.0.0/iostream \
/usr/include/c++/4.0.0/bits/sstream.tcc:
/usr/include/sys/stat.h:
task.h:
/usr/include/c++/4.0.0/vector:

View file

@ -6,6 +6,7 @@
#include <iostream>
#include <fstream>
#include <sstream>
#include <sys/stat.h>
#include "task.h"
#include "Config.h"
@ -60,6 +61,67 @@ bool Config::load (const std::string& file)
return false;
}
////////////////////////////////////////////////////////////////////////////////
void Config::createDefault (const std::string& file)
{
if (confirm (
"A configuration file could not be found in "
+ file
+ "\n\n"
+ "Would you like a sample .taskrc created, so task can proceed?"))
{
// Determine a path to the task directory.
std::string taskDir = "";
for (int i = file.length () - 1; i >= 0; --i)
{
if (file[i] == '/')
{
taskDir = file.substr (0, i) + "/.task";
if (-1 == access (taskDir.c_str (), F_OK))
mkdir (taskDir.c_str (), S_IRWXU);
break;
}
}
if (taskDir != "")
{
FILE* out;
if (out = fopen (file.c_str (), "w"))
{
fprintf (out, "data.location=%s\n", taskDir.c_str ());
fprintf (out, "command.logging=off\n");
fprintf (out, "confirmation=yes\n");
fprintf (out, "#nag=Note: try to stick to high priority tasks. See \"task next\".\n");
fprintf (out, "next=2\n");
fprintf (out, "curses=on\n");
fprintf (out, "color=on\n");
fprintf (out, "color.overdue=red\n");
fprintf (out, "#color.due=on yellow\n");
fprintf (out, "#color.pri.H=on_red\n");
fprintf (out, "#color.pri.M=on_yellow\n");
fprintf (out, "#color.pri.L=on_green\n");
fprintf (out, "color.active=cyan\n");
fprintf (out, "color.tagged=yellow\n");
fclose (out);
set ("data.location", taskDir);
set ("command.logging", "off");
set ("confirmation", "yes");
set ("next", 2);
set ("curses", "on");
set ("color", "on");
set ("color.overdue", "red");
set ("color.active", "cyan");
set ("color.tagged", "yellow");
std::cout << "Done." << std::endl;
}
}
}
}
////////////////////////////////////////////////////////////////////////////////
// Return the configuration value given the specified key.
const std::string& Config::get (const char* key)

View file

@ -17,6 +17,8 @@ public:
Config (const std::string&);
bool load (const std::string&);
void createDefault (const std::string&);
const std::string& get (const char*);
const std::string& get (const char*, const char*);
const std::string& get (const std::string&);

View file

@ -1,5 +1,5 @@
////////////////////////////////////////////////////////////////////////////////
// Copyright 2006 - 2008 Paul Beckingham.
// Copyright 2006 - 2008, Paul Beckingham.
// All rights reserved.
//
//
@ -38,9 +38,9 @@ void usage (Config& conf)
}
#endif
table.addColumn ("");
table.addColumn ("");
table.addColumn ("");
table.addColumn (" ");
table.addColumn (" ");
table.addColumn (" ");
table.setColumnJustification (0, Table::left);
table.setColumnJustification (1, Table::left);
@ -180,11 +180,13 @@ void usage (Config& conf)
////////////////////////////////////////////////////////////////////////////////
int main (int argc, char** argv)
{
// TODO Find out what this is, and either promote it to live code, or remove it.
// std::set_terminate (__gnu_cxx::__verbose_terminate_handler);
try
{
// Load the config file from the home directory.
// Load the config file from the home directory. If the file cannot be
// found, offer to create a sample one.
Config conf;
struct passwd* pw = getpwuid (getuid ());
if (!pw)
@ -192,7 +194,8 @@ int main (int argc, char** argv)
std::string home = pw->pw_dir;
home += "/.taskrc";
conf.load (home);
if (!conf.load (home))
conf.createDefault (home);
TDB tdb;
tdb.dataDirectory (conf.get ("data.location"));