diff --git a/LICENSE b/LICENSE index be32ba8..62ba285 100644 --- a/LICENSE +++ b/LICENSE @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +SOFTWARE. \ No newline at end of file diff --git a/akita/cmd/builderTemplate.txt b/akita/cmd/builderTemplate.txt index f984ed0..adcda51 100644 --- a/akita/cmd/builderTemplate.txt +++ b/akita/cmd/builderTemplate.txt @@ -1,3 +1,4 @@ +// Builder can create the component {{packageName}} with different configurations. package {{packageName}} import "github.com/sarchlab/akita/v4/sim" diff --git a/akita/cmd/compTemplate.txt b/akita/cmd/compTemplate.txt index daf644a..74ca672 100644 --- a/akita/cmd/compTemplate.txt +++ b/akita/cmd/compTemplate.txt @@ -1,3 +1,4 @@ +// Comp provides the component {{packageName}} with the ticking functionality. package {{packageName}} import "github.com/sarchlab/akita/v4/sim" diff --git a/akita/cmd/component.go b/akita/cmd/component.go index 036c283..0066009 100644 --- a/akita/cmd/component.go +++ b/akita/cmd/component.go @@ -17,13 +17,12 @@ var builderTemplate string //go:embed compTemplate.txt var compTemplate string -// componentCmd represents the main component command var componentCmd = &cobra.Command{ Use: "component", Short: "Create and manage components.", - Long: "`component --create [ComponentName]` creates a new component.", + Long: "`component --create [ComponentName]` creates a new component folder containing the builder and comp files", Run: func(cmd *cobra.Command, args []string) { - componentName, _ := cmd.Flags().GetString("create") // fetch the string value of the flag + componentName, _ := cmd.Flags().GetString("create") if componentName != "" { if !inGitRepo() { log.Fatalf("Error: This command must be run inside a Git repository.") @@ -37,15 +36,15 @@ var componentCmd = &cobra.Command{ errFile := generateBuilderFile(componentName) if errFile != nil { - fmt.Printf("Error generating builder file: %v\n", errFile) - } else { + log.Fatalf("Failed to generate builder file for component '%s': %v\n", componentName, errFile) + } else { fmt.Println("Builder File generated successfully!") } errComp := generateCompFile(componentName) if errComp != nil { - fmt.Printf("Error generating comp file: %v\n", errComp) - } else { + log.Fatalf("Failed to generate comp file for component '%s': %v\n", componentName, errFile) + } else { fmt.Println("Comp File generated successfully!") } @@ -57,7 +56,7 @@ var componentCmd = &cobra.Command{ func init() { rootCmd.AddCommand(componentCmd) - componentCmd.Flags().String("create", "", "Create a new component") + componentCmd.Flags().String("create", "", "create a new component") } // Check if current operation is in a Git repository @@ -66,7 +65,7 @@ func inGitRepo() bool { cmd.Dir = filepath.Dir(".") output, err := cmd.Output() if err != nil { - log.Printf("Error running git command: %v\n", err) + log.Fatalf("Error running git command: %v\n", err) return false } return strings.TrimSpace(string(output)) == "true" @@ -82,15 +81,15 @@ func createComponentFolder(name string) error { // Create basic files for the new component func generateBuilderFile(folder string) error { // Ensure the folder exists before proceeding - folder = filepath.Join("./akita", folder) - _, errFind := os.Stat(folder) + folderPath := filepath.Join("./akita", folder) + _, errFind := os.Stat(folderPath) if os.IsNotExist(errFind) { - return fmt.Errorf("failed to find folder: %s", folder) + return fmt.Errorf("failed to find folder: %s", folderPath) } else if errFind != nil { return fmt.Errorf("error checking folder: %v", errFind) } - filePath := filepath.Join(folder, "builder.go") + filePath := filepath.Join(folderPath, "builder.go") placeholder := "{{packageName}}" packageName := folder content := strings.Replace(builderTemplate, placeholder, packageName, -1) @@ -105,15 +104,15 @@ func generateBuilderFile(folder string) error { func generateCompFile(folder string) error { // Ensure the folder exists before proceeding - folder = filepath.Join("./akita", folder) - _, errFind := os.Stat(folder) + folderPath := filepath.Join("./akita", folder) + _, errFind := os.Stat(folderPath) if os.IsNotExist(errFind) { - return fmt.Errorf("failed to find folder: %s", folder) + return fmt.Errorf("failed to find folder: %s", folderPath) } else if errFind != nil { return fmt.Errorf("error checking folder: %v", errFind) } - filePath := filepath.Join(folder, "comp.go") + filePath := filepath.Join(folderPath, "comp.go") placeholder := "{{packageName}}" packageName := folder content := strings.Replace(compTemplate, placeholder, packageName, -1) diff --git a/akita/cmd/root.go b/akita/cmd/root.go index 9249219..39672f5 100644 --- a/akita/cmd/root.go +++ b/akita/cmd/root.go @@ -7,25 +7,16 @@ import ( "github.com/spf13/cobra" ) - - // rootCmd represents the base command when called without any subcommands var rootCmd = &cobra.Command{ Use: "akita", - Short: "A brief description of your application", - Long: `A longer description that spans multiple lines and likely contains -examples and usage of using your application. For example: - -Cobra is a CLI library for Go that empowers applications. -This application is a tool to generate the needed files -to quickly create a Cobra application.`, - // Uncomment the following line if your bare application - // has an action associated with it: - // Run: func(cmd *cobra.Command, args []string) { }, + Short: "akita command", + Long: `akita command is the root command for Akita framework. + It contains child commands that help users to manage components and files + in Akita.`, } // Execute adds all child commands to the root command and sets flags appropriately. -// This is called by main.main(). It only needs to happen once to the rootCmd. func Execute() { err := rootCmd.Execute() if err != nil { @@ -33,16 +24,6 @@ func Execute() { } } -func init() { - // Here you will define your flags and configuration settings. - // Cobra supports persistent flags, which, if defined here, - // will be global for your application. - - // rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.akita.yaml)") - - // Cobra also supports local flags, which will only run - // when this action is called directly. - rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") -} - - +func main() { + Execute() +} \ No newline at end of file diff --git a/main.go b/main.go deleted file mode 100644 index 09ff1fc..0000000 --- a/main.go +++ /dev/null @@ -1,11 +0,0 @@ -/* -Copyright © 2024 NAME HERE - -*/ -package main - -import "github.com/sarchlab/akita/v4/akita/cmd" - -func main() { - cmd.Execute() -}