Skip to content

Commit

Permalink
format update
Browse files Browse the repository at this point in the history
  • Loading branch information
syifan committed Dec 3, 2024
1 parent b761399 commit b7976c9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
37 changes: 19 additions & 18 deletions akita/cmd/component.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
package cmd

import (
_ "embed"
"fmt"
"log"
"os"
"os/exec"
"path/filepath"
"strings"
_ "embed"

"github.com/spf13/cobra"
)

//go:embed builderTemplate.txt
var builderTemplate string

//go:embed compTemplate.txt
var compTemplate string

Expand All @@ -32,7 +33,7 @@ var componentCmd = &cobra.Command{
if err != nil {
log.Fatalf("Error creating component: %v", err)
} else {
fmt.Printf("Component '%s' created successfully!\n", componentName)
fmt.Printf("Component '%s' created successfully!\n", componentName)
}

errFile := generateBuilderFile(componentName)
Expand Down Expand Up @@ -74,23 +75,23 @@ func inGitRepo() bool {
// Create folder for the new component
func createComponentFolder(name string) error {
if _, err := os.Stat(name); err == nil {
return fmt.Errorf("folder '%s' already exists", name)
} else if !os.IsNotExist(err) {
return fmt.Errorf("%v", err)
}
return fmt.Errorf("folder '%s' already exists", name)
} else if !os.IsNotExist(err) {
return fmt.Errorf("%v", err)
}

return os.MkdirAll(name, 0755)
}

// Create builder file for the new component
func generateBuilderFile(folder string) error {
// Ensure the folder exists before proceeding
// Ensure the folder exists before proceeding
_, errFind := os.Stat(folder)
if os.IsNotExist(errFind) {
return fmt.Errorf("failed to find folder %s", folder)
} else if errFind != nil {
return fmt.Errorf("%v", errFind)
}
if os.IsNotExist(errFind) {
return fmt.Errorf("failed to find folder %s", folder)
} else if errFind != nil {
return fmt.Errorf("%v", errFind)
}

filePath := filepath.Join(folder, "builder.go")
placeholder := "{{packageName}}"
Expand All @@ -109,11 +110,11 @@ func generateBuilderFile(folder string) error {
func generateCompFile(folder string) error {
// Ensure the folder exists before proceeding
_, errFind := os.Stat(folder)
if os.IsNotExist(errFind) {
return fmt.Errorf("failed to find folder: %s", folder)
} else if errFind != nil {
return fmt.Errorf("%v", errFind)
}
if os.IsNotExist(errFind) {
return fmt.Errorf("failed to find folder: %s", folder)
} else if errFind != nil {
return fmt.Errorf("%v", errFind)
}

filePath := filepath.Join(folder, "comp.go")
placeholder := "{{packageName}}"
Expand All @@ -126,4 +127,4 @@ func generateCompFile(folder string) error {
}

return nil
}
}
2 changes: 1 addition & 1 deletion akita/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ func Execute() {
if err != nil {
os.Exit(1)
}
}
}
4 changes: 2 additions & 2 deletions akita/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ package main
import "github.com/sarchlab/akita/v4/akita/cmd"

func main() {
cmd.Execute()
}
cmd.Execute()
}

0 comments on commit b7976c9

Please sign in to comment.