Václav Kubernát | 24df80e | 2018-06-06 15:18:03 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 CESNET, https://photonics.cesnet.cz/ |
| 3 | * Copyright (C) 2018 FIT CVUT, https://fit.cvut.cz/ |
| 4 | * |
| 5 | * Written by Václav Kubernát <kubervac@fit.cvut.cz> |
| 6 | * |
| 7 | */ |
| 8 | #pragma once |
| 9 | |
Václav Kubernát | 5727242 | 2019-02-08 12:48:24 +0100 | [diff] [blame] | 10 | #include <boost/mpl/vector.hpp> |
Václav Kubernát | 509ce65 | 2019-05-29 19:46:44 +0200 | [diff] [blame] | 11 | #include <boost/spirit/home/x3/support/ast/position_tagged.hpp> |
Václav Kubernát | 24df80e | 2018-06-06 15:18:03 +0200 | [diff] [blame] | 12 | #include "ast_path.hpp" |
Václav Kubernát | 627f615 | 2018-08-29 13:23:56 +0200 | [diff] [blame] | 13 | #include "ast_values.hpp" |
Václav Kubernát | 162165e | 2021-02-22 09:46:53 +0100 | [diff] [blame] | 14 | #include "datastore_access.hpp" |
Václav Kubernát | 6a7dd4d | 2020-06-23 22:44:13 +0200 | [diff] [blame] | 15 | #include "yang_operations.hpp" |
Václav Kubernát | 24df80e | 2018-06-06 15:18:03 +0200 | [diff] [blame] | 16 | |
| 17 | namespace x3 = boost::spirit::x3; |
Václav Kubernát | 24df80e | 2018-06-06 15:18:03 +0200 | [diff] [blame] | 18 | |
Václav Kubernát | 7707cae | 2020-01-16 12:04:53 +0100 | [diff] [blame] | 19 | using keyValue_ = std::pair<std::string, leaf_data_>; |
Václav Kubernát | 24df80e | 2018-06-06 15:18:03 +0200 | [diff] [blame] | 20 | |
Václav Kubernát | e7d4aea | 2018-09-11 18:15:48 +0200 | [diff] [blame] | 21 | enum class LsOption { |
| 22 | Recursive |
| 23 | }; |
| 24 | |
Václav Kubernát | 6d79143 | 2018-10-25 16:00:35 +0200 | [diff] [blame] | 25 | struct discard_ : x3::position_tagged { |
Václav Kubernát | 5727242 | 2019-02-08 12:48:24 +0100 | [diff] [blame] | 26 | static constexpr auto name = "discard"; |
Václav Kubernát | 054cc99 | 2019-02-21 14:23:52 +0100 | [diff] [blame] | 27 | static constexpr auto shortHelp = "discard - Discard current changes."; |
| 28 | static constexpr auto longHelp = R"( |
| 29 | discard |
| 30 | |
| 31 | Discards current changes. Accepts no arguments. |
| 32 | |
| 33 | Usage: |
| 34 | /> discard)"; |
Václav Kubernát | 6d79143 | 2018-10-25 16:00:35 +0200 | [diff] [blame] | 35 | bool operator==(const discard_& b) const; |
| 36 | }; |
| 37 | |
Václav Kubernát | 11afac7 | 2018-07-18 14:59:53 +0200 | [diff] [blame] | 38 | struct ls_ : x3::position_tagged { |
Václav Kubernát | 5727242 | 2019-02-08 12:48:24 +0100 | [diff] [blame] | 39 | static constexpr auto name = "ls"; |
Václav Kubernát | 054cc99 | 2019-02-21 14:23:52 +0100 | [diff] [blame] | 40 | static constexpr auto shortHelp = "ls - List available nodes."; |
| 41 | static constexpr auto longHelp = R"( |
| 42 | ls [--recursive] [path] |
| 43 | |
Václav Kubernát | 419d917 | 2020-11-30 01:20:28 +0100 | [diff] [blame] | 44 | Lists available child nodes in the current context node. Optionally accepts |
| 45 | a path argument. Accepts both schema paths and data paths. Path starting |
| 46 | with a forward slash means an absolute path. |
| 47 | |
| 48 | Options: |
| 49 | --recursive makes `ls` work recursively |
Václav Kubernát | 054cc99 | 2019-02-21 14:23:52 +0100 | [diff] [blame] | 50 | |
| 51 | Usage: |
| 52 | /> ls |
| 53 | /> ls --recursive module:node |
| 54 | /> ls /module:node)"; |
Václav Kubernát | 11afac7 | 2018-07-18 14:59:53 +0200 | [diff] [blame] | 55 | bool operator==(const ls_& b) const; |
Václav Kubernát | e7d4aea | 2018-09-11 18:15:48 +0200 | [diff] [blame] | 56 | std::vector<LsOption> m_options; |
Václav Kubernát | beaa8aa | 2020-04-29 22:39:34 +0200 | [diff] [blame] | 57 | boost::optional<boost::variant<dataPath_, schemaPath_, module_>> m_path; |
Václav Kubernát | 11afac7 | 2018-07-18 14:59:53 +0200 | [diff] [blame] | 58 | }; |
| 59 | |
Václav Kubernát | 24df80e | 2018-06-06 15:18:03 +0200 | [diff] [blame] | 60 | struct cd_ : x3::position_tagged { |
Václav Kubernát | 5727242 | 2019-02-08 12:48:24 +0100 | [diff] [blame] | 61 | static constexpr auto name = "cd"; |
Václav Kubernát | 054cc99 | 2019-02-21 14:23:52 +0100 | [diff] [blame] | 62 | static constexpr auto shortHelp = "cd - Enter a different node."; |
| 63 | static constexpr auto longHelp = R"( |
Václav Kubernát | 419d917 | 2020-11-30 01:20:28 +0100 | [diff] [blame] | 64 | cd <path> |
Václav Kubernát | 054cc99 | 2019-02-21 14:23:52 +0100 | [diff] [blame] | 65 | |
Václav Kubernát | 419d917 | 2020-11-30 01:20:28 +0100 | [diff] [blame] | 66 | Changes context to a node specified by <path>. Only accepts data paths |
| 67 | (paths with all list keys supplied). |
Václav Kubernát | 054cc99 | 2019-02-21 14:23:52 +0100 | [diff] [blame] | 68 | |
| 69 | Usage: |
| 70 | /> cd /module:node/node2 |
| 71 | /> cd ..)"; |
Václav Kubernát | 24df80e | 2018-06-06 15:18:03 +0200 | [diff] [blame] | 72 | bool operator==(const cd_& b) const; |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 73 | dataPath_ m_path; |
Václav Kubernát | 24df80e | 2018-06-06 15:18:03 +0200 | [diff] [blame] | 74 | }; |
| 75 | |
| 76 | struct create_ : x3::position_tagged { |
Václav Kubernát | 5727242 | 2019-02-08 12:48:24 +0100 | [diff] [blame] | 77 | static constexpr auto name = "create"; |
Václav Kubernát | 419d917 | 2020-11-30 01:20:28 +0100 | [diff] [blame] | 78 | static constexpr auto shortHelp = "create - Create a node."; |
Václav Kubernát | 054cc99 | 2019-02-21 14:23:52 +0100 | [diff] [blame] | 79 | static constexpr auto longHelp = R"( |
Václav Kubernát | 419d917 | 2020-11-30 01:20:28 +0100 | [diff] [blame] | 80 | create <path> |
Václav Kubernát | 054cc99 | 2019-02-21 14:23:52 +0100 | [diff] [blame] | 81 | |
Václav Kubernát | 419d917 | 2020-11-30 01:20:28 +0100 | [diff] [blame] | 82 | Creates a node specified by <path>. |
| 83 | Supported node types are list items, leaflist instance and presence |
| 84 | containers. |
Václav Kubernát | 054cc99 | 2019-02-21 14:23:52 +0100 | [diff] [blame] | 85 | |
| 86 | Usage: |
Václav Kubernát | f5f64f0 | 2019-03-19 17:15:47 +0100 | [diff] [blame] | 87 | /> create /module:pContainer |
Václav Kubernát | 419d917 | 2020-11-30 01:20:28 +0100 | [diff] [blame] | 88 | /> create /module:leafList['value'] |
Václav Kubernát | f5f64f0 | 2019-03-19 17:15:47 +0100 | [diff] [blame] | 89 | /> create /module:list[key=value][anotherKey=value])"; |
Václav Kubernát | 24df80e | 2018-06-06 15:18:03 +0200 | [diff] [blame] | 90 | bool operator==(const create_& b) const; |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 91 | dataPath_ m_path; |
Václav Kubernát | 24df80e | 2018-06-06 15:18:03 +0200 | [diff] [blame] | 92 | }; |
| 93 | |
| 94 | struct delete_ : x3::position_tagged { |
Václav Kubernát | 5727242 | 2019-02-08 12:48:24 +0100 | [diff] [blame] | 95 | static constexpr auto name = "delete"; |
Václav Kubernát | 419d917 | 2020-11-30 01:20:28 +0100 | [diff] [blame] | 96 | static constexpr auto shortHelp = "delete - Delete a node."; |
Václav Kubernát | 054cc99 | 2019-02-21 14:23:52 +0100 | [diff] [blame] | 97 | static constexpr auto longHelp = R"( |
Václav Kubernát | 419d917 | 2020-11-30 01:20:28 +0100 | [diff] [blame] | 98 | delete <path> |
Václav Kubernát | 054cc99 | 2019-02-21 14:23:52 +0100 | [diff] [blame] | 99 | |
Václav Kubernát | 419d917 | 2020-11-30 01:20:28 +0100 | [diff] [blame] | 100 | Deletes a node specified by <path>. |
| 101 | Supported node types are leafs, list items, leaflist instance and presence |
| 102 | containers. |
Václav Kubernát | 054cc99 | 2019-02-21 14:23:52 +0100 | [diff] [blame] | 103 | |
| 104 | Usage: |
Václav Kubernát | f5f64f0 | 2019-03-19 17:15:47 +0100 | [diff] [blame] | 105 | /> delete /module:pContainer |
Václav Kubernát | 419d917 | 2020-11-30 01:20:28 +0100 | [diff] [blame] | 106 | /> delete /module:leafList['value'] |
Václav Kubernát | f5f64f0 | 2019-03-19 17:15:47 +0100 | [diff] [blame] | 107 | /> delete /module:list[key=value][anotherKey=value])"; |
Václav Kubernát | 24df80e | 2018-06-06 15:18:03 +0200 | [diff] [blame] | 108 | bool operator==(const delete_& b) const; |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 109 | dataPath_ m_path; |
Václav Kubernát | 24df80e | 2018-06-06 15:18:03 +0200 | [diff] [blame] | 110 | }; |
| 111 | |
| 112 | struct set_ : x3::position_tagged { |
Václav Kubernát | 5727242 | 2019-02-08 12:48:24 +0100 | [diff] [blame] | 113 | static constexpr auto name = "set"; |
Václav Kubernát | 419d917 | 2020-11-30 01:20:28 +0100 | [diff] [blame] | 114 | static constexpr auto shortHelp = "set - Set value of a leaf."; |
Václav Kubernát | 054cc99 | 2019-02-21 14:23:52 +0100 | [diff] [blame] | 115 | static constexpr auto longHelp = R"( |
Václav Kubernát | 419d917 | 2020-11-30 01:20:28 +0100 | [diff] [blame] | 116 | set <path_to_leaf> <value> |
Václav Kubernát | 054cc99 | 2019-02-21 14:23:52 +0100 | [diff] [blame] | 117 | |
Václav Kubernát | 419d917 | 2020-11-30 01:20:28 +0100 | [diff] [blame] | 118 | Sets the leaf specified by <path_to_leaf> to <value>. |
Václav Kubernát | 054cc99 | 2019-02-21 14:23:52 +0100 | [diff] [blame] | 119 | |
| 120 | Usage: |
| 121 | /> set /module:leaf 123 |
| 122 | /> set /module:leaf abc)"; |
Václav Kubernát | 24df80e | 2018-06-06 15:18:03 +0200 | [diff] [blame] | 123 | bool operator==(const set_& b) const; |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 124 | dataPath_ m_path; |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 125 | leaf_data_ m_data; |
Václav Kubernát | 24df80e | 2018-06-06 15:18:03 +0200 | [diff] [blame] | 126 | }; |
| 127 | |
Václav Kubernát | 812ee28 | 2018-08-30 17:10:03 +0200 | [diff] [blame] | 128 | struct commit_ : x3::position_tagged { |
Václav Kubernát | 5727242 | 2019-02-08 12:48:24 +0100 | [diff] [blame] | 129 | static constexpr auto name = "commit"; |
Václav Kubernát | 054cc99 | 2019-02-21 14:23:52 +0100 | [diff] [blame] | 130 | static constexpr auto shortHelp = "commit - Commit current changes."; |
| 131 | static constexpr auto longHelp = R"( |
| 132 | commit |
| 133 | |
| 134 | Commits the current changes. Accepts no arguments. |
| 135 | |
| 136 | Usage: |
| 137 | /> commit)"; |
Václav Kubernát | 812ee28 | 2018-08-30 17:10:03 +0200 | [diff] [blame] | 138 | }; |
| 139 | |
Václav Kubernát | b6ff0b6 | 2018-08-30 16:14:53 +0200 | [diff] [blame] | 140 | struct get_ : x3::position_tagged { |
Václav Kubernát | 5727242 | 2019-02-08 12:48:24 +0100 | [diff] [blame] | 141 | static constexpr auto name = "get"; |
Václav Kubernát | 054cc99 | 2019-02-21 14:23:52 +0100 | [diff] [blame] | 142 | static constexpr auto shortHelp = "get - Retrieve configuration from the server."; |
| 143 | static constexpr auto longHelp = R"( |
| 144 | get [path] |
| 145 | |
Václav Kubernát | 419d917 | 2020-11-30 01:20:28 +0100 | [diff] [blame] | 146 | Prints out content of the current datastore at a specified [path], or below |
| 147 | the current context tree. |
Václav Kubernát | 054cc99 | 2019-02-21 14:23:52 +0100 | [diff] [blame] | 148 | |
| 149 | Usage: |
| 150 | /> get |
| 151 | /> get /module:path)"; |
Václav Kubernát | b6ff0b6 | 2018-08-30 16:14:53 +0200 | [diff] [blame] | 152 | bool operator==(const get_& b) const; |
Václav Kubernát | 8f6bff3 | 2020-06-10 14:51:10 +0200 | [diff] [blame] | 153 | boost::optional<boost::variant<dataPath_, module_>> m_path; |
Václav Kubernát | b6ff0b6 | 2018-08-30 16:14:53 +0200 | [diff] [blame] | 154 | }; |
Václav Kubernát | 812ee28 | 2018-08-30 17:10:03 +0200 | [diff] [blame] | 155 | |
Václav Kubernát | 9cfcd87 | 2020-02-18 12:34:02 +0100 | [diff] [blame] | 156 | struct describe_ : x3::position_tagged { |
| 157 | static constexpr auto name = "describe"; |
| 158 | static constexpr auto shortHelp = "describe - Print information about YANG tree path."; |
| 159 | static constexpr auto longHelp = R"( |
| 160 | describe <path> |
| 161 | |
Václav Kubernát | 419d917 | 2020-11-30 01:20:28 +0100 | [diff] [blame] | 162 | Shows documentation of YANG tree paths. In the YANG model, each item may |
Václav Kubernát | 9cfcd87 | 2020-02-18 12:34:02 +0100 | [diff] [blame] | 163 | have an optional `description` which often explains the function of that |
Václav Kubernát | 419d917 | 2020-11-30 01:20:28 +0100 | [diff] [blame] | 164 | node to the end user. This command takes the description from the YANG model |
| 165 | and shows it to the user along with additional data, such as the type of the |
| 166 | node, units of leaf values, etc. |
Václav Kubernát | 9cfcd87 | 2020-02-18 12:34:02 +0100 | [diff] [blame] | 167 | |
| 168 | Usage: |
| 169 | /> describe /module:node)"; |
| 170 | bool operator==(const describe_& b) const; |
| 171 | |
| 172 | boost::variant<schemaPath_, dataPath_> m_path; |
| 173 | }; |
| 174 | |
Václav Kubernát | 7160a13 | 2020-04-03 02:11:01 +0200 | [diff] [blame] | 175 | struct copy_ : x3::position_tagged { |
| 176 | static constexpr auto name = "copy"; |
Václav Kubernát | 419d917 | 2020-11-30 01:20:28 +0100 | [diff] [blame] | 177 | static constexpr auto shortHelp = "copy - Copy configuration."; |
Václav Kubernát | 7160a13 | 2020-04-03 02:11:01 +0200 | [diff] [blame] | 178 | static constexpr auto longHelp = R"( |
| 179 | copy <source> <destination> |
| 180 | |
Václav Kubernát | 419d917 | 2020-11-30 01:20:28 +0100 | [diff] [blame] | 181 | Copies configuration from <source> to <destination>. |
| 182 | |
Václav Kubernát | 7160a13 | 2020-04-03 02:11:01 +0200 | [diff] [blame] | 183 | Usage: |
| 184 | /> copy running startup |
| 185 | /> copy startup running)"; |
| 186 | bool operator==(const copy_& b) const; |
| 187 | |
| 188 | Datastore m_source; |
| 189 | Datastore m_destination; |
| 190 | }; |
| 191 | |
Václav Kubernát | bf65dd7 | 2020-05-28 02:32:31 +0200 | [diff] [blame] | 192 | enum class MoveMode { |
| 193 | Begin, |
| 194 | End, |
| 195 | Before, |
| 196 | After |
| 197 | }; |
| 198 | |
| 199 | struct move_ : x3::position_tagged { |
| 200 | static constexpr auto name = "move"; |
Václav Kubernát | 419d917 | 2020-11-30 01:20:28 +0100 | [diff] [blame] | 201 | static constexpr auto shortHelp = "move - Move (leaf)list instances."; |
Václav Kubernát | bf65dd7 | 2020-05-28 02:32:31 +0200 | [diff] [blame] | 202 | static constexpr auto longHelp = R"( |
Václav Kubernát | 419d917 | 2020-11-30 01:20:28 +0100 | [diff] [blame] | 203 | move <path> begin |
| 204 | move <path> end |
| 205 | move <path> before <key> |
| 206 | move <path> after <key> |
| 207 | |
| 208 | Moves the instance specified by <path> to the position specified by the |
| 209 | specified by the second and third argument. |
Václav Kubernát | bf65dd7 | 2020-05-28 02:32:31 +0200 | [diff] [blame] | 210 | |
| 211 | Usage: |
| 212 | /> move mod:leaflist['abc'] begin |
| 213 | /> move mod:leaflist['def'] after 'abc' |
Václav Kubernát | 419d917 | 2020-11-30 01:20:28 +0100 | [diff] [blame] | 214 | /> move mod:interfaces[name='eth0'] after [name='eth1'])"; |
Václav Kubernát | bf65dd7 | 2020-05-28 02:32:31 +0200 | [diff] [blame] | 215 | bool operator==(const move_& b) const; |
| 216 | |
| 217 | dataPath_ m_source; |
| 218 | |
| 219 | std::variant<yang::move::Absolute, yang::move::Relative> m_destination; |
| 220 | }; |
| 221 | |
Václav Kubernát | 70d7f7a | 2020-06-23 14:40:40 +0200 | [diff] [blame] | 222 | struct dump_ : x3::position_tagged { |
| 223 | static constexpr auto name = "dump"; |
Václav Kubernát | 419d917 | 2020-11-30 01:20:28 +0100 | [diff] [blame] | 224 | static constexpr auto shortHelp = "dump - Print out datastore content as JSON or XML."; |
Václav Kubernát | 70d7f7a | 2020-06-23 14:40:40 +0200 | [diff] [blame] | 225 | static constexpr auto longHelp = R"( |
| 226 | dump xml|json |
| 227 | |
Václav Kubernát | 419d917 | 2020-11-30 01:20:28 +0100 | [diff] [blame] | 228 | Prints out the content of the datastore. Supports JSON and XML. |
| 229 | |
Václav Kubernát | 70d7f7a | 2020-06-23 14:40:40 +0200 | [diff] [blame] | 230 | Usage: |
| 231 | /> dump xml |
| 232 | /> dump json)"; |
| 233 | bool operator==(const dump_& other) const; |
| 234 | |
| 235 | DataFormat m_format; |
| 236 | }; |
| 237 | |
Václav Kubernát | aa4250a | 2020-07-22 00:02:23 +0200 | [diff] [blame] | 238 | struct prepare_ : x3::position_tagged { |
| 239 | static constexpr auto name = "prepare"; |
Václav Kubernát | 419d917 | 2020-11-30 01:20:28 +0100 | [diff] [blame] | 240 | static constexpr auto shortHelp = "prepare - Initiate RPC/action."; |
Václav Kubernát | e7248b2 | 2020-06-26 15:38:59 +0200 | [diff] [blame] | 241 | static constexpr auto longHelp = R"( |
Václav Kubernát | aa4250a | 2020-07-22 00:02:23 +0200 | [diff] [blame] | 242 | prepare <path-to-rpc-or-action> |
Václav Kubernát | e7248b2 | 2020-06-26 15:38:59 +0200 | [diff] [blame] | 243 | |
Václav Kubernát | 419d917 | 2020-11-30 01:20:28 +0100 | [diff] [blame] | 244 | This command enters a mode for entering input parameters for the RPC/action. |
| 245 | In this mode, you can use commands like `set` on nodes inside the RPC/action |
| 246 | to set the input. After setting the input, use `exec` to execute the |
| 247 | RPC/action. |
Václav Kubernát | e7248b2 | 2020-06-26 15:38:59 +0200 | [diff] [blame] | 248 | |
| 249 | Usage: |
Václav Kubernát | 419d917 | 2020-11-30 01:20:28 +0100 | [diff] [blame] | 250 | /> prepare /mod:launch-nukes |
| 251 | /> set kilotons 1000 |
| 252 | /> exec)"; |
Václav Kubernát | aa4250a | 2020-07-22 00:02:23 +0200 | [diff] [blame] | 253 | bool operator==(const prepare_& other) const; |
Václav Kubernát | e7248b2 | 2020-06-26 15:38:59 +0200 | [diff] [blame] | 254 | |
| 255 | dataPath_ m_path; |
| 256 | }; |
| 257 | |
| 258 | struct exec_ : x3::position_tagged { |
| 259 | static constexpr auto name = "exec"; |
Václav Kubernát | 419d917 | 2020-11-30 01:20:28 +0100 | [diff] [blame] | 260 | static constexpr auto shortHelp = "exec - Execute RPC/action."; |
Václav Kubernát | e7248b2 | 2020-06-26 15:38:59 +0200 | [diff] [blame] | 261 | static constexpr auto longHelp = R"( |
Václav Kubernát | d8408e0 | 2020-12-02 05:13:27 +0100 | [diff] [blame] | 262 | exec [path] |
Václav Kubernát | e7248b2 | 2020-06-26 15:38:59 +0200 | [diff] [blame] | 263 | |
Václav Kubernát | 419d917 | 2020-11-30 01:20:28 +0100 | [diff] [blame] | 264 | This command executes the RPC/action you have previously initiated via the |
| 265 | `prepare` command. |
Václav Kubernát | e7248b2 | 2020-06-26 15:38:59 +0200 | [diff] [blame] | 266 | |
Václav Kubernát | d8408e0 | 2020-12-02 05:13:27 +0100 | [diff] [blame] | 267 | If the RPC/action has no input parameters, it can be directly execute via |
| 268 | `exec` without usgin `prepare`. |
| 269 | |
Václav Kubernát | e7248b2 | 2020-06-26 15:38:59 +0200 | [diff] [blame] | 270 | Usage: |
Václav Kubernát | d8408e0 | 2020-12-02 05:13:27 +0100 | [diff] [blame] | 271 | /> exec |
| 272 | /> exec /mod:myRpc)"; |
Václav Kubernát | e7248b2 | 2020-06-26 15:38:59 +0200 | [diff] [blame] | 273 | bool operator==(const exec_& other) const; |
Václav Kubernát | d8408e0 | 2020-12-02 05:13:27 +0100 | [diff] [blame] | 274 | |
| 275 | boost::optional<dataPath_> m_path; |
Václav Kubernát | e7248b2 | 2020-06-26 15:38:59 +0200 | [diff] [blame] | 276 | }; |
| 277 | |
| 278 | struct cancel_ : x3::position_tagged { |
| 279 | static constexpr auto name = "cancel"; |
Václav Kubernát | 419d917 | 2020-11-30 01:20:28 +0100 | [diff] [blame] | 280 | static constexpr auto shortHelp = "cancel - Cancel an ongoing RPC/action input."; |
Václav Kubernát | e7248b2 | 2020-06-26 15:38:59 +0200 | [diff] [blame] | 281 | static constexpr auto longHelp = R"( |
| 282 | cancel |
| 283 | |
Václav Kubernát | 419d917 | 2020-11-30 01:20:28 +0100 | [diff] [blame] | 284 | This command cancels a previously entered RPC/action context. |
Václav Kubernát | e7248b2 | 2020-06-26 15:38:59 +0200 | [diff] [blame] | 285 | |
| 286 | Usage: |
| 287 | /> cancel)"; |
| 288 | bool operator==(const cancel_& other) const; |
| 289 | }; |
| 290 | |
Václav Kubernát | 162165e | 2021-02-22 09:46:53 +0100 | [diff] [blame] | 291 | struct switch_ : x3::position_tagged { |
| 292 | static constexpr auto name = "switch"; |
| 293 | static constexpr auto shortHelp = "switch - Switch datastore target."; |
| 294 | static constexpr auto longHelp = R"( |
| 295 | switch <target> |
| 296 | |
| 297 | This command switches the datastore target. Available targets are: |
| 298 | |
| 299 | operational: |
| 300 | - reads from operational, writes to running |
| 301 | startup: |
| 302 | - reads from startup, writes to startup |
| 303 | running: |
| 304 | - reads from running, writes to running |
| 305 | |
| 306 | |
| 307 | Usage: |
| 308 | /> switch running |
| 309 | /> switch startup |
| 310 | /> switch operational)"; |
| 311 | bool operator==(const switch_& other) const; |
| 312 | DatastoreTarget m_target; |
| 313 | }; |
| 314 | |
Václav Kubernát | 054cc99 | 2019-02-21 14:23:52 +0100 | [diff] [blame] | 315 | struct help_; |
Václav Kubernát | 162165e | 2021-02-22 09:46:53 +0100 | [diff] [blame] | 316 | using CommandTypes = boost::mpl::vector<cancel_, cd_, commit_, copy_, create_, delete_, describe_, discard_, dump_, exec_, get_, help_, ls_, move_, prepare_, set_, switch_>; |
Václav Kubernát | 054cc99 | 2019-02-21 14:23:52 +0100 | [diff] [blame] | 317 | struct help_ : x3::position_tagged { |
| 318 | static constexpr auto name = "help"; |
| 319 | static constexpr auto shortHelp = "help - Print help for commands."; |
| 320 | static constexpr auto longHelp = R"( |
| 321 | help [command_name] |
| 322 | |
| 323 | Print help for command_name. If used without an argument, |
| 324 | print short help for all commands. |
| 325 | |
| 326 | Usage: |
| 327 | /> help |
| 328 | /> help cd |
| 329 | /> help help)"; |
| 330 | bool operator==(const help_& b) const; |
| 331 | |
| 332 | // The help command has got one optional argument – a command name (type). |
| 333 | // All commands are saved in CommandTypes, so we could just use that, but |
| 334 | // that way, Spirit would be default constructing the command structs, |
| 335 | // which is undesirable, so firstly we use mpl::transform to wrap |
| 336 | // CommandTypes with boost::type: |
| 337 | using WrappedCommandTypes = boost::mpl::transform<CommandTypes, boost::type<boost::mpl::_>>::type; |
| 338 | // Next, we create a variant over the wrapped types: |
| 339 | using CommandTypesVariant = boost::make_variant_over<WrappedCommandTypes>::type; |
| 340 | // Finally, we wrap the variant with boost::optional: |
| 341 | boost::optional<CommandTypesVariant> m_cmd; |
| 342 | }; |
| 343 | |
Václav Kubernát | 5727242 | 2019-02-08 12:48:24 +0100 | [diff] [blame] | 344 | // TODO: The usage of MPL won't be necessary after std::variant support is added to Spirit |
| 345 | // https://github.com/boostorg/spirit/issues/270 |
Václav Kubernát | 5727242 | 2019-02-08 12:48:24 +0100 | [diff] [blame] | 346 | using command_ = boost::make_variant_over<CommandTypes>::type; |
Václav Kubernát | 24df80e | 2018-06-06 15:18:03 +0200 | [diff] [blame] | 347 | |
Václav Kubernát | e7d4aea | 2018-09-11 18:15:48 +0200 | [diff] [blame] | 348 | BOOST_FUSION_ADAPT_STRUCT(ls_, m_options, m_path) |
Václav Kubernát | 24df80e | 2018-06-06 15:18:03 +0200 | [diff] [blame] | 349 | BOOST_FUSION_ADAPT_STRUCT(cd_, m_path) |
| 350 | BOOST_FUSION_ADAPT_STRUCT(create_, m_path) |
| 351 | BOOST_FUSION_ADAPT_STRUCT(delete_, m_path) |
Václav Kubernát | 24df80e | 2018-06-06 15:18:03 +0200 | [diff] [blame] | 352 | BOOST_FUSION_ADAPT_STRUCT(set_, m_path, m_data) |
Václav Kubernát | ab53899 | 2019-03-06 15:30:50 +0100 | [diff] [blame] | 353 | BOOST_FUSION_ADAPT_STRUCT(enum_, m_value) |
Václav Kubernát | dab73ca | 2020-10-26 23:44:43 +0100 | [diff] [blame] | 354 | BOOST_FUSION_ADAPT_STRUCT(bits_, m_bits) |
Václav Kubernát | ab53899 | 2019-03-06 15:30:50 +0100 | [diff] [blame] | 355 | BOOST_FUSION_ADAPT_STRUCT(binary_, m_value) |
Václav Kubernát | eeb3884 | 2019-03-20 19:46:05 +0100 | [diff] [blame] | 356 | BOOST_FUSION_ADAPT_STRUCT(identityRef_, m_prefix, m_value) |
Václav Kubernát | 812ee28 | 2018-08-30 17:10:03 +0200 | [diff] [blame] | 357 | BOOST_FUSION_ADAPT_STRUCT(commit_) |
Václav Kubernát | 9cfcd87 | 2020-02-18 12:34:02 +0100 | [diff] [blame] | 358 | BOOST_FUSION_ADAPT_STRUCT(describe_, m_path) |
Václav Kubernát | 054cc99 | 2019-02-21 14:23:52 +0100 | [diff] [blame] | 359 | BOOST_FUSION_ADAPT_STRUCT(help_, m_cmd) |
Václav Kubernát | 6d79143 | 2018-10-25 16:00:35 +0200 | [diff] [blame] | 360 | BOOST_FUSION_ADAPT_STRUCT(discard_) |
Václav Kubernát | b6ff0b6 | 2018-08-30 16:14:53 +0200 | [diff] [blame] | 361 | BOOST_FUSION_ADAPT_STRUCT(get_, m_path) |
Václav Kubernát | 7160a13 | 2020-04-03 02:11:01 +0200 | [diff] [blame] | 362 | BOOST_FUSION_ADAPT_STRUCT(copy_, m_source, m_destination) |
Václav Kubernát | bf65dd7 | 2020-05-28 02:32:31 +0200 | [diff] [blame] | 363 | BOOST_FUSION_ADAPT_STRUCT(move_, m_source, m_destination) |
Václav Kubernát | 70d7f7a | 2020-06-23 14:40:40 +0200 | [diff] [blame] | 364 | BOOST_FUSION_ADAPT_STRUCT(dump_, m_format) |
Václav Kubernát | aa4250a | 2020-07-22 00:02:23 +0200 | [diff] [blame] | 365 | BOOST_FUSION_ADAPT_STRUCT(prepare_, m_path) |
Václav Kubernát | d8408e0 | 2020-12-02 05:13:27 +0100 | [diff] [blame] | 366 | BOOST_FUSION_ADAPT_STRUCT(exec_, m_path) |
Václav Kubernát | 162165e | 2021-02-22 09:46:53 +0100 | [diff] [blame] | 367 | BOOST_FUSION_ADAPT_STRUCT(switch_, m_target) |