MCPcopy Create free account
hub / github.com/compozy/agh / runConfigEditor

Function runConfigEditor

internal/cli/config.go:1825–1849  ·  view source on GitHub ↗
(cmd *cobra.Command, deps commandDeps, path string)

Source from the content-addressed store, hash-verified

1823}
1824
1825func runConfigEditor(cmd *cobra.Command, deps commandDeps, path string) error {
1826 editor := strings.TrimSpace(deps.getenv("VISUAL"))
1827 if editor == "" {
1828 editor = strings.TrimSpace(deps.getenv("EDITOR"))
1829 }
1830 if editor == "" {
1831 return errors.New("cli: config edit requires VISUAL or EDITOR")
1832 }
1833 parts, err := shellquote.Split(editor)
1834 if err != nil {
1835 return fmt.Errorf("cli: parse config editor command: %w", err)
1836 }
1837 if len(parts) == 0 {
1838 return errors.New("cli: config editor command is empty")
1839 }
1840 //nolint:gosec // VISUAL/EDITOR intentionally selects the local editor for config edit.
1841 editorCmd := exec.CommandContext(cmd.Context(), parts[0], append(parts[1:], path)...)
1842 editorCmd.Stdin = os.Stdin
1843 editorCmd.Stdout = cmd.OutOrStdout()
1844 editorCmd.Stderr = cmd.ErrOrStderr()
1845 if err := editorCmd.Run(); err != nil {
1846 return fmt.Errorf("cli: run config editor %q: %w", parts[0], err)
1847 }
1848 return nil
1849}

Callers 1

newConfigEditCommandFunction · 0.85

Calls 2

appendFunction · 0.85
RunMethod · 0.65

Tested by

no test coverage detected