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
|
||||
task list
|
||||
|
||||
# 17 Shell
|
||||
echo Shell --------------------------------------------------------------
|
||||
echo $ task shell
|
||||
#task shell
|
||||
echo '> projects'
|
||||
#> projects
|
||||
echo '> tags'
|
||||
#> tags
|
||||
echo '> list'
|
||||
#> list
|
||||
echo '> quit'
|
||||
#> quit
|
||||
|
||||
# 18 Special tags
|
||||
# 17 Special tags
|
||||
echo Special tags --------------------------------------------------------------
|
||||
echo $ task 6 +nocolor
|
||||
task 6 +nocolor
|
||||
|
@ -330,7 +317,7 @@ task tags
|
|||
echo $ task 6 -nocolor
|
||||
task 6 -nocolor
|
||||
|
||||
# 19 Waiting
|
||||
# 18 Waiting
|
||||
echo Waiting --------------------------------------------------------------
|
||||
echo $ 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
|
||||
task 11 rc.confirmation:no delete
|
||||
|
||||
# 20 Dependencies
|
||||
# 19 Dependencies
|
||||
echo Dependencies --------------------------------------------------------------
|
||||
echo $ task list pro:party
|
||||
task list pro:party
|
||||
|
@ -385,7 +372,7 @@ echo 'y' | task 2 done
|
|||
echo $ task 1 info
|
||||
task 1 info
|
||||
|
||||
# 21 Reports
|
||||
# 20 Reports
|
||||
echo Reports --------------------------------------------------------------
|
||||
echo $ task minimal
|
||||
task minimal
|
||||
|
@ -414,7 +401,7 @@ task timesheet
|
|||
echo $ task next
|
||||
task next
|
||||
|
||||
# 22 Custom report
|
||||
# 21 Custom report
|
||||
echo Custom report --------------------------------------------------------------
|
||||
echo 'report.foo.description=My own report' >> x
|
||||
echo 'report.foo.columns=id,entry,description' >> x
|
||||
|
@ -428,7 +415,7 @@ task show report.foo
|
|||
echo $ task foo
|
||||
task foo
|
||||
|
||||
# 23 Charts
|
||||
# 22 Charts
|
||||
echo Charts --------------------------------------------------------------
|
||||
echo $ task history
|
||||
task history
|
||||
|
@ -441,7 +428,7 @@ task ghistory.annual
|
|||
echo $ task summary
|
||||
task summary
|
||||
|
||||
# 24 Advanced filters
|
||||
# 23 Advanced filters
|
||||
echo Advanced filters --------------------------------------------------------------
|
||||
echo $ task list
|
||||
task list
|
||||
|
@ -470,7 +457,7 @@ task all status:pending
|
|||
echo $ task all status:waiting
|
||||
task all status:waiting
|
||||
|
||||
# 25 Import/export
|
||||
# 24 Import/export
|
||||
echo Import/export --------------------------------------------------------------
|
||||
echo $ task export.csv
|
||||
task export.csv
|
||||
|
@ -507,7 +494,7 @@ printf "y\n" | task import file.yaml
|
|||
echo $ task new limit:2
|
||||
task new limit:2
|
||||
|
||||
# 26 Help
|
||||
# 25 Help
|
||||
echo Help --------------------------------------------------------------
|
||||
echo $ task help
|
||||
task help
|
||||
|
@ -524,7 +511,7 @@ echo $ man task-faq
|
|||
echo $ man task-sync
|
||||
#man task-sync
|
||||
|
||||
# 27 Wrap up
|
||||
# 26 Wrap up
|
||||
echo Wrap up --------------------------------------------------------------
|
||||
echo $ task version
|
||||
task version
|
||||
|
|
|
@ -10,7 +10,7 @@ task-tutorial.5 man page.
|
|||
|
||||
---------------------------------------- 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> tags can also be run inside the shell, without the need to prefix
|
||||
task> list every command with "task".
|
||||
|
|
|
@ -970,7 +970,13 @@
|
|||
#define STRING_UTIL_BYTES "B"
|
||||
|
||||
// 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
|
||||
|
||||
|
|
|
@ -27,6 +27,8 @@
|
|||
|
||||
#define L10N // Localization complete.
|
||||
|
||||
#include <iostream>
|
||||
#include <unistd.h>
|
||||
#include <Readline.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -45,6 +47,12 @@ std::string Readline::gets (const std::string& prompt)
|
|||
return ret;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool Readline::interactive_mode (const std::istream& in)
|
||||
{
|
||||
return (&in == &std::cin && isatty(0) == 1);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
Wordexp::Wordexp (const std::string &str)
|
||||
{
|
||||
|
|
|
@ -49,6 +49,7 @@ class Readline
|
|||
{
|
||||
public:
|
||||
static std::string gets (const std::string& prompt);
|
||||
static bool interactive_mode (const std::istream& in);
|
||||
|
||||
private:
|
||||
// No construction or destruction.
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
|
||||
#define L10N // Localization complete.
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
#include <stdlib.h>
|
||||
|
@ -63,82 +64,133 @@ int main (int argc, const char** argv)
|
|||
#endif
|
||||
|
||||
int status = 0;
|
||||
bool read_from_file = false;
|
||||
|
||||
if (argc == 2 && !strcmp (argv[1], "--version"))
|
||||
if (argc > 2)
|
||||
{
|
||||
std::cout << VERSION << "\n";
|
||||
std::cout << STRING_SHELL_USAGE << "\n";
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
else if (argc == 2)
|
||||
{
|
||||
if (argc > 1)
|
||||
if (!strcmp (argv[1], "--version"))
|
||||
{
|
||||
std::cerr << STRING_SHELL_UNKOWN_OPTION << argv[1] << "\n";
|
||||
std::cout << VERSION << "\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Begining initilaization
|
||||
status = context.initialize (0, NULL);
|
||||
|
||||
// Display some kind of welcome message.
|
||||
Color bold (Color::nocolor, Color::nocolor, false, true, false);
|
||||
std::cout << (context.color () ? bold.colorize (PACKAGE_STRING) : PACKAGE_STRING)
|
||||
<< " shell\n\n"
|
||||
<< STRING_CMD_SHELL_HELP1 << "\n"
|
||||
<< STRING_CMD_SHELL_HELP2 << "\n"
|
||||
<< STRING_CMD_SHELL_HELP3 << "\n\n";
|
||||
|
||||
// Make a copy because context.clear will delete them.
|
||||
std::string permanent_overrides;
|
||||
std::vector <Arg>::iterator i;
|
||||
for (i = context.a3.begin (); i != context.a3.end (); ++i)
|
||||
else if (!strcmp (argv[1], "--help"))
|
||||
{
|
||||
if (i->_category == Arg::cat_rc ||
|
||||
i->_category == Arg::cat_override)
|
||||
{
|
||||
if (i != context.a3.begin ())
|
||||
permanent_overrides += " ";
|
||||
|
||||
permanent_overrides += i->_raw;
|
||||
std::cout << STRING_SHELL_USAGE << "\n";
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
// The user has give tasksh a task commands file to execute
|
||||
File input_file = File (argv[1]);
|
||||
if (!input_file.exists ()) {
|
||||
std::cout << STRING_SHELL_NO_FILE;
|
||||
std::cout << STRING_SHELL_USAGE << "\n";
|
||||
return -1;
|
||||
}
|
||||
|
||||
read_from_file = true;
|
||||
}
|
||||
}
|
||||
|
||||
std::string input, prompt(context.config.get ("shell.prompt") + " ");
|
||||
// if a file is given, read from it
|
||||
std::ifstream fin;
|
||||
if (read_from_file) {
|
||||
fin.open(argv[1]);
|
||||
}
|
||||
|
||||
std::vector <std::string> quit_commands;
|
||||
quit_commands.push_back ("quit");
|
||||
quit_commands.push_back ("exit");
|
||||
quit_commands.push_back ("bye");
|
||||
// commands may be redirected too
|
||||
std::istream &in = read_from_file ? fin : std::cin;
|
||||
|
||||
// The event loop.
|
||||
while (1)
|
||||
// Begining initilaization
|
||||
status = context.initialize (0, NULL);
|
||||
|
||||
// Display some kind of welcome message.
|
||||
Color bold (Color::nocolor, Color::nocolor, false, true, false);
|
||||
|
||||
std::cout << (context.color () ? bold.colorize (PACKAGE_STRING) : PACKAGE_STRING)
|
||||
<< " shell\n\n"
|
||||
<< STRING_CMD_SHELL_HELP1 << "\n"
|
||||
<< STRING_CMD_SHELL_HELP2 << "\n"
|
||||
<< STRING_CMD_SHELL_HELP3 << "\n\n";
|
||||
|
||||
// Make a copy because context.clear will delete them.
|
||||
std::string permanent_overrides;
|
||||
std::vector <Arg>::iterator i;
|
||||
for (i = context.a3.begin (); i != context.a3.end (); ++i)
|
||||
{
|
||||
if (i->_category == Arg::cat_rc ||
|
||||
i->_category == Arg::cat_override)
|
||||
{
|
||||
context.clear ();
|
||||
if (i != context.a3.begin ())
|
||||
permanent_overrides += " ";
|
||||
|
||||
permanent_overrides += i->_raw;
|
||||
}
|
||||
}
|
||||
|
||||
std::string input;
|
||||
|
||||
std::vector <std::string> quit_commands;
|
||||
quit_commands.push_back ("quit");
|
||||
quit_commands.push_back ("exit");
|
||||
quit_commands.push_back ("bye");
|
||||
|
||||
// The event loop.
|
||||
while (in)
|
||||
{
|
||||
std::string prompt(context.config.get ("shell.prompt") + " ");
|
||||
context.clear ();
|
||||
|
||||
if (Readline::interactive_mode(in))
|
||||
{
|
||||
input = Readline::gets (prompt);
|
||||
if (std::find (quit_commands.begin (), quit_commands.end (),
|
||||
lowerCase (input)) != quit_commands.end ())
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::getline (in, input);
|
||||
|
||||
try
|
||||
{
|
||||
Wordexp w ("task " + trim (input + permanent_overrides));
|
||||
status = context.initialize (w.argc (), (const char**)w.argv ());
|
||||
if (status == 0)
|
||||
status = context.run ();
|
||||
// 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
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
catch (const std::string& error)
|
||||
{
|
||||
std::cerr << error << "\n";
|
||||
status = -1;
|
||||
break;
|
||||
}
|
||||
status = context.initialize (w.argc (), (const char**)w.argv ());
|
||||
if (status == 0)
|
||||
status = context.run ();
|
||||
}
|
||||
|
||||
catch (...)
|
||||
{
|
||||
std::cerr << STRING_UNKNOWN_ERROR << "\n";
|
||||
status = -2;
|
||||
break;
|
||||
}
|
||||
catch (const std::string& error)
|
||||
{
|
||||
std::cerr << error << "\n";
|
||||
status = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
catch (...)
|
||||
{
|
||||
std::cerr << STRING_UNKNOWN_ERROR << "\n";
|
||||
status = -2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -42,12 +42,12 @@ if (open my $fh, '>', 'shell.rc')
|
|||
}
|
||||
|
||||
# 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');
|
||||
|
||||
# Test a simple add, then info.
|
||||
qx{echo "add foo" | ../src/task rc:shell.rc shell 2>&1};
|
||||
$output = qx{echo "1 info" | ../src/task rc:shell.rc shell 2>&1};
|
||||
qx{echo "rc:shell.rc add foo" | ../src/shell/tasksh 2>&1};
|
||||
$output = qx{echo "rc:shell.rc 1 info" | ../src/shell/tasksh 2>&1};
|
||||
like ($output, qr/Description\s+foo/, 'add/info working');
|
||||
|
||||
unlink 'shell.rc';
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue