aboutsummaryrefslogtreecommitdiffstats
path: root/qt-cli/cmd/new-class.go
blob: 7d6634d562b1830aaaec949ab71e3e9e54fcfae4 (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
// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only

package cmd

import (
	"qtcli/generator"
	"qtcli/util"

	"github.com/sirupsen/logrus"
	"github.com/spf13/cobra"
)

var classType string
var base string

var cppMacroList []string
var cppIncludeList []string
var cppIsQObject bool

var pythonModuleName string
var pythonImportList []string

var newClassCmd = &cobra.Command{
	Use:   "class <name> --type <type>",
	Short: util.Msg("Create a new class"),
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) < 1 {
			cmd.Help()
			return
		}

		g := generator.NewGenerator(&generator.GeneratorInputData{
			Category:          generator.TargetCategoryClass,
			Type:              classType,
			Name:              args[0],
			OutputDir:         outputDir,
			LicenseFile:       licenseTemplatePath,
			CustomTemplateDir: customTemplateDir,

			CppBaseClass:      base,
			CppMacroList:      cppMacroList,
			CppIncludeList:    cppIncludeList,
			CppClassIsQObject: cppIsQObject,
			CppUsePragma:      true,

			PythonBaseClass:  base,
			PythonModuleName: pythonModuleName,
			PythonImportList: pythonImportList,
		})

		_, err := g.Run()
		if err != nil {
			logrus.Fatal(err)
		}
	},
}

func init() {
	// common
	flags := newClassCmd.Flags()
	flags.StringVarP(
		&classType, "type", "t", "",
		util.Msg("Specify file type to create"))

	flags.StringVarP(
		&base, "base", "b", "",
		util.Msg("Base class name"))

	newClassCmd.MarkFlagRequired("type")

	// cpp related
	flags.StringSliceVarP(
		&cppMacroList, "add", "a", []string{},
		util.Msg("Qt macro to add. (e.g., Q_OBJECT, QML_ELEMENT)"))

	flags.StringSliceVarP(
		&cppIncludeList, "include", "i", []string{},
		util.Msg("Qt classe to include in a header file"))

	flags.BoolVarP(
		&cppIsQObject, "qobject", "q", false,
		util.Msg("Specify if class is a QObject-derived class"))

	// python related
	flags.StringVarP(
		&pythonModuleName, "module", "m", "PySide6",
		util.Msg("Qt for Python Module"))

	flags.StringSliceVar(
		&pythonImportList, "import", []string{},
		util.Msg("Qt classe to import"))

	newCmd.AddCommand(newClassCmd)
}