This issue is a continuation of https://github.com/MatrixAI/Polykey-CLI/issues/266 (ENG-398). In the previous issue, support for creating a file if it doesn't already exist in the vault was added. To finish off this issue, we need to identify the preferred editor of each platform and use that, instead of relying on $EDITOR.
Each platform has their own preferences for file editor. As such, identify and launch the corresponding file editor to edit the secret. Windows would have notepad.exe, and MacOS and Linux editors would require to be inferred from environment. To ensure everything is working smoothly, integration tests need to be done on all the given platforms.
Generally speaking you rely on an environment variable: $VISUAL then if not set, rely on $EDITOR, and if not set, then you default onto something that would exist on most platforms.
Linux - VISUAL, EDITOR, nano, ed - I wouldn't default to vi or vim because it's actually a more advanced editor.
Windows - VISUAL, EDITOR, get the .txt file association first, then default to notepad.exe and wait for it to finish. Windows never had a default terminal text editor.
MacOS - VISUAL, EDITOR, pico, nano
If the defaults cannot be found, you need to error out, indicating that no default editor could be found, and users can instead choose to set VISUAL, EDITOR or pass in the "editor" program with --ed or something.
Furthermore it is important that the temporary being created can only be edited by the same user as the user who ran polykey secrets edit, otherwise it can be intercepted. The file should have a limited umask like 700. Or equivalent for the Windows.
The behaviour of secrets edit command shouldn't be what is simplest. It should be what makes the most sense.
Specification
This issue is a continuation of https://github.com/MatrixAI/Polykey-CLI/issues/266 (ENG-398). In the previous issue, support for creating a file if it doesn't already exist in the vault was added. To finish off this issue, we need to identify the preferred editor of each platform and use that, instead of relying on
$EDITOR
.Each platform has their own preferences for file editor. As such, identify and launch the corresponding file editor to edit the secret. Windows would have
notepad.exe
, and MacOS and Linux editors would require to be inferred from environment. To ensure everything is working smoothly, integration tests need to be done on all the given platforms.The behaviour of
secrets edit
command shouldn't be what is simplest. It should be what makes the most sense.Additional context
Tasks