mirror of
https://github.com/safedep/pmg.git
synced 2026-08-03 07:24:09 +02:00
feat: Add support for sandbox edit command (#385)
* feat: Add support for sandbox edit command * docs: Update sandbox docs * fix(editor): address review — neutral failure wording, skip sh-script tests on Windows Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(test): avoid pnpm init in pm-e2e — devEngines.packageManager crashes subsequent pnpm add Same workaround and rationale as the PNPM job in pmg-e2e.yml. Latest pnpm (unpinned pnpm/action-setup) writes devEngines.packageManager with onFail:download on init, and the next add fails with "Cannot use 'in' operator to search for 'integrity' in undefined". Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
bafd3c0654
commit
695a1d739d
+2
-46
@@ -5,12 +5,9 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
appConfig "github.com/safedep/pmg/config"
|
||||
"github.com/safedep/pmg/internal/shellwords"
|
||||
"github.com/safedep/pmg/internal/editor"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@@ -100,46 +97,5 @@ func runEdit() error {
|
||||
return fmt.Errorf("failed to stat config file %q: %w", path, err)
|
||||
}
|
||||
|
||||
editor, err := resolveEditor()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
parts, err := shellwords.Split(editor)
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid editor command %q: %w", editor, err)
|
||||
}
|
||||
if len(parts) == 0 {
|
||||
return fmt.Errorf("editor command is empty")
|
||||
}
|
||||
parts = append(parts, path)
|
||||
|
||||
c := exec.Command(parts[0], parts[1:]...)
|
||||
c.Stdin = os.Stdin
|
||||
c.Stdout = os.Stdout
|
||||
c.Stderr = os.Stderr
|
||||
if err := c.Run(); err != nil {
|
||||
return fmt.Errorf("editor %q exited with error: %w", editor, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resolveEditor() (string, error) {
|
||||
if v := strings.TrimSpace(os.Getenv("VISUAL")); v != "" {
|
||||
return v, nil
|
||||
}
|
||||
if v := strings.TrimSpace(os.Getenv("EDITOR")); v != "" {
|
||||
return v, nil
|
||||
}
|
||||
|
||||
if runtime.GOOS == "windows" {
|
||||
return "notepad", nil
|
||||
}
|
||||
|
||||
if _, err := exec.LookPath("vi"); err == nil {
|
||||
return "vi", nil
|
||||
}
|
||||
|
||||
return "", fmt.Errorf("no editor found: set $VISUAL or $EDITOR")
|
||||
return editor.Open(path)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user