From 32cf553d4e780663e86491f6b353c7c48bcd01dd Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Mon, 1 Feb 2016 18:38:14 -0500 Subject: [PATCH] TW-188: short help text - Thanks to David Patrick. --- ChangeLog | 1 + NEWS | 7 +++++-- src/commands/CmdHelp.cpp | 29 +++++++++++++++++++++-------- src/commands/CmdHelp.h | 3 +++ 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index f756250f0..a10f641d8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,7 @@ - TW-38 Dates in the far future give bad estimates in burndown (thanks to Ben Boeckel). +- TW-188 short help text (thanks to David Patrick). - TW-311 Estimated completion in burndown.daily shows impossible results (thanks to Michele Santullo). - TW-1313 some recurring intervals reset due time to midnight diff --git a/NEWS b/NEWS index 41b03a2f8..3aaa93582 100644 --- a/NEWS +++ b/NEWS @@ -1,11 +1,14 @@ New Features in Taskwarrior 2.5.1 - - None, this is a bug-fix, code cleanup and performance release only. + - As a bug-fix, code cleanup and performance release, new features are + limited to only small tweaks. + - The 'help' command now takes a 'usage' argument, which displays only the + command usage. New Commands in Taskwarrior 2.5.1 - - None, this is a bug-fix, code cleanup and performance release only. + - None. New Configuration Options in Taskwarrior 2.5.1 diff --git a/src/commands/CmdHelp.cpp b/src/commands/CmdHelp.cpp index 1ce2f99d0..371c0801a 100644 --- a/src/commands/CmdHelp.cpp +++ b/src/commands/CmdHelp.cpp @@ -32,6 +32,7 @@ #include #include #include +#include // TODO Remove extern Context context; @@ -39,7 +40,7 @@ extern Context context; CmdHelp::CmdHelp () { _keyword = "help"; - _usage = "task help"; + _usage = "task help ['usage']"; _description = STRING_CMD_HELP_USAGE; _read_only = true; _displays_id = false; @@ -47,12 +48,29 @@ CmdHelp::CmdHelp () _uses_context = false; _accepts_filter = false; _accepts_modifications = false; - _accepts_miscellaneous = false; + _accepts_miscellaneous = true; _category = Command::Category::misc; } //////////////////////////////////////////////////////////////////////////////// int CmdHelp::execute (std::string& output) +{ + auto words = context.cli2.getWords (); + if (words.size () == 1 && closeEnough ("usage", words[0])) + output = "\n" + + composeUsage () + + "\n"; + else + output = "\n" + + composeUsage () + + "\n" + + STRING_CMD_HELP_TEXT; + + return 0; +} + +//////////////////////////////////////////////////////////////////////////////// +std::string CmdHelp::composeUsage () const { ViewText view; view.width (context.getWidth ()); @@ -110,12 +128,7 @@ int CmdHelp::execute (std::string& output) } } - output = "\n" - + view.render () - + "\n" - + STRING_CMD_HELP_TEXT; - - return 0; + return view.render (); } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/commands/CmdHelp.h b/src/commands/CmdHelp.h index 889dac873..3808691af 100644 --- a/src/commands/CmdHelp.h +++ b/src/commands/CmdHelp.h @@ -35,6 +35,9 @@ class CmdHelp : public Command public: CmdHelp (); int execute (std::string&); + +private: + std::string composeUsage () const; }; #endif