aboutsummaryrefslogtreecommitdiffstats
path: root/qt-cli/prompt/prompt-class.go
blob: 65138e708a284794842df036d87930cc55cbc213 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package prompt

import (
	"qtcli/generator"

	"github.com/manifoldco/promptui"
)

func runTypeSelection() (generator.TargetType, error) {
	items := []struct {
		Name string
		Id   generator.TargetType
	}{
		{Name: "C++ Class", Id: generator.TargetClassCpp},
		{Name: "Python Class", Id: generator.TargetClassPython},
	}

	templates := &promptui.SelectTemplates{
		Selected: "{{ .Name }}",
		Inactive: "\U00002002 {{ .Name }}",
		Active:   "\U00002192 {{ .Name | bold | underline }}",
	}

	prompt := promptui.Select{
		Label:     "What do you want to create?",
		Items:     items,
		Templates: templates,
	}

	index, _, err := prompt.Run()
	if err != nil {
		return generator.TargetTypeInvalid, err
	}

	return items[index].Id, nil
}

func RunNewCppClass() (generator.GeneratorInputData, error) {
	fallback := generator.GeneratorInputData{}
	promptName := promptui.Prompt{
		Label: "Class Name",
	}

	promptBaseClass := promptui.Prompt{
		Label: "Base class",
	}

	promptOutputDir := promptui.Prompt{
		Label: "Output Dir",
	}

	className, err := promptName.Run()
	if err != nil {
		return fallback, err
	}

	baseClass, err := promptBaseClass.Run()
	if err != nil {
		return fallback, err
	}

	outputDir, err := promptOutputDir.Run()
	if err != nil {
		return fallback, err
	}

	return generator.GeneratorInputData{
		Category:     generator.TargetCategoryClass,
		Type:         "cpp",
		Name:         className,
		OutputDir:    outputDir,
		CppBaseClass: baseClass,
	}, nil
}

func RunNewPythonClass() (generator.GeneratorInputData, error) {
	fallback := generator.GeneratorInputData{}
	promptModule := promptui.Prompt{
		Label: "Python Module (PySide6, PySide2, etc)",
	}

	promptName := promptui.Prompt{
		Label: "Class Name (could include namespaces)",
	}

	promptBaseClass := promptui.Prompt{
		Label: "Base class",
	}

	promptOutputDir := promptui.Prompt{
		Label: "Output Dir",
	}

	moduleName, err := promptModule.Run()
	if err != nil {
		return fallback, err
	}

	className, err := promptName.Run()
	if err != nil {
		return fallback, err
	}

	baseClass, err := promptBaseClass.Run()
	if err != nil {
		return fallback, err
	}

	outputDir, err := promptOutputDir.Run()
	if err != nil {
		return fallback, err
	}

	return generator.GeneratorInputData{
		Category:         generator.TargetCategoryClass,
		Type:             "python",
		Name:             className,
		OutputDir:        outputDir,
		PythonBaseClass:  baseClass,
		PythonModuleName: moduleName,
	}, nil
}