Skip to content

Commit b2528e5

Browse files
authored
autoscaling agent as part of get-started (#21)
* add ability to clone example from other repos * cleanup
1 parent 68f4354 commit b2528e5

File tree

2 files changed

+38
-8
lines changed

2 files changed

+38
-8
lines changed

src/cloneBoilerplates.go

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,33 @@ import (
77
"path/filepath"
88
)
99

10-
var repositoryUrls = map[string]string{
11-
"typescript": "https://github.com/restackio/examples-typescript.git",
12-
"python": "https://github.com/restackio/examples-python.git",
10+
type RepoInfo struct {
11+
URL string
12+
IsAtRoot bool
13+
}
14+
15+
var repositoryInfos = map[string]map[string]RepoInfo{
16+
"typescript": {
17+
"agent-todo": {URL: "https://github.com/restackio/examples-typescript.git", IsAtRoot: false},
18+
"agent-chat": {URL: "https://github.com/restackio/examples-typescript.git", IsAtRoot: false},
19+
"agent-scaling": {URL: "https://github.com/restackio/autoscaling-agent.git", IsAtRoot: true},
20+
},
21+
"python": {
22+
"agent_todo": {URL: "https://github.com/restackio/examples-python.git", IsAtRoot: false},
23+
"agent_chat": {URL: "https://github.com/restackio/examples-python.git", IsAtRoot: false},
24+
},
1325
}
1426

1527
func (m model) cloneBoilerplates() error {
1628
targetDir := filepath.Join(m.currentDir, m.applicationName)
1729
tempDir := filepath.Join(m.currentDir, "temp")
1830

19-
repoName := repositoryUrls[m.language]
31+
exampleName := m.example[1:]
32+
repoInfo := repositoryInfos[m.language][exampleName]
2033

21-
cmd := exec.Command("git", "clone", repoName, tempDir)
34+
fmt.Printf("Repository URL: %s, Is at root: %v\n", repoInfo.URL, repoInfo.IsAtRoot)
35+
36+
cmd := exec.Command("git", "clone", repoInfo.URL, tempDir)
2237
cmd.Stdout = os.Stdout
2338
cmd.Stderr = os.Stderr
2439
err := cmd.Run()
@@ -28,12 +43,27 @@ func (m model) cloneBoilerplates() error {
2843

2944
fmt.Printf("Moving files from %s to %s\n", tempDir, targetDir)
3045

31-
cmd = exec.Command("mv", tempDir+m.example, targetDir)
46+
var sourceDir string
47+
if repoInfo.IsAtRoot {
48+
// If the template is at the root of the repository, use the whole temp directory
49+
sourceDir = tempDir
50+
} else {
51+
// Otherwise, use the specified subdirectory
52+
sourceDir = tempDir + m.example
53+
}
54+
55+
// Create target directory if it doesn't exist
56+
if err := os.MkdirAll(targetDir, 0755); err != nil {
57+
return fmt.Errorf("failed to create target directory: %v", err)
58+
}
59+
60+
// Use cp -r instead of mv to handle both directory and root cases
61+
cmd = exec.Command("cp", "-r", sourceDir+"/.", targetDir)
3262
cmd.Stdout = os.Stdout
3363
cmd.Stderr = os.Stderr
3464
err = cmd.Run()
3565
if err != nil {
36-
return fmt.Errorf("move files failed: %v", err)
66+
return fmt.Errorf("copy files failed: %v", err)
3767
}
3868

3969
cmd = exec.Command("rm", "-rf", tempDir)

src/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ type model struct {
1313
applicationName string
1414
currentDir string
1515
example string
16-
installDeps bool
1716
startRestack bool
1817
openUI bool
1918
}
@@ -80,6 +79,7 @@ func main() {
8079
Options([]huh.Option[string]{
8180
{Value: "/agent-todo", Key: "Default agent (recommended)"},
8281
{Value: "/agent-chat", Key: "Empty agent"},
82+
{Value: "/agent-scaling", Key: "Scaling agent"},
8383
}...).
8484
Value(&m.example)
8585
} else if m.language == "python" {

0 commit comments

Comments
 (0)