mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Fixing tests and updating documentation.
This commit is contained in:
parent
f5d6da2a7b
commit
60a7d2128e
7 changed files with 139 additions and 85 deletions
|
@ -306,20 +306,7 @@ printf "y\ny\n" | task 11 delete # y, y
|
||||||
echo $ task list
|
echo $ task list
|
||||||
task list
|
task list
|
||||||
|
|
||||||
# 17 Shell
|
# 17 Special tags
|
||||||
echo Shell --------------------------------------------------------------
|
|
||||||
echo $ task shell
|
|
||||||
#task shell
|
|
||||||
echo '> projects'
|
|
||||||
#> projects
|
|
||||||
echo '> tags'
|
|
||||||
#> tags
|
|
||||||
echo '> list'
|
|
||||||
#> list
|
|
||||||
echo '> quit'
|
|
||||||
#> quit
|
|
||||||
|
|
||||||
# 18 Special tags
|
|
||||||
echo Special tags --------------------------------------------------------------
|
echo Special tags --------------------------------------------------------------
|
||||||
echo $ task 6 +nocolor
|
echo $ task 6 +nocolor
|
||||||
task 6 +nocolor
|
task 6 +nocolor
|
||||||
|
@ -330,7 +317,7 @@ task tags
|
||||||
echo $ task 6 -nocolor
|
echo $ task 6 -nocolor
|
||||||
task 6 -nocolor
|
task 6 -nocolor
|
||||||
|
|
||||||
# 19 Waiting
|
# 18 Waiting
|
||||||
echo Waiting --------------------------------------------------------------
|
echo Waiting --------------------------------------------------------------
|
||||||
echo $ task add Look for new apartment due:eoy
|
echo $ task add Look for new apartment due:eoy
|
||||||
task add Look for new apartment due:eoy
|
task add Look for new apartment due:eoy
|
||||||
|
@ -354,7 +341,7 @@ task list
|
||||||
echo $ task 11 rc.confirmation:no delete
|
echo $ task 11 rc.confirmation:no delete
|
||||||
task 11 rc.confirmation:no delete
|
task 11 rc.confirmation:no delete
|
||||||
|
|
||||||
# 20 Dependencies
|
# 19 Dependencies
|
||||||
echo Dependencies --------------------------------------------------------------
|
echo Dependencies --------------------------------------------------------------
|
||||||
echo $ task list pro:party
|
echo $ task list pro:party
|
||||||
task list pro:party
|
task list pro:party
|
||||||
|
@ -385,7 +372,7 @@ echo 'y' | task 2 done
|
||||||
echo $ task 1 info
|
echo $ task 1 info
|
||||||
task 1 info
|
task 1 info
|
||||||
|
|
||||||
# 21 Reports
|
# 20 Reports
|
||||||
echo Reports --------------------------------------------------------------
|
echo Reports --------------------------------------------------------------
|
||||||
echo $ task minimal
|
echo $ task minimal
|
||||||
task minimal
|
task minimal
|
||||||
|
@ -414,7 +401,7 @@ task timesheet
|
||||||
echo $ task next
|
echo $ task next
|
||||||
task next
|
task next
|
||||||
|
|
||||||
# 22 Custom report
|
# 21 Custom report
|
||||||
echo Custom report --------------------------------------------------------------
|
echo Custom report --------------------------------------------------------------
|
||||||
echo 'report.foo.description=My own report' >> x
|
echo 'report.foo.description=My own report' >> x
|
||||||
echo 'report.foo.columns=id,entry,description' >> x
|
echo 'report.foo.columns=id,entry,description' >> x
|
||||||
|
@ -428,7 +415,7 @@ task show report.foo
|
||||||
echo $ task foo
|
echo $ task foo
|
||||||
task foo
|
task foo
|
||||||
|
|
||||||
# 23 Charts
|
# 22 Charts
|
||||||
echo Charts --------------------------------------------------------------
|
echo Charts --------------------------------------------------------------
|
||||||
echo $ task history
|
echo $ task history
|
||||||
task history
|
task history
|
||||||
|
@ -441,7 +428,7 @@ task ghistory.annual
|
||||||
echo $ task summary
|
echo $ task summary
|
||||||
task summary
|
task summary
|
||||||
|
|
||||||
# 24 Advanced filters
|
# 23 Advanced filters
|
||||||
echo Advanced filters --------------------------------------------------------------
|
echo Advanced filters --------------------------------------------------------------
|
||||||
echo $ task list
|
echo $ task list
|
||||||
task list
|
task list
|
||||||
|
@ -470,7 +457,7 @@ task all status:pending
|
||||||
echo $ task all status:waiting
|
echo $ task all status:waiting
|
||||||
task all status:waiting
|
task all status:waiting
|
||||||
|
|
||||||
# 25 Import/export
|
# 24 Import/export
|
||||||
echo Import/export --------------------------------------------------------------
|
echo Import/export --------------------------------------------------------------
|
||||||
echo $ task export.csv
|
echo $ task export.csv
|
||||||
task export.csv
|
task export.csv
|
||||||
|
@ -507,7 +494,7 @@ printf "y\n" | task import file.yaml
|
||||||
echo $ task new limit:2
|
echo $ task new limit:2
|
||||||
task new limit:2
|
task new limit:2
|
||||||
|
|
||||||
# 26 Help
|
# 25 Help
|
||||||
echo Help --------------------------------------------------------------
|
echo Help --------------------------------------------------------------
|
||||||
echo $ task help
|
echo $ task help
|
||||||
task help
|
task help
|
||||||
|
@ -524,7 +511,7 @@ echo $ man task-faq
|
||||||
echo $ man task-sync
|
echo $ man task-sync
|
||||||
#man task-sync
|
#man task-sync
|
||||||
|
|
||||||
# 27 Wrap up
|
# 26 Wrap up
|
||||||
echo Wrap up --------------------------------------------------------------
|
echo Wrap up --------------------------------------------------------------
|
||||||
echo $ task version
|
echo $ task version
|
||||||
task version
|
task version
|
||||||
|
|
|
@ -10,7 +10,7 @@ task-tutorial.5 man page.
|
||||||
|
|
||||||
---------------------------------------- Shell -----------------------------------------------------
|
---------------------------------------- Shell -----------------------------------------------------
|
||||||
|
|
||||||
task shell You can use the shell command to create a more immersive
|
tasksh You can use the tasksh shell to create a more immersive
|
||||||
task> projects environment. Any task command you run outside the shell
|
task> projects environment. Any task command you run outside the shell
|
||||||
task> tags can also be run inside the shell, without the need to prefix
|
task> tags can also be run inside the shell, without the need to prefix
|
||||||
task> list every command with "task".
|
task> list every command with "task".
|
||||||
|
|
|
@ -970,7 +970,13 @@
|
||||||
#define STRING_UTIL_BYTES "B"
|
#define STRING_UTIL_BYTES "B"
|
||||||
|
|
||||||
// shell
|
// shell
|
||||||
#define STRING_SHELL_UNKOWN_OPTION "Ignoring unkown option: "
|
#define STRING_SHELL_USAGE \
|
||||||
|
"Usage: tasksh [<commands-file>] Execute task commands inside <commands-file> if given,\n" \
|
||||||
|
" or otherwise, start interactive task shell.\n" \
|
||||||
|
" tasksh --version Print task version.\n" \
|
||||||
|
" tasksh --help Print this help.\n"
|
||||||
|
|
||||||
|
#define STRING_SHELL_NO_FILE "Input file does not exist.\n"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,8 @@
|
||||||
|
|
||||||
#define L10N // Localization complete.
|
#define L10N // Localization complete.
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <unistd.h>
|
||||||
#include <Readline.h>
|
#include <Readline.h>
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -45,6 +47,12 @@ std::string Readline::gets (const std::string& prompt)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
bool Readline::interactive_mode (const std::istream& in)
|
||||||
|
{
|
||||||
|
return (&in == &std::cin && isatty(0) == 1);
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
Wordexp::Wordexp (const std::string &str)
|
Wordexp::Wordexp (const std::string &str)
|
||||||
{
|
{
|
||||||
|
|
|
@ -49,6 +49,7 @@ class Readline
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static std::string gets (const std::string& prompt);
|
static std::string gets (const std::string& prompt);
|
||||||
|
static bool interactive_mode (const std::istream& in);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// No construction or destruction.
|
// No construction or destruction.
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
|
|
||||||
#define L10N // Localization complete.
|
#define L10N // Localization complete.
|
||||||
|
|
||||||
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -63,23 +64,54 @@ int main (int argc, const char** argv)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int status = 0;
|
int status = 0;
|
||||||
|
bool read_from_file = false;
|
||||||
|
|
||||||
if (argc == 2 && !strcmp (argv[1], "--version"))
|
if (argc > 2)
|
||||||
|
{
|
||||||
|
std::cout << STRING_SHELL_USAGE << "\n";
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
else if (argc == 2)
|
||||||
|
{
|
||||||
|
if (!strcmp (argv[1], "--version"))
|
||||||
{
|
{
|
||||||
std::cout << VERSION << "\n";
|
std::cout << VERSION << "\n";
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else if (!strcmp (argv[1], "--help"))
|
||||||
|
{
|
||||||
|
std::cout << STRING_SHELL_USAGE << "\n";
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (argc > 1)
|
// The user has give tasksh a task commands file to execute
|
||||||
{
|
File input_file = File (argv[1]);
|
||||||
std::cerr << STRING_SHELL_UNKOWN_OPTION << argv[1] << "\n";
|
if (!input_file.exists ()) {
|
||||||
|
std::cout << STRING_SHELL_NO_FILE;
|
||||||
|
std::cout << STRING_SHELL_USAGE << "\n";
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
read_from_file = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// if a file is given, read from it
|
||||||
|
std::ifstream fin;
|
||||||
|
if (read_from_file) {
|
||||||
|
fin.open(argv[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// commands may be redirected too
|
||||||
|
std::istream &in = read_from_file ? fin : std::cin;
|
||||||
|
|
||||||
// Begining initilaization
|
// Begining initilaization
|
||||||
status = context.initialize (0, NULL);
|
status = context.initialize (0, NULL);
|
||||||
|
|
||||||
// Display some kind of welcome message.
|
// Display some kind of welcome message.
|
||||||
Color bold (Color::nocolor, Color::nocolor, false, true, false);
|
Color bold (Color::nocolor, Color::nocolor, false, true, false);
|
||||||
|
|
||||||
std::cout << (context.color () ? bold.colorize (PACKAGE_STRING) : PACKAGE_STRING)
|
std::cout << (context.color () ? bold.colorize (PACKAGE_STRING) : PACKAGE_STRING)
|
||||||
<< " shell\n\n"
|
<< " shell\n\n"
|
||||||
<< STRING_CMD_SHELL_HELP1 << "\n"
|
<< STRING_CMD_SHELL_HELP1 << "\n"
|
||||||
|
@ -101,7 +133,7 @@ int main (int argc, const char** argv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string input, prompt(context.config.get ("shell.prompt") + " ");
|
std::string input;
|
||||||
|
|
||||||
std::vector <std::string> quit_commands;
|
std::vector <std::string> quit_commands;
|
||||||
quit_commands.push_back ("quit");
|
quit_commands.push_back ("quit");
|
||||||
|
@ -109,18 +141,39 @@ int main (int argc, const char** argv)
|
||||||
quit_commands.push_back ("bye");
|
quit_commands.push_back ("bye");
|
||||||
|
|
||||||
// The event loop.
|
// The event loop.
|
||||||
while (1)
|
while (in)
|
||||||
{
|
{
|
||||||
|
std::string prompt(context.config.get ("shell.prompt") + " ");
|
||||||
context.clear ();
|
context.clear ();
|
||||||
|
|
||||||
|
if (Readline::interactive_mode(in))
|
||||||
|
{
|
||||||
input = Readline::gets (prompt);
|
input = Readline::gets (prompt);
|
||||||
if (std::find (quit_commands.begin (), quit_commands.end (),
|
}
|
||||||
lowerCase (input)) != quit_commands.end ())
|
else
|
||||||
break;
|
{
|
||||||
|
std::getline (in, input);
|
||||||
|
|
||||||
|
// if a string has nothing but whitespaces, ignore it
|
||||||
|
if (input.find_first_not_of (" \t") == std::string::npos)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
std::cout << prompt << input << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Wordexp w ("task " + trim (input + permanent_overrides));
|
Wordexp w ("task " + trim (input + permanent_overrides));
|
||||||
|
|
||||||
|
for (int i = 0; i < w.argc (); ++i) {
|
||||||
|
if (std::find (quit_commands.begin (), quit_commands.end (),
|
||||||
|
lowerCase (w.argv ()[i])) != quit_commands.end ())
|
||||||
|
{
|
||||||
|
context.clearMessages ();
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
status = context.initialize (w.argc (), (const char**)w.argv ());
|
status = context.initialize (w.argc (), (const char**)w.argv ());
|
||||||
if (status == 0)
|
if (status == 0)
|
||||||
status = context.run ();
|
status = context.run ();
|
||||||
|
@ -140,7 +193,6 @@ int main (int argc, const char** argv)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// No need to repeat any overrides after the shell quits.
|
// No need to repeat any overrides after the shell quits.
|
||||||
context.clearMessages ();
|
context.clearMessages ();
|
||||||
|
|
|
@ -42,12 +42,12 @@ if (open my $fh, '>', 'shell.rc')
|
||||||
}
|
}
|
||||||
|
|
||||||
# Test the prompt.
|
# Test the prompt.
|
||||||
my $output = qx{echo "quit" | ../src/task rc:shell.rc shell 2>&1};
|
my $output = qx{printf "rc:test.rc add foo\nquit" | ../src/shell/tasksh 2>&1};
|
||||||
like ($output, qr/testprompt>/, 'custom prompt is being used');
|
like ($output, qr/testprompt>/, 'custom prompt is being used');
|
||||||
|
|
||||||
# Test a simple add, then info.
|
# Test a simple add, then info.
|
||||||
qx{echo "add foo" | ../src/task rc:shell.rc shell 2>&1};
|
qx{echo "rc:shell.rc add foo" | ../src/shell/tasksh 2>&1};
|
||||||
$output = qx{echo "1 info" | ../src/task rc:shell.rc shell 2>&1};
|
$output = qx{echo "rc:shell.rc 1 info" | ../src/shell/tasksh 2>&1};
|
||||||
like ($output, qr/Description\s+foo/, 'add/info working');
|
like ($output, qr/Description\s+foo/, 'add/info working');
|
||||||
|
|
||||||
unlink 'shell.rc';
|
unlink 'shell.rc';
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue