-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #184 from intelops/add-cli
Add cli
- Loading branch information
Showing
524 changed files
with
82,213 additions
and
1,701 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,4 @@ openapitools.json | |
/openapitools.json | ||
/deploy/build/ | ||
compage | ||
/config.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"version": "1.0.0", | ||
"configurations": [ | ||
{ | ||
"name": "Debug cli", | ||
"type": "go", | ||
"request": "launch", | ||
"mode": "debug", | ||
"program": "${workspaceRoot}/main.go", | ||
"cwd": "${workspaceRoot}", | ||
"args": ["generate"] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"files.insertFinalNewline": true, | ||
"files.trimFinalNewlines": true, | ||
"go.autocompleteUnimportedPackages": true, | ||
"go.installDependenciesWhenBuilding": false, | ||
"go.formatTool": "goimports", | ||
"go.coverOnTestPackage": true, | ||
"go.useLanguageServer": true, | ||
"editor.tabSize": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
project: | ||
name: {{.ProjectName}} | ||
git: | ||
repository: | ||
name: {{.GitRepositoryName}} | ||
url: {{.GitRepositoryURL}} | ||
platform: | ||
name: {{.GitPlatformName}} | ||
url: {{.GitPlatformURL}} | ||
userName: {{.GitPlatformUserName}} | ||
{{if .IsRestServer}} | ||
compageJSON: | ||
edges: [] | ||
nodes: | ||
- id: node-ef | ||
name: user-service | ||
language: go | ||
restConfig: | ||
server: | ||
sqlDB: Map | ||
port: '1337' | ||
resources: | ||
- fields: | ||
Name: | ||
datatype: string | ||
Age: | ||
datatype: int | ||
name: User | ||
framework: go-gin-server | ||
template: compage | ||
{{end}} | ||
{{if .IsGrpcServer}} | ||
compageJSON: | ||
edges: [] | ||
nodes: | ||
- id: node-c5 | ||
name: user-service | ||
language: go | ||
grpcConfig: | ||
server: | ||
sqlDB: SQLite | ||
port: '50033' | ||
resources: | ||
- name: User | ||
allowedMethods: | ||
- POST | ||
- LIST | ||
- GET | ||
- PUT | ||
- DELETE | ||
fields: | ||
Name: | ||
datatype: string | ||
City: | ||
datatype: string | ||
template: compage | ||
framework: go-grpc-server | ||
{{end}} | ||
{{if .IsRestAndGrpcServer}} | ||
compageJSON: | ||
edges: | ||
- dest: node-90 | ||
id: edge-12 | ||
src: node-ee | ||
name: user-service-to-account-service | ||
nodes: | ||
- id: node-ee | ||
name: user-service | ||
language: go | ||
restConfig: | ||
server: | ||
sqlDB: MySQL | ||
port: '3000' | ||
resources: | ||
- name: User | ||
allowedMethods: | ||
- POST | ||
- LIST | ||
- GET | ||
- PUT | ||
- DELETE | ||
fields: | ||
Name: | ||
datatype: string | ||
City: | ||
datatype: string | ||
template: compage | ||
framework: go-gin-server | ||
- id: node-90 | ||
name: account-service | ||
language: go | ||
grpcConfig: | ||
server: | ||
sqlDB: MongoDB | ||
port: '50033' | ||
resources: | ||
- name: Account | ||
allowedMethods: | ||
- POST | ||
- LIST | ||
- GET | ||
- PUT | ||
- DELETE | ||
fields: | ||
Name: | ||
datatype: string | ||
AccountNumber: | ||
datatype: string | ||
City: | ||
datatype: string | ||
template: compage | ||
framework: go-grpc-server | ||
{{end}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/intelops/compage/cmd/models" | ||
"github.com/intelops/compage/internal/converter/cmd" | ||
"github.com/intelops/compage/internal/handlers" | ||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// generateCmd represents the generate command | ||
var generateCmd = &cobra.Command{ | ||
Use: "generate", | ||
Short: "Generates the code for the given configuration", | ||
Long: `This will generate the code for the given configuration. The configuration file is a yaml file that contains the configuration that guides the compage to generate the code. | ||
Change the file as per your needs and then run the compage generate command to generate the code.`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
GenerateCode() | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(generateCmd) | ||
|
||
// Here you will define your flags and configuration settings. | ||
|
||
// Cobra supports Persistent Flags which will work for this command | ||
// and all subcommands, e.g.: | ||
// generateCmd.PersistentFlags().String("foo", "", "A help for foo") | ||
|
||
// Cobra supports local flags which will only run when this command | ||
// is called directly, e.g.: | ||
// generateCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") | ||
} | ||
|
||
func GenerateCode() { | ||
// Read the file from the current directory and convert it to project | ||
project, err := models.ReadConfigYAMLFile("config.yaml") | ||
cobra.CheckErr(err) | ||
|
||
// converts to core project | ||
coreProject, err := cmd.GetProject(project) | ||
if err != nil { | ||
log.Debugf("error while converting request to project [" + err.Error() + "]") | ||
return | ||
} | ||
|
||
// triggers project generation, process the request | ||
if err0 := handlers.Handle(coreProject); err0 != nil { | ||
log.Debugf("error while generating the project [" + err0.Error() + "]") | ||
} | ||
log.Info("project generated successfully") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/intelops/compage/cmd/prompts" | ||
"github.com/intelops/compage/internal/languages/executor" | ||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
"os" | ||
) | ||
|
||
// initCmd represents the init command | ||
var initCmd = &cobra.Command{ | ||
Use: "init", | ||
Short: "Initializes the compage configuration, generates the file and writes it down in the current directory", | ||
Long: `Compage configuration file is a yaml file that contains the configuration that guides the compage to generate the code. | ||
You can change the file as per your needs and then run the compage generate command to generate the code.`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
projectDetails, err := prompts.GetProjectDetails() | ||
cobra.CheckErr(err) | ||
gitPlatformDetails, err := prompts.GetGitPlatformDetails() | ||
cobra.CheckErr(err) | ||
var serverType string | ||
if len(args) == 1 { | ||
serverType = args[0] | ||
} else { | ||
serverType = "rest" | ||
} | ||
createOrUpdateDefaultConfigFile(projectDetails, gitPlatformDetails, serverType) | ||
}, | ||
} | ||
|
||
func createOrUpdateDefaultConfigFile(pd *prompts.ProjectDetails, gpd *prompts.GitPlatformDetails, serverType string) { | ||
// create default config file | ||
configFilePath := "config.yaml" | ||
_, err := os.Stat(configFilePath) | ||
if os.IsExist(err) { | ||
log.Warnf("config file already exists at %s", configFilePath) | ||
overwriteConfirmation, err := prompts.GetInputBoolean("Do you want to overwrite the existing config file? (y/n)", false) | ||
cobra.CheckErr(err) | ||
if overwriteConfirmation == "n" { | ||
log.Infof("skipping config file creation") | ||
return | ||
} | ||
} | ||
|
||
err = os.Remove(configFilePath) | ||
if err != nil && !os.IsNotExist(err) { | ||
log.Warnf("error while removing the config file %s", err) | ||
cobra.CheckErr(err) | ||
} | ||
_, err = os.Create(configFilePath) | ||
cobra.CheckErr(err) | ||
contentData, err := Content.ReadFile("config.yaml.tmpl") | ||
cobra.CheckErr(err) | ||
// copy the default config file and use go template to replace the values | ||
err = os.WriteFile(configFilePath, contentData, 0644) | ||
cobra.CheckErr(err) | ||
|
||
var filePaths []*string | ||
filePaths = append(filePaths, &configFilePath) | ||
data := make(map[string]interface{}) | ||
data["ProjectName"] = pd.ProjectName | ||
data["GitRepositoryName"] = gpd.RepositoryName | ||
data["GitRepositoryURL"] = gpd.PlatformURL + "/" + gpd.PlatformUserName + "/" + gpd.RepositoryName | ||
data["GitPlatformName"] = gpd.PlatformName | ||
data["GitPlatformURL"] = gpd.PlatformURL | ||
data["GitPlatformUserName"] = gpd.PlatformUserName | ||
if serverType == "grpc" { | ||
data["IsRestAndGrpcServer"] = false | ||
data["IsGrpcServer"] = true | ||
data["IsRestServer"] = false | ||
} else if serverType == "rest-grpc" { | ||
data["IsRestAndGrpcServer"] = true | ||
data["IsGrpcServer"] = false | ||
data["IsRestServer"] = false | ||
} else { | ||
log.Info("defaulting to serverType config `rest`") | ||
data["IsRestAndGrpcServer"] = false | ||
data["IsGrpcServer"] = false | ||
data["IsRestServer"] = true | ||
} | ||
err = executor.Execute(filePaths, data) | ||
cobra.CheckErr(err) | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(initCmd) | ||
|
||
// Here you will define your flags and configuration settings. | ||
|
||
// Cobra supports Persistent Flags which will work for this command | ||
// and all subcommands, e.g.: | ||
// initCmd.PersistentFlags().String("foo", "", "A help for foo") | ||
|
||
// Cobra supports local flags which will only run when this command | ||
// is called directly, e.g.: | ||
// initCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") | ||
} |
Oops, something went wrong.