| 145 | } |
| 146 | |
| 147 | bool process(function<void(FormattedJson const&)> output, |
| 148 | Command const& command, |
| 149 | Options const& options, |
| 150 | FormattedJson const& input) { |
| 151 | if (command.is<GetCommand>()) { |
| 152 | GetCommand const& getCmd = command.get<GetCommand>(); |
| 153 | try { |
| 154 | FormattedJson value = getCmd.path->get(input); |
| 155 | if (getCmd.children) { |
| 156 | forEachChild(value, output); |
| 157 | } else { |
| 158 | output(value); |
| 159 | } |
| 160 | } catch (JsonPath::TraversalException const& e) { |
| 161 | if (!getCmd.opt) |
| 162 | throw e; |
| 163 | } |
| 164 | |
| 165 | } else if (command.is<SetCommand>()) { |
| 166 | SetCommand const& setCmd = command.get<SetCommand>(); |
| 167 | output(addOrSet(false, setCmd.path, input, options.insertLocation, setCmd.value)); |
| 168 | |
| 169 | } else if (command.is<AddCommand>()) { |
| 170 | AddCommand const& addCmd = command.get<AddCommand>(); |
| 171 | output(addOrSet(true, addCmd.path, input, options.insertLocation, addCmd.value)); |
| 172 | |
| 173 | } else if (command.is<RemoveCommand>()) { |
| 174 | output(command.get<RemoveCommand>().path->remove(input)); |
| 175 | |
| 176 | } else { |
| 177 | starAssert(command.empty()); |
| 178 | output(input); |
| 179 | } |
| 180 | return true; |
| 181 | } |
| 182 | |
| 183 | bool process( |
| 184 | function<void(FormattedJson const&)> output, Command const& command, Options const& options, String const& input) { |