Skip to content

Commit df4f2d5

Browse files
committed
Copy files from github if none given locally
1 parent 5dc403d commit df4f2d5

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

internal/fetch/fetch.go

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,31 @@ func copyLocalFiles(templateDir, fileNames, solutionDir string) (files []string,
133133
return
134134
}
135135

136-
func copyGlobalFilesFromGithub() (files []string, err error) {
136+
func copyGlobalFilesFromGithub(solutionDir string) (files []string, err error) {
137+
solutionFileData, err := getRawDataFromURL("https://raw.githubusercontent.com/joshmenden/aocplz/main/templates/solution.rb.tmpl", false)
138+
if err != nil {
139+
return
140+
}
141+
142+
err = copyFile(nil, fmt.Sprintf("%s/%s", solutionDir, "solution.rb"), solutionFileData)
143+
if err != nil {
144+
return
145+
} else {
146+
files = append(files, "github.com/.../solution.rb")
147+
}
148+
149+
gemfileData, err := getRawDataFromURL("https://raw.githubusercontent.com/joshmenden/aocplz/main/templates/Gemfile.tmpl", false)
150+
if err != nil {
151+
return
152+
}
153+
154+
err = copyFile(nil, fmt.Sprintf("%s/%s", solutionDir, "Gemfile"), gemfileData)
155+
if err != nil {
156+
return
157+
} else {
158+
files = append(files, "github.com/.../Gemfile")
159+
}
160+
137161
return
138162
}
139163

@@ -144,7 +168,7 @@ func createSolutionFiles(solutionDir string) (files []string, err error) {
144168
if tmplsDir != "" && tmplsStr != "" {
145169
return copyLocalFiles(tmplsDir, tmplsStr, solutionDir)
146170
} else {
147-
return copyGlobalFilesFromGithub()
171+
return copyGlobalFilesFromGithub(solutionDir)
148172
}
149173
}
150174

main.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ var (
1919
requiredVars = []string{
2020
"AOCPLZ_SESSION_TOKEN",
2121
"AOCPLZ_ROOT_DIR",
22-
"AOCPLZ_TEMPLATES_DIR",
23-
"AOCPLZ_TEMPLATE_FILES",
2422
}
2523
)
2624

0 commit comments

Comments
 (0)