mirror of
https://github.com/sst/opencode.git
synced 2025-07-07 16:14:59 +00:00
feat: prioritize project config over global (fallback to global)
This commit is contained in:
parent
1523afbcc3
commit
6b0e307e8e
1 changed files with 20 additions and 10 deletions
|
@ -2,6 +2,7 @@ package tui
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"os"
|
||||
"os/exec"
|
||||
|
@ -968,7 +969,6 @@ func (a appModel) executeCommand(command commands.Command) (tea.Model, tea.Cmd)
|
|||
cmd = toast.NewSuccessToast("Message copied to clipboard")
|
||||
cmds = append(cmds, cmd)
|
||||
}
|
||||
case commands.MessagesRevertCommand:
|
||||
case commands.ConfigCommand:
|
||||
if a.app.IsBusy() {
|
||||
return a, nil
|
||||
|
@ -978,19 +978,29 @@ func (a appModel) executeCommand(command commands.Command) (tea.Model, tea.Cmd)
|
|||
return a, toast.NewErrorToast("No EDITOR set, can't open config")
|
||||
}
|
||||
|
||||
configPath := filepath.Join(a.app.Info.Path.Config, "config.json")
|
||||
c := exec.Command(editor, configPath) //nolint:gosec
|
||||
cfgPath := filepath.Join(a.app.Info.Path.Cwd, "opencode.json")
|
||||
cfgKind := "project"
|
||||
if _, err := os.Stat(cfgPath); os.IsNotExist(err) {
|
||||
cfgPath = filepath.Join(a.app.Info.Path.Config, "config.json")
|
||||
cfgKind = "global"
|
||||
}
|
||||
|
||||
c := exec.Command(editor, cfgPath) //nolint:gosec
|
||||
c.Stdin = os.Stdin
|
||||
c.Stdout = os.Stdout
|
||||
c.Stderr = os.Stderr
|
||||
cmd := tea.ExecProcess(c, func(err error) tea.Msg {
|
||||
if err != nil {
|
||||
slog.Error("Failed to open config", "error", err)
|
||||
return toast.NewErrorToast("Failed to open config")()
|
||||
}
|
||||
return toast.NewSuccessToast("Config updated, restart to apply changes")()
|
||||
})
|
||||
cmd := tea.ExecProcess(exec.Command(editor, cfgPath), func(err error) tea.Msg {
|
||||
if err != nil {
|
||||
slog.Error("Failed to open config", "error", err)
|
||||
return toast.NewErrorToast("Failed to open config")()
|
||||
}
|
||||
return toast.NewSuccessToast(
|
||||
fmt.Sprintf("%s config updated, restart to apply changes",
|
||||
strings.Title(cfgKind)),
|
||||
)()
|
||||
})
|
||||
cmds = append(cmds, cmd)
|
||||
case commands.MessagesRevertCommand:
|
||||
case commands.AppExitCommand:
|
||||
return a, tea.Quit
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue