(self, params, **kwargs)
| 222 | return edit_parser |
| 223 | |
| 224 | def execute(self, params, **kwargs): |
| 225 | name = kwargs.get('record') |
| 226 | |
| 227 | if not name: |
| 228 | self.get_parser().print_help() |
| 229 | return |
| 230 | |
| 231 | record_uid = None |
| 232 | if name in params.record_cache: |
| 233 | record_uid = name |
| 234 | else: |
| 235 | rs = try_resolve_path(params, name) |
| 236 | if rs is not None: |
| 237 | folder, name = rs |
| 238 | if folder is not None and name is not None: |
| 239 | folder_uid = folder.uid or '' |
| 240 | if folder_uid in params.subfolder_record_cache: |
| 241 | for uid in params.subfolder_record_cache[folder_uid]: |
| 242 | r = api.get_record(params, uid) |
| 243 | if r.title.lower() == name.lower(): |
| 244 | record_uid = uid |
| 245 | break |
| 246 | |
| 247 | if record_uid is None: |
| 248 | raise CommandError('edit', 'Enter name or uid of existing record') |
| 249 | |
| 250 | record = api.get_record(params, record_uid) |
| 251 | |
| 252 | changed = False |
| 253 | password_changed = False |
| 254 | if kwargs.get('title') is not None: |
| 255 | title = kwargs['title'] |
| 256 | if title: |
| 257 | record.title = title |
| 258 | changed = True |
| 259 | else: |
| 260 | logging.warning('Record title cannot be empty.') |
| 261 | if kwargs.get('login') is not None: |
| 262 | record.login = kwargs['login'] |
| 263 | changed = True |
| 264 | if kwargs.get('password') is not None: |
| 265 | last_password = record.unmasked_password or record.password |
| 266 | record.password = kwargs['password'] |
| 267 | password_changed = record.password != last_password |
| 268 | changed = True |
| 269 | else: |
| 270 | if kwargs.get('generate'): |
| 271 | record.password = generator.generate(16) |
| 272 | changed = password_changed = True |
| 273 | if kwargs.get('url') is not None: |
| 274 | record.login_url = kwargs['url'] |
| 275 | changed = True |
| 276 | if kwargs.get('notes') is not None: |
| 277 | notes = kwargs['notes'] # type: str |
| 278 | if notes: |
| 279 | if notes.startswith("+"): |
| 280 | notes = record.notes + "\n" + notes[1:] |
| 281 | record.notes = notes |
nothing calls this directly
no test coverage detected