From 985aab054155cec5db75817b879ae623ce442bca Mon Sep 17 00:00:00 2001 From: Tomas Babej Date: Mon, 22 Mar 2021 00:58:58 -0400 Subject: [PATCH] CmdContext: Define both read and write context --- src/commands/CmdContext.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/commands/CmdContext.cpp b/src/commands/CmdContext.cpp index 88012e4d8..fe251fb4c 100644 --- a/src/commands/CmdContext.cpp +++ b/src/commands/CmdContext.cpp @@ -165,11 +165,18 @@ void CmdContext::defineContext (const std::vector & words, std::str ! confirm (format ("The filter '{1}' matches 0 pending tasks. Do you wish to continue?", value))) throw std::string ("Context definition aborted."); - // Set context definition config variable - bool success = CmdConfig::setConfigVariable (name, value, confirmation); + // TODO: Validate the context as valid for writing and prompt for alternative if invald - if (!success) - throw format ("Context '{1}' not defined.", words[1]); + // Set context definition config variable + bool read_success = CmdConfig::setConfigVariable (name + ".read", value, confirmation); + bool write_success = CmdConfig::setConfigVariable (name + ".write", value, confirmation); + + if (!read_success and !write_success) + throw format ("Context '{1}' not defined (setting read and write failed).", words[1]); + else if (!read_success) + throw format ("Context '{1}' not defined (setting read failed).", words[1]); + else if (!write_success) + throw format ("Context '{1}' not defined (setting write failed).", words[1]); out << format ("Context '{1}' defined. Use 'task context {1}' to activate.\n", words[1]); }