1 //////////////////////////////////////////////////////////////////////////////// 2 // 3 // Copyright 2006 - 2021, Tomas Babej, Paul Beckingham, Federico Hernandez. 4 // 5 // Permission is hereby granted, free of charge, to any person obtaining a copy 6 // of this software and associated documentation files (the "Software"), to deal 7 // in the Software without restriction, including without limitation the rights 8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 // copies of the Software, and to permit persons to whom the Software is 10 // furnished to do so, subject to the following conditions: 11 // 12 // The above copyright notice and this permission notice shall be included 13 // in all copies or substantial portions of the Software. 14 // 15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 // SOFTWARE. 22 // 23 // https://www.opensource.org/licenses/mit-license.php 24 // 25 //////////////////////////////////////////////////////////////////////////////// 26 27 #ifndef INCLUDED_COMMAND 28 #define INCLUDED_COMMAND 29 30 #include <map> 31 #include <vector> 32 #include <string> 33 #include <Task.h> 34 35 class Command 36 { 37 public: 38 enum class Category 39 { 40 unassigned, 41 // In presentation ("usefulness") order: frequently-used categories first. 42 metadata, 43 report, 44 operation, 45 context, 46 graphs, 47 config, 48 migration, 49 misc, 50 internal, 51 UNDOCUMENTED, 52 // Whenever you extend this enum, update categoryNames. 53 }; 54 55 Command (); 56 virtual ~Command () = default; 57 58 static void factory (std::map <std::string, Command*>&); 59 60 std::string keyword () const; 61 std::string usage () const; 62 std::string description () const; 63 bool read_only () const; 64 bool displays_id () const; 65 bool needs_gc () const; 66 virtual bool uses_context () const; 67 bool accepts_filter () const; 68 bool accepts_modifications () const; 69 bool accepts_miscellaneous () const; 70 Category category () const; 71 virtual int execute (std::string&) = 0; 72 73 protected: 74 bool permission (const std::string&, unsigned int); 75 static const std::map <Command::Category, std::string> categoryNames; 76 77 protected: 78 std::string _keyword; 79 std::string _usage; 80 std::string _description; 81 bool _read_only; 82 bool _displays_id; 83 bool _needs_confirm; 84 bool _needs_gc; 85 bool _uses_context; 86 bool _accepts_filter; 87 bool _accepts_modifications; 88 bool _accepts_miscellaneous; 89 Category _category; 90 91 // Permission support 92 bool _permission_quit; 93 bool _permission_all; 94 bool _first_iteration; 95 }; 96 97 #endif 98 //////////////////////////////////////////////////////////////////////////////// 99