/* Copyright © 2025 Wiki Cafe This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ package cmd import ( "fmt" "os" "path/filepath" "github.com/spf13/cobra" ) // initCmd represents the init command var initCmd = &cobra.Command{ Use: "init [path]", Short: "Create the directory structure needed for the member-console", Long: `The init command creates the directory structure and files needed for the member-console web application in the current directory. A different directory can be specified using the --dir flag.`, Args: cobra.ExactArgs(1), Run: func(cmd *cobra.Command, args []string) { fmt.Println("init called") // Create the directories and files needed for the member-console web application targetDir := args[0] // Create the target directory if it doesn't exist if err := os.MkdirAll(targetDir, 0755); err != nil { fmt.Fprintf(os.Stderr, "Error creating target directory: %v\n", err) os.Exit(1) } // Create the templates, static, and assets directories directories := []string{"templates", "static", "assets"} for _, dir := range directories { dirPath := filepath.Join(targetDir, dir) if err := os.MkdirAll(dirPath, 0755); err != nil { fmt.Fprintf(os.Stderr, "Error creating %s directory: %v\n", dir, err) os.Exit(1) } } // Create the config.yaml file configFilePath := filepath.Join(targetDir, "mc-config.yaml") configFile, err := os.Create(configFilePath) if err != nil { fmt.Fprintf(os.Stderr, "Error creating config file: %v\n", err) os.Exit(1) } defer configFile.Close() // Write default config to the config file defaultConfig := "# Default configuration for member-console\n" if _, err := configFile.WriteString(defaultConfig); err != nil { fmt.Fprintf(os.Stderr, "Error writing to config file: %v\n", err) os.Exit(1) } fmt.Printf("Created config file at %s\n", configFilePath) fmt.Printf("Project initialized at %s\n", targetDir) }, } func init() { rootCmd.AddCommand(initCmd) }