Skip to content

Commit f8834bf

Browse files
committed
feat: Allow overriding detected type when not detected
1 parent fd181ba commit f8834bf

3 files changed

Lines changed: 22 additions & 21 deletions

File tree

internal/command/init.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,20 @@ func initHandler(ctx *gear.Context, args gear.ValidatedArgs) error {
3232
projectType = models.ParseProjectType(projectTypeFlag)
3333
} else {
3434
projectType = detector.DetectCurrentProjectType()
35+
if projectType == models.ProjectTypeUnknown {
36+
logger.Warning("Could not detect project type automatically.")
37+
typeList := detector.ListSupportedProjectTypes()
38+
logger.Info("Supported project types: %v", typeList)
39+
answer, err := logger.Prompt("Please specify the project type (or 'unknown' for default config): ")
40+
if err != nil {
41+
return err
42+
}
43+
projectType = models.ParseProjectType(answer)
44+
if answer != "y" {
45+
logger.Warning("Initialization cancelled.")
46+
return nil
47+
}
48+
}
3549
}
3650
if projectType == models.ProjectTypeUnknown {
3751
logger.Info("Detected project type is unknown and would generate a default config.")

internal/template/detector/detector.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,31 +44,21 @@ var detectors = []detector{
4444
"go.sum",
4545
"main.go",
4646
),
47-
anyDirExistsIndicator(
48-
"cmd",
49-
"pkg",
50-
),
5147
),
5248
newBaseDetector(
5349
models.ProjectTypeNode,
5450
fileExistsIndicator("package.json"),
55-
dirExistsIndicator("node_modules"),
5651
),
5752
newBaseDetector(
5853
models.ProjectTypePython,
5954
anyFileExistsIndicator(
6055
"*.py",
6156
"main.py",
6257
),
63-
anyDirExistsIndicator(
64-
"src",
65-
"tests",
66-
),
6758
),
6859
newBaseDetector(
6960
models.ProjectTypeRust,
7061
fileExistsIndicator("Cargo.toml"),
71-
dirExistsIndicator("src"),
7262
),
7363
}
7464

@@ -88,3 +78,11 @@ func DetectCurrentProjectType() models.ProjectType {
8878
}
8979
return DetectProjectType(cwd)
9080
}
81+
82+
func ListSupportedProjectTypes() []models.ProjectType {
83+
var types []models.ProjectType
84+
for _, detector := range detectors {
85+
types = append(types, detector.ProjectType())
86+
}
87+
return types
88+
}

internal/template/detector/indicator.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,3 @@ func anyFileExistsIndicator(filePaths ...string) indicatorFunc {
3838
return false
3939
}
4040
}
41-
42-
func anyDirExistsIndicator(dirPaths ...string) indicatorFunc {
43-
return func(projectPath string) bool {
44-
for _, dirPath := range dirPaths {
45-
if dirExistsIndicator(dirPath)(projectPath) {
46-
return true
47-
}
48-
}
49-
return false
50-
}
51-
}

0 commit comments

Comments
 (0)