doorstop-dev / doorstop

Requirements management using version control.
https://doorstop.readthedocs.io
Other
474 stars 132 forks source link

doorstop edit REQ001 doesn't save #578

Closed ashiroji closed 10 months ago

ashiroji commented 2 years ago

Hello, I'm new to doorstop and trying to understand how to use it correctly. I have a very simple tree containing just a single req REQ001.yml. I noticed that when using the command: doorstop edit REQ001 the new text is not saved, but when using the command: doorstop edit -a REQ001 or the command doorstop edit REQ the new text is saved correctly is there something that I'm missing?

neerdoc commented 10 months ago

Hi @ashiroji, sorry for the very late reply.

I cannot reproduce this behaviour unfortunately. Can you please give us some more information on how to reproduce this?

ashiroji commented 10 months ago

I'll try to describe as much as possible. Feel free to ask for more details.

Steps to reproduce error:

  1. Create new folder: mkdir test_folder
  2. initialise the git repo: git init .
  3. create tree: doorstop create SRD ./reqs/srd
  4. add element: doorstop add SRD
  5. edit element: doorstop edit SRD001
  6. TextEdit is launched to edit only the text portion of the .yml file
  7. type text in text editor
  8. attempt to save
  9. Error: Location of file "SRD01_smbz0gq6" was not determined. Cancel or Save As...

Steps to correctly edit:

  1. Create new folder: mkdir test_folder
  2. initialise the git repo: git init .
  3. create tree: doorstop create SRD ./reqs/srd
  4. add element: doorstop add SRD
  5. edit element: doorstop edit -a SRD001 or doorstop edit SRD
  6. VSCode is launched to edit the entire .yml file
  7. type text in text editor
  8. attempt to save
  9. Success

Verification process:

  1. edit element: doorstop edit SRD001
  2. TextEdit is launched
  3. Added text from previous steps is available
  4. New text cannot be added due to same error as described earlier
neerdoc commented 10 months ago

I think I understand. It seems that you are using the default text editor in Mac OS, is that correct?

I just tried that and it fails miserably for me before I even get the file opened. The TextEdit.app is not really suited to edit files in this manner, so I would suggest that you install and use another text editor that is meant to be used from the terminal.

You can use Homebrew for this, e.g., brew install joe or another editor. You can then test it out by setting the editor directly on the command line like this: EDITOR=joe doorstop edit SRD001

ashiroji commented 10 months ago

Thank you very much. it works with joe. I also tried vim and it worked. Can you please explain why?

neerdoc commented 10 months ago

I can try... :)

doorstop is a Python program and is used from the command line. It expects the editor to start and then waits for the editor to stop executing, i.e., when you save and exit, before it continues handling the temporary file it supplied to the editor.

TextEdit.app, and I would suspect a lot of other GUI-based applications, say Word in Windows, does not really work like that because they spawn new processes in the OS to run. This causes doorstop to believe that the editor is done while it is actually just starting itself. Since doorstop then removes the temporary file, TextEdit does not have it when it is trying to save causing the issue you see.

So it's basically a question of a mismatch in how some editors work and how doorstop expects them to work.

While certainly possible to solve, it would require a lot more code to try to catch the spawned subprocesses, which would make doorstop a lot more complex for no good reason. A command line text editor will start a lot faster for instance than a complex GUI-app.

I'm going to close this issue with this explanation.