@@ -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
1527func (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 )
0 commit comments