heroku / cli

Heroku CLI
https://devcenter.heroku.com/articles/heroku-cli
ISC License
854 stars 224 forks source link

`config:edit` examples using `$EDITOR` / `$VISUAL` with args don't work #1996

Open edmorley opened 2 years ago

edmorley commented 2 years ago

Do you want to request a feature or report a bug?

Bug

What is the current behavior?

The config:edit help text says:

DESCRIPTION
  This command opens the app config in a text editor set by $VISUAL or $EDITOR.
  Any variables added/removed/changed will be updated on the app after saving and closing the file.

EXAMPLES
  # edit with vim
  $ EDITOR="vim" heroku config:edit
  # edit with emacs
  $ EDITOR="emacs" heroku config:edit
  # edit with pico
  $ EDITOR="pico" heroku config:edit
  # edit with atom editor
  $ VISUAL="atom --wait" heroku config:edit

This works if I set EDITOR (or VISUAL) to a single command (such as code), however fails if I pass in additional arguments as per the final example in the help text.

$ EDITOR='code --wait' h config:edit
Fetching config... done
Waiting for code --wait... Error: spawn code --wait ENOENT

In VSCode's case, the argument --wait is required to make the editor wait for the window to be closed before the command returns (otherwise one gets a › Warning: no changes to config warning from the Heroku CLI, as the command returned early).

This is using macOS 12.3.1 with Homebrew bash.

What is the expected behavior?

That:


This editor functionality is provided by the edit-string package, called here: https://github.com/heroku/cli/blob/b8292f347101f13c2bb833b1dcf088886c8aa984/packages/config/src/commands/config/edit.ts#L105

Whose implementation is here: https://github.com/jdxcode/edit-string/blob/v1.1.6/src/edit.ts

edmorley commented 2 years ago

I was hoping to work around this by eg creating a bash alias to wrap the --wait arg, however the edit-string package doesn't use the shell option with its execa usage, so that doesn't work.

However, a workaround that does work is to create a script that wraps the call and put that on PATH.

eg:

#!/usr/bin/env bash

exec code --wait "$@"

-> Ensure on path -> export EDITOR='<script-name>.sh'

machty commented 2 years ago

I'm running into the same issue, in addition to a different one:

heroku-cli doesn't appear honor the EDITOR env var that I've set in my .zshrc:

machty@MacBook-Pro business-server % echo $EDITOR
/usr/bin/vim
machty@MacBook-Pro business-server % heroku config:edit -r staging

Running ^ this opens pico, not vim.

All of the following DO work though:

EDITOR=vim heroku config:edit -r staging
EDITOR=/usr/bin/vim heroku config:edit -r staging
EDITOR=$EDITOR heroku config:edit -r staging
sbosio commented 4 months ago

Added a work item to track the fix.

GUS Work Item (Heroku internal).