Skip to content

Commit 4f7eef1

Browse files
committed
feat: support URL in snapshot --import for curl one-liner restore
openboot snapshot --import https://example.com/my-setup.json now downloads the JSON before importing. Enables the full one-liner: curl -fsSL https://openboot.dev/install | bash -s -- snapshot --import <url>
1 parent 2bd6303 commit 4f7eef1

1 file changed

Lines changed: 25 additions & 1 deletion

File tree

internal/cli/snapshot.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"net/http"
99
"os"
1010
"os/exec"
11+
"path/filepath"
1112
"strings"
1213

1314
"github.com/charmbracelet/lipgloss"
@@ -319,7 +320,30 @@ func printSnapshotList(items []string, max int) {
319320
}
320321

321322
func runSnapshotImport(importPath string, dryRun bool) error {
322-
snap, err := snapshot.LoadFile(importPath)
323+
localPath := importPath
324+
if strings.HasPrefix(importPath, "http://") || strings.HasPrefix(importPath, "https://") {
325+
fmt.Fprintf(os.Stderr, " Downloading snapshot from %s...\n", importPath)
326+
resp, err := http.Get(importPath)
327+
if err != nil {
328+
return fmt.Errorf("failed to download snapshot: %w", err)
329+
}
330+
defer resp.Body.Close()
331+
if resp.StatusCode != http.StatusOK {
332+
return fmt.Errorf("failed to download snapshot: HTTP %d", resp.StatusCode)
333+
}
334+
tmpFile := filepath.Join(os.TempDir(), "openboot-snapshot-import.json")
335+
data, err := io.ReadAll(resp.Body)
336+
if err != nil {
337+
return fmt.Errorf("failed to read snapshot response: %w", err)
338+
}
339+
if err := os.WriteFile(tmpFile, data, 0644); err != nil {
340+
return fmt.Errorf("failed to save snapshot: %w", err)
341+
}
342+
defer os.Remove(tmpFile)
343+
localPath = tmpFile
344+
}
345+
346+
snap, err := snapshot.LoadFile(localPath)
323347
if err != nil {
324348
return err
325349
}

0 commit comments

Comments
 (0)