Skip to content

Commit 2e56d8f

Browse files
feat: oc installation
1 parent 2ab9719 commit 2e56d8f

1 file changed

Lines changed: 30 additions & 1 deletion

File tree

cmd/ask/ask.go

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ import (
1010
"path/filepath"
1111
"strings"
1212

13+
"github.com/pterm/pterm"
1314
"github.com/urfave/cli/v2"
15+
16+
"github.com/NodeOps-app/createos-cli/internal/terminal"
1417
)
1518

1619
//go:embed agent.md
@@ -53,7 +56,33 @@ func NewAskCommand() *cli.Command {
5356
Action: func(c *cli.Context) error {
5457
opencodeBin, err := exec.LookPath("opencode")
5558
if err != nil {
56-
return fmt.Errorf("opencode is not installed or not in PATH\n\n Install it from: https://opencode.ai")
59+
if !terminal.IsInteractive() {
60+
return fmt.Errorf("opencode is not installed\n\n Install it with:\n curl -fsSL https://opencode.ai/install | bash")
61+
}
62+
63+
install, _ := pterm.DefaultInteractiveConfirm.
64+
WithDefaultText("opencode is not installed. Install it now?").
65+
WithDefaultValue(true).
66+
Show()
67+
if !install {
68+
return fmt.Errorf("opencode is required for the ask command\n\n Install it manually:\n curl -fsSL https://opencode.ai/install | bash")
69+
}
70+
71+
pterm.Info.Println("Installing opencode...")
72+
installCmd := exec.Command("bash", "-c", "curl -fsSL https://opencode.ai/install | bash") // #nosec G204 -- install URL is hardcoded
73+
installCmd.Stdin = os.Stdin
74+
installCmd.Stdout = os.Stdout
75+
installCmd.Stderr = os.Stderr
76+
if err := installCmd.Run(); err != nil {
77+
return fmt.Errorf("failed to install opencode: %w", err)
78+
}
79+
80+
opencodeBin, err = exec.LookPath("opencode")
81+
if err != nil {
82+
return fmt.Errorf("opencode was installed but not found in PATH\n\n Try restarting your terminal and running this command again")
83+
}
84+
pterm.Success.Println("opencode installed successfully")
85+
fmt.Println()
5786
}
5887

5988
if err := installAgent(); err != nil {

0 commit comments

Comments
 (0)