mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Feature #632
- Added feature #632, which allows environment variables TASKRC and TASKDATA to override .taskrc and .task directory locations (thanks to Steve Rader). - Added unit tests. +
This commit is contained in:
parent
09431caf1c
commit
c785836083
7 changed files with 129 additions and 2 deletions
2
AUTHORS
2
AUTHORS
|
@ -66,6 +66,7 @@ The following submitted code, packages or analysis, and deserve special thanks:
|
||||||
Ralph Bean
|
Ralph Bean
|
||||||
Uli Martens
|
Uli Martens
|
||||||
Michal Vyskocil
|
Michal Vyskocil
|
||||||
|
Steve Rader
|
||||||
|
|
||||||
Thanks to the following, who submitted detailed bug reports and excellent
|
Thanks to the following, who submitted detailed bug reports and excellent
|
||||||
suggestions:
|
suggestions:
|
||||||
|
@ -99,7 +100,6 @@ suggestions:
|
||||||
Max Muller
|
Max Muller
|
||||||
Thomas Sattler
|
Thomas Sattler
|
||||||
Erlan Sergaziev
|
Erlan Sergaziev
|
||||||
Steve Rader
|
|
||||||
Andy Kriger
|
Andy Kriger
|
||||||
Patrick R McDonald
|
Patrick R McDonald
|
||||||
Pete Lewis
|
Pete Lewis
|
||||||
|
|
|
@ -80,6 +80,8 @@
|
||||||
+ Added feature #612, so that the 'info' command displays the sum of all
|
+ Added feature #612, so that the 'info' command displays the sum of all
|
||||||
active (start/stop) times for a task, if the 'journal.info' configuration
|
active (start/stop) times for a task, if the 'journal.info' configuration
|
||||||
variable is set (thanks to Andy Kriger).
|
variable is set (thanks to Andy Kriger).
|
||||||
|
+ Added feature #632, which allows environment variables TASKRC and TASKDATA
|
||||||
|
to override .taskrc and .task directory locations (thanks to Steve Rader).
|
||||||
+ Added feature #657 & #658, using the 'ids' command, tasks matching a filter
|
+ Added feature #657 & #658, using the 'ids' command, tasks matching a filter
|
||||||
can now be modified as a group (thanks to Bryce Harrington, Eric Fluger).
|
can now be modified as a group (thanks to Bryce Harrington, Eric Fluger).
|
||||||
+ Added feature #679, which makes color rules match project names in a left-
|
+ Added feature #679, which makes color rules match project names in a left-
|
||||||
|
|
|
@ -124,6 +124,17 @@ This includes two standard files that are distributed with taskwarrior, which
|
||||||
define a set of US holidays, and set up a 16-color theme to use, to color the
|
define a set of US holidays, and set up a 16-color theme to use, to color the
|
||||||
reports and calendar.
|
reports and calendar.
|
||||||
|
|
||||||
|
.SH ENVIRONMENT VARIABLES
|
||||||
|
These environmant variables override defaults and command line arguments.
|
||||||
|
|
||||||
|
.TP
|
||||||
|
.B TASKDATA=~/.task
|
||||||
|
The overrides the default path for the taskwarrior data files.
|
||||||
|
|
||||||
|
.TP
|
||||||
|
.B TASKRC=~/.taskrc
|
||||||
|
The overrides the default RC file.
|
||||||
|
|
||||||
.SH CONFIGURATION VARIABLES
|
.SH CONFIGURATION VARIABLES
|
||||||
Valid variable names and their default values are:
|
Valid variable names and their default values are:
|
||||||
|
|
||||||
|
|
|
@ -91,6 +91,15 @@ int Context::initialize (int argc, const char** argv)
|
||||||
a3.categorize ();
|
a3.categorize ();
|
||||||
a3.rc_override (home_dir, rc_file);
|
a3.rc_override (home_dir, rc_file);
|
||||||
|
|
||||||
|
// TASKRC environment variable overrides the command line.
|
||||||
|
char* override = getenv ("TASKRC");
|
||||||
|
if (override)
|
||||||
|
{
|
||||||
|
rc_file = File (override);
|
||||||
|
debug ("TASKRC override: ");
|
||||||
|
header (format (STRING_CONTEXT_RC_OVERRIDE, rc_file._data));
|
||||||
|
}
|
||||||
|
|
||||||
// Dump any existing values and load rc file.
|
// Dump any existing values and load rc file.
|
||||||
config.clear ();
|
config.clear ();
|
||||||
config.load (rc_file);
|
config.load (rc_file);
|
||||||
|
@ -101,7 +110,18 @@ int Context::initialize (int argc, const char** argv)
|
||||||
std::string location;
|
std::string location;
|
||||||
a3.get_data_location (location);
|
a3.get_data_location (location);
|
||||||
data_dir = Directory (location);
|
data_dir = Directory (location);
|
||||||
|
|
||||||
|
override = getenv ("TASKDATA");
|
||||||
|
if (override)
|
||||||
|
{
|
||||||
|
data_dir = Directory (override);
|
||||||
|
config.set ("data.location", data_dir._data);
|
||||||
|
header (format (STRING_CONTEXT_DATA_OVERRIDE, data_dir._data));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* TODO Enable this when the time is right, say for 2.1
|
||||||
extension_dir = data_dir._data + "/extensions";
|
extension_dir = data_dir._data + "/extensions";
|
||||||
|
*/
|
||||||
|
|
||||||
// Create missing config file and data directory, if necessary.
|
// Create missing config file and data directory, if necessary.
|
||||||
createDefaultConfig ();
|
createDefaultConfig ();
|
||||||
|
|
|
@ -75,7 +75,6 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void assumeLocations ();
|
void assumeLocations ();
|
||||||
void determineDataLocation ();
|
|
||||||
void createDefaultConfig ();
|
void createDefaultConfig ();
|
||||||
void loadAliases ();
|
void loadAliases ();
|
||||||
void updateXtermTitle ();
|
void updateXtermTitle ();
|
||||||
|
|
|
@ -510,6 +510,8 @@
|
||||||
// Context
|
// Context
|
||||||
#define STRING_CONTEXT_CREATE_RC "A configuration file could not be found in {1}\n\nWould you like a sample {2} created, so taskwarrior can proceed?"
|
#define STRING_CONTEXT_CREATE_RC "A configuration file could not be found in {1}\n\nWould you like a sample {2} created, so taskwarrior can proceed?"
|
||||||
#define STRING_CONTEXT_NEED_RC "Cannot proceed without rc file."
|
#define STRING_CONTEXT_NEED_RC "Cannot proceed without rc file."
|
||||||
|
#define STRING_CONTEXT_RC_OVERRIDE "TASKRC override: {1}"
|
||||||
|
#define STRING_CONTEXT_DATA_OVERRIDE "TASKDATA override: {1}"
|
||||||
#define STRING_CONTEXT_SHADOW_P "Configuration variable 'shadow.file' is set to " "overwrite your pending tasks. Please change it."
|
#define STRING_CONTEXT_SHADOW_P "Configuration variable 'shadow.file' is set to " "overwrite your pending tasks. Please change it."
|
||||||
#define STRING_CONTEXT_SHADOW_C "Configuration variable 'shadow.file' is set to " "overwrite your completed tasks. Please change it."
|
#define STRING_CONTEXT_SHADOW_C "Configuration variable 'shadow.file' is set to " "overwrite your completed tasks. Please change it."
|
||||||
#define STRING_CONTEXT_SHADOW_U "Configuration variable 'shadow.file' is set to " "overwrite your undo log. Please change it."
|
#define STRING_CONTEXT_SHADOW_U "Configuration variable 'shadow.file' is set to " "overwrite your undo log. Please change it."
|
||||||
|
|
93
test/feature.632.t
Executable file
93
test/feature.632.t
Executable file
|
@ -0,0 +1,93 @@
|
||||||
|
#! /usr/bin/perl
|
||||||
|
################################################################################
|
||||||
|
## taskwarrior - a command line task list manager.
|
||||||
|
##
|
||||||
|
## Copyright 2006-2012, Paul Beckingham, Federico Hernandez.
|
||||||
|
##
|
||||||
|
## Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
## of this software and associated documentation files (the "Software"), to deal
|
||||||
|
## in the Software without restriction, including without limitation the rights
|
||||||
|
## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
## copies of the Software, and to permit persons to whom the Software is
|
||||||
|
## furnished to do so, subject to the following conditions:
|
||||||
|
##
|
||||||
|
## The above copyright notice and this permission notice shall be included
|
||||||
|
## in all copies or substantial portions of the Software.
|
||||||
|
##
|
||||||
|
## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||||
|
## OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||||
|
## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
## SOFTWARE.
|
||||||
|
##
|
||||||
|
## http://www.opensource.org/licenses/mit-license.php
|
||||||
|
##
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
use Test::More tests => 12;
|
||||||
|
use File::Path;
|
||||||
|
|
||||||
|
# Create the rc files.
|
||||||
|
if (open my $fh, '>', 'rc1')
|
||||||
|
{
|
||||||
|
print $fh "data.location=./data1\n";
|
||||||
|
close $fh;
|
||||||
|
ok (-r 'rc1', 'Created rc1');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (open my $fh, '>', 'rc2')
|
||||||
|
{
|
||||||
|
print $fh "data.location=./data2\n";
|
||||||
|
close $fh;
|
||||||
|
ok (-r 'rc2', 'Created rc2');
|
||||||
|
}
|
||||||
|
|
||||||
|
# Feature #632: task environment variables: TASKRC and TASKDATA
|
||||||
|
qx{../src/task rc:rc1 add one};
|
||||||
|
qx{../src/task rc:rc2 add two};
|
||||||
|
|
||||||
|
# All in agreement: 1
|
||||||
|
my $output = qx{../src/task rc:rc1 list};
|
||||||
|
like ($output, qr/one/, 'rc1');
|
||||||
|
|
||||||
|
$output = qx{TASKDATA=./data1 ../src/task rc:rc1 list};
|
||||||
|
like ($output, qr/one/, 'TASKDATA, rc1');
|
||||||
|
|
||||||
|
$output = qx{TASKRC=./rc1 ../src/task list};
|
||||||
|
like ($output, qr/one/, 'TASKRC');
|
||||||
|
|
||||||
|
$output = qx{TASKDATA=./data1 TASKRC=./rc1 ../src/task list};
|
||||||
|
like ($output, qr/one/, 'TASKDATA, TASKRC, rc1');
|
||||||
|
|
||||||
|
# All in agreement: 2
|
||||||
|
$output = qx{../src/task rc:rc2 list};
|
||||||
|
like ($output, qr/two/, 'rc2');
|
||||||
|
|
||||||
|
$output = qx{TASKDATA=./data2 ../src/task rc:rc2 list};
|
||||||
|
like ($output, qr/two/, 'TASKDATA, rc2');
|
||||||
|
|
||||||
|
$output = qx{TASKRC=./rc2 ../src/task list};
|
||||||
|
like ($output, qr/two/, 'TASKRC');
|
||||||
|
|
||||||
|
$output = qx{TASKDATA=./data2 TASKRC=./rc2 ../src/task list};
|
||||||
|
like ($output, qr/two/, 'TASKDATA, TASKRC, rc2');
|
||||||
|
|
||||||
|
# rc: overrides TASKRC, TASKDATA
|
||||||
|
$output = qx{TASKDATA=./data1 TASKRC=./rc1 ../src/task rc:rc2 list};
|
||||||
|
like ($output, qr/one/, 'overrides TASKDATA, TASKRC override rc:');
|
||||||
|
|
||||||
|
rmtree ('./data1', 0 , 1);
|
||||||
|
rmtree ('./data2', 0 , 1);
|
||||||
|
|
||||||
|
unlink qw(rc1 rc2);
|
||||||
|
ok (! -d './data1' &&
|
||||||
|
! -d './data2' &&
|
||||||
|
! -r 'rc1' &&
|
||||||
|
! -r 'rc2', 'Cleanup');
|
||||||
|
|
||||||
|
exit 0
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue