Skip to content

Commit 00a26d2

Browse files
Initial commit
0 parents  commit 00a26d2

14 files changed

Lines changed: 1261 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
build-and-test:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- uses: actions/setup-go@v5
16+
with:
17+
go-version: '1.23'
18+
19+
- run: go build ./...
20+
- run: go vet ./...
21+
- run: go test ./... -v -race -count=1

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bin/
2+
*.exe

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# instant CLI
2+
3+
Zero-friction infrastructure CLI for [instant.dev](https://instant.dev).
4+
5+
## Install
6+
7+
```bash
8+
go install github.com/instant-dev/cli@latest
9+
```
10+
11+
## Usage
12+
13+
```bash
14+
instant db new # Provision a Postgres database
15+
instant cache new # Provision a Redis cache
16+
instant nosql new # Provision a MongoDB document store
17+
instant queue new # Provision a NATS JetStream queue
18+
instant resources # List your provisioned resources (requires login)
19+
instant status # Show locally tracked resources
20+
instant login # Log in to your instant.dev account
21+
instant whoami # Show current account
22+
```
23+
24+
## Build from source
25+
26+
```bash
27+
go build -o bin/instant .
28+
```

cmd/discover.go

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package cmd
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"io"
7+
"net/http"
8+
"os"
9+
"text/tabwriter"
10+
11+
"github.com/spf13/cobra"
12+
)
13+
14+
// resourcesCmd lists resources from the agent API (requires login).
15+
var resourcesCmd = &cobra.Command{
16+
Use: "resources",
17+
Short: "List your provisioned resources",
18+
Long: `List all resources associated with your instant.dev account.
19+
20+
Requires login. Run 'instant login' first if you haven't already.
21+
22+
Use 'instant status' to see resources tracked locally (no login required).
23+
`,
24+
RunE: func(cmd *cobra.Command, args []string) error {
25+
url := fmt.Sprintf("%s/api/v1/resources", APIBaseURL)
26+
req, err := http.NewRequest(http.MethodGet, url, nil)
27+
if err != nil {
28+
return err
29+
}
30+
31+
resp, err := HTTPClient.Do(req)
32+
if err != nil {
33+
return fmt.Errorf("request failed: %w", err)
34+
}
35+
defer resp.Body.Close()
36+
37+
if resp.StatusCode == http.StatusUnauthorized {
38+
fmt.Fprintln(os.Stderr, "Not logged in. Run `instant login` first.")
39+
return nil
40+
}
41+
42+
raw, _ := io.ReadAll(resp.Body)
43+
if resp.StatusCode != http.StatusOK {
44+
return fmt.Errorf("server returned %d: %s", resp.StatusCode, raw)
45+
}
46+
47+
var result struct {
48+
OK bool `json:"ok"`
49+
Total int `json:"total"`
50+
Items []struct {
51+
Token string `json:"token"`
52+
ResourceType string `json:"resource_type"`
53+
Name string `json:"name"`
54+
Tier string `json:"tier"`
55+
Status string `json:"status"`
56+
} `json:"items"`
57+
}
58+
if err := json.Unmarshal(raw, &result); err != nil {
59+
return fmt.Errorf("parsing response: %w", err)
60+
}
61+
62+
if len(result.Items) == 0 {
63+
fmt.Println("No resources found.")
64+
return nil
65+
}
66+
67+
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
68+
fmt.Fprintln(w, "TOKEN\tTYPE\tNAME\tTIER\tSTATUS")
69+
for _, r := range result.Items {
70+
shortToken := r.Token
71+
if len(shortToken) > 12 {
72+
shortToken = shortToken[:12] + "…"
73+
}
74+
name := r.Name
75+
if name == "" {
76+
name = "-"
77+
}
78+
fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n",
79+
shortToken, r.ResourceType, name, r.Tier, r.Status)
80+
}
81+
w.Flush()
82+
return nil
83+
},
84+
}
85+
86+
func init() {
87+
rootCmd.AddCommand(resourcesCmd)
88+
}

0 commit comments

Comments
 (0)