Skip to content

Commit 4288e8e

Browse files
authored
Add skill install and dune auth to the install.sh script (#24)
* Add skill install and dune auth to the install.sh script * Fix install script tty detection * Improve tty handling
1 parent a5637f4 commit 4288e8e

5 files changed

Lines changed: 80 additions & 5 deletions

File tree

cmd/auth/auth.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
"github.com/duneanalytics/cli/authconfig"
1010
"github.com/spf13/cobra"
11+
"golang.org/x/term"
1112
)
1213

1314
// NewAuthCmd returns the `auth` command.
@@ -29,15 +30,23 @@ func runAuth(cmd *cobra.Command, _ []string) error {
2930
}
3031

3132
if key == "" {
33+
if stdin, ok := cmd.InOrStdin().(*os.File); ok && !term.IsTerminal(int(stdin.Fd())) {
34+
return fmt.Errorf("no API key provided; pass --api-key, set DUNE_API_KEY, or run dune auth in an interactive terminal")
35+
}
36+
37+
var (
38+
reader = cmd.InOrStdin()
39+
)
40+
3241
fmt.Fprint(cmd.ErrOrStderr(), "Enter your Dune API key: ")
33-
scanner := bufio.NewScanner(cmd.InOrStdin())
42+
scanner := bufio.NewScanner(reader)
3443
if scanner.Scan() {
3544
key = strings.TrimSpace(scanner.Text())
3645
}
3746
}
3847

3948
if key == "" {
40-
return fmt.Errorf("no API key provided")
49+
return fmt.Errorf("no API key provided; pass --api-key, set DUNE_API_KEY, or run dune auth in an interactive terminal")
4150
}
4251

4352
cfg, err := authconfig.Load()

cmd/auth/auth_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,5 +90,5 @@ func TestAuthEmptyInput(t *testing.T) {
9090
root.SetArgs([]string{"auth"})
9191
err := root.Execute()
9292
assert.Error(t, err)
93-
assert.Contains(t, err.Error(), "no API key provided")
93+
assert.Contains(t, err.Error(), "no API key provided; pass --api-key, set DUNE_API_KEY, or run dune auth in an interactive terminal")
9494
}

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ require (
4444
github.com/yosida95/uritemplate/v3 v3.0.2 // indirect
4545
golang.org/x/oauth2 v0.34.0 // indirect
4646
golang.org/x/sync v0.17.0 // indirect
47-
golang.org/x/sys v0.40.0 // indirect
47+
golang.org/x/sys v0.41.0 // indirect
48+
golang.org/x/term v0.40.0 // indirect
4849
golang.org/x/text v0.24.0 // indirect
4950
)

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ golang.org/x/sync v0.17.0 h1:l60nONMj9l5drqw6jlhIELNv9I0A4OFgRsG9k2oT9Ug=
8989
golang.org/x/sync v0.17.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
9090
golang.org/x/sys v0.40.0 h1:DBZZqJ2Rkml6QMQsZywtnjnnGvHza6BTfYFWY9kjEWQ=
9191
golang.org/x/sys v0.40.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
92+
golang.org/x/sys v0.41.0 h1:Ivj+2Cp/ylzLiEU89QhWblYnOE9zerudt9Ftecq2C6k=
93+
golang.org/x/sys v0.41.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
94+
golang.org/x/term v0.40.0 h1:36e4zGLqU4yhjlmxEaagx2KuYbJq3EwY8K943ZsHcvg=
95+
golang.org/x/term v0.40.0/go.mod h1:w2P8uVp06p2iyKKuvXIm7N/y0UCRt3UfJTfZ7oOpglM=
9296
golang.org/x/text v0.24.0 h1:dd5Bzh4yt5KYA8f9CJHCP4FB4D51c2c6JvN37xJJkJ0=
9397
golang.org/x/text v0.24.0/go.mod h1:L8rBsPeo2pSS+xqN0d5u2ikmjtmoJbDBT1b7nHvFCdU=
9498
golang.org/x/tools v0.41.0 h1:a9b8iMweWG+S0OBnlU36rzLp20z1Rp10w+IY2czHTQc=

install.sh

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,68 @@ main() {
8282
sudo mv "$tmp/$binary_name" "$install_dir/$binary_name"
8383
fi
8484

85-
log "Installed ${BINARY} ${version} to ${install_dir}/${binary_name}"
85+
# Post-install interactive setup only when we have a usable terminal.
86+
if has_tty; then
87+
post_install "${install_dir}/${binary_name}" "$version"
88+
else
89+
echo "" >&2
90+
log "Dune CLI ${version} installed successfully!"
91+
echo "" >&2
92+
log "Tip: Run 'npx skills add duneanalytics/skills' to install the Dune AI coding skill."
93+
log "Tip: Run 'dune auth' to authenticate with your Dune account."
94+
fi
95+
}
96+
97+
post_install() {
98+
dune_bin="$1"
99+
dune_version="$2"
100+
echo "" >&2
101+
102+
# --- Skill install ---
103+
if has npx; then
104+
log "The Dune skill lets AI coding agents (Cursor, Claude Code, etc.) query"
105+
log "blockchain data on your behalf."
106+
printf " Install Dune skill for your AI coding agent? [Y/n] " >&2
107+
read -r answer < /dev/tty || answer=""
108+
case "$answer" in
109+
[nN]*)
110+
log "Skipped. You can install it later with: npx skills add duneanalytics/skills"
111+
;;
112+
*)
113+
log "Installing Dune skill..."
114+
npx skills add duneanalytics/skills < /dev/tty || log "Skill installation failed. You can retry with: npx skills add duneanalytics/skills"
115+
;;
116+
esac
117+
else
118+
log "Tip: Run 'npx skills add duneanalytics/skills' to install the Dune AI coding skill."
119+
log "(requires Node.js / npx)"
120+
fi
121+
122+
echo "" >&2
123+
124+
# --- Authentication ---
125+
log "Authenticate to start running queries and accessing your Dune account."
126+
printf " Authenticate with Dune now? [Y/n] " >&2
127+
read -r answer < /dev/tty || answer=""
128+
case "$answer" in
129+
[nN]*)
130+
log "Skipped. You can authenticate later with: dune auth"
131+
;;
132+
*)
133+
echo "" >&2
134+
log "You'll need a Dune API key."
135+
log "Go to https://dune.com and navigate to APIs and Connectors > API Keys."
136+
echo "" >&2
137+
"$dune_bin" auth < /dev/tty || log "Authentication failed. You can retry with: dune auth"
138+
;;
139+
esac
140+
141+
echo "" >&2
142+
log "Dune CLI ${dune_version} installed successfully!"
143+
}
144+
145+
has_tty() {
146+
[ -t 0 ] || [ -t 1 ] || [ -t 2 ]
86147
}
87148

88149
# Pick the best install directory by checking user-writable directories

0 commit comments

Comments
 (0)