Skip to content

Commit

Permalink
Merge pull request #190 from intelops/change-folder-for-generated-pro…
Browse files Browse the repository at this point in the history
…ject

enhancement: changed the folder for generated project and fixed the g…
  • Loading branch information
mahendraintelops authored Nov 28, 2023
2 parents 8ef2545 + 1ff6ef0 commit dc80967
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ on:
tags:
- "v*.*.*"
permissions:
contents: write
contents: write # needed to write releases
id-token: write # needed for keyless signing
packages: write # needed for ghcr access

jobs:
push_to_registry:
name: Build and push Docker image github container registry.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,10 @@ git clone https://github.com/intelops/compage.git
cd compage
go build -o compage .
## initialize the config.yaml file
./compage init
./compage init --serverType grpc
## edit the config.yaml file as per your requirement
## generate the code. Below command accepts serverType [rest, grpc and rest-grpc]
./compage generate grpc
./compage generate
```

## Contributing
Expand Down
13 changes: 12 additions & 1 deletion cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/intelops/compage/internal/utils"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"os"
)

// generateCmd represents the generate command
Expand All @@ -23,7 +24,17 @@ Change the file as per your needs and then run the compage generate command to g

func init() {
rootCmd.AddCommand(generateCmd)

wD, err := os.Getwd()
if err != nil {
log.Errorf("error while getting the current directory [" + err.Error() + "]")
return
}
// set the project folder environment variable, if this is set, then the project will be generated in this folder
err = os.Setenv("COMPAGE_GENERATED_PROJECT_FOLDER", wD)
if err != nil {
log.Errorf("error while setting the project folder [" + err.Error() + "]")
return
}
// Here you will define your flags and configuration settings.

// Cobra supports Persistent Flags which will work for this command
Expand Down
1 change: 1 addition & 0 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func createOrUpdateDefaultConfigFile() {
log.Infof("skipping config file creation")
return
}
log.Infof("overwriting the config file")
err = os.Remove(configFilePath)
if err != nil {
log.Warnf("error while removing the config file %s", err)
Expand Down
5 changes: 5 additions & 0 deletions internal/utils/fileUtils.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ import (

// GetProjectDirectoryName returns tarFile parent path
func GetProjectDirectoryName(name string) string {
projectDirectoryName := os.Getenv("COMPAGE_GENERATED_PROJECT_FOLDER")
if projectDirectoryName != "" {
return projectDirectoryName + "/" + name
}

userHomeDir, err := os.UserHomeDir()
if err != nil {
log.Debugf("Error getting user home directory: %s", err)
Expand Down

0 comments on commit dc80967

Please sign in to comment.