Skip to content

refactor: naming conventions and errors handled to fix build issues #224

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
21 changes: 21 additions & 0 deletions cmd/custom-license.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package cmd

import (
"github.com/intelops/compage/cmd/subcommand/customlicense"
"github.com/sirupsen/logrus"
)

func init() {
// Create the logger instance
logger := logrus.New()
logger.SetFormatter(&logrus.TextFormatter{
FullTimestamp: true,
TimestampFormat: "2006-01-02 15:04:05",
})

// Create the instance for customlicense
customLicense := customlicense.NewCustomLicenseCmd(logger)

// Add Subcommand for the root command
rootCmd.AddCommand(customLicense.Execute())
}
21 changes: 0 additions & 21 deletions cmd/customLicense.go

This file was deleted.

24 changes: 12 additions & 12 deletions cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ Change the file as per your needs and then run the compage generate command to g
Run: func(cmd *cobra.Command, args []string) {
wD, err := os.Getwd()
if err != nil {
log.Errorf("error while getting the current directory [" + err.Error() + "]")
log.Errorf("error while getting the current directory: %v", err)
return
}
// set the project directory environment variable, if this is set, then the project will be generated in this folder
err = os.Setenv("COMPAGE_GENERATED_PROJECT_DIRECTORY", wD)
if err != nil {
log.Errorf("error while setting the project directory [" + err.Error() + "]")
log.Errorf("error while setting the project directory: %v", err)
return
}

Expand Down Expand Up @@ -59,7 +59,7 @@ func GenerateCode() error {
// converts to core project
coreProject, err := cmd.GetProject(project)
if err != nil {
log.Errorf("error while converting request to project [" + err.Error() + "]")
log.Errorf("error while converting request to project: %v", err)
return err
}

Expand All @@ -70,21 +70,21 @@ func GenerateCode() error {
// convert the license data to byte array
licenseData, err1 := json.Marshal(l)
if err1 != nil {
log.Errorf("error while marshalling license data [" + err1.Error() + "]")
log.Errorf("error while marshalling license data: %v", err1)
return err1
}
// convert the license data to license struct
err1 = json.Unmarshal(licenseData, license)
if err1 != nil {
log.Errorf("error while unmarshalling license data [" + err1.Error() + "]")
log.Errorf("error while unmarshalling license data: %v", err1)
return err1
}
// assign absolute path to the license file Path if it's not set
if len(license.Path) > 0 {
// assign absolute path to the license file Path if it's not
absPath, err2 := filepath.Abs(license.Path)
if err2 != nil {
log.Errorf("error while getting absolute path [" + err2.Error() + "]")
log.Errorf("error while getting absolute path: %v", err2)
return err2
}
license.Path = absPath
Expand All @@ -103,21 +103,21 @@ func GenerateCode() error {
// convert the license data to byte array
licenseData, err1 := json.Marshal(l)
if err1 != nil {
log.Errorf("error while marshalling license data [" + err1.Error() + "]")
log.Errorf("error while marshalling license data: %v", err1)
return err1
}
// convert the license data to license struct
err1 = json.Unmarshal(licenseData, license)
if err1 != nil {
log.Errorf("error while unmarshalling license data [" + err1.Error() + "]")
log.Errorf("error while unmarshalling license data: %v", err1)
return err1
}
// assign absolute path to the license file Path if it's not set
if len(license.Path) > 0 {
// assign absolute path to the license file Path if it's not
absPath, err2 := filepath.Abs(license.Path)
if err2 != nil {
log.Errorf("error while getting absolute path [" + err2.Error() + "]")
log.Errorf("error while getting absolute path: %v", err2)
return err2
}
license.Path = absPath
Expand All @@ -130,14 +130,14 @@ func GenerateCode() error {
// pull the common templates
err = ociregistry.PullOCIArtifact("common", project.CompageCoreVersion)
if err != nil {
log.Errorf("error while pulling the common templates [" + err.Error() + "]")
log.Errorf("error while pulling the common templates: %v", err)
return err
}
for _, node := range coreProject.CompageJSON.Nodes {
// make sure that the latest template is pulled
err = ociregistry.PullOCIArtifact(node.Language, project.CompageCoreVersion)
if err != nil {
log.Errorf("error while pulling the template [" + err.Error() + "]")
log.Errorf("error while pulling the template: %v", err)
return err
}
log.Debugf("template pulled successfully for language %s", node.Language)
Expand All @@ -146,7 +146,7 @@ func GenerateCode() error {
// triggers project generation, process the request
err0 := handlers.Handle(coreProject)
if err0 != nil {
log.Errorf("error while generating the project [" + err0.Error() + "]")
log.Errorf("error while generating the project: %v", err0)
return err
}
log.Infof("project generated successfully at %s", utils.GetProjectDirectoryName(project.Name))
Expand Down
4 changes: 2 additions & 2 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ func createOrUpdateDefaultConfigFile() error {

if language != "go" && language != "dotnet" {
message := fmt.Sprintf("language %s is not supported", language)
log.Errorf(message)
return fmt.Errorf(message)
log.Errorf("%s", message)
return fmt.Errorf("%s", message)
}

_, err = os.Create(configFilePath)
Expand Down
2 changes: 1 addition & 1 deletion cmd/subcommand/customLicense/constants.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package customLicense
package customlicense

const exampleCommand = `
# Convert XML file to JSON and YAML with the file path provided in the command line
Expand Down
4 changes: 2 additions & 2 deletions cmd/subcommand/customLicense/customLicense.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package customLicense
package customlicense

import (
import (
"io"
"net/http"
"os"
Expand Down
10 changes: 8 additions & 2 deletions cmd/subcommand/xmlconvert/xmlconvert.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,17 @@ func (xml *XMLConvertCmd) run(cmd *cobra.Command, args []string) {
// Check if only one output file is provided
if len(outputFiles) == 1 {
fileExtension := strings.Split(outputFiles[0], ".")[len(strings.Split(outputFiles[0], "."))-1]
CreateFile(xmlData, outputFiles[0], fileExtension)
err := CreateFile(xmlData, outputFiles[0], fileExtension)
if err != nil {
xml.logger.Fatal(err)
}
} else {
for _, file := range outputFiles {
fileExtension := strings.Split(file, ".")[len(strings.Split(file, "."))-1]
CreateFile(xmlData, file, fileExtension)
err := CreateFile(xmlData, file, fileExtension)
if err != nil {
xml.logger.Fatal(err)
}
}
}
}
Loading
Loading