You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

35 lines
747 B

package main
import (
"fmt"
"regexp"
"github.com/spf13/cobra"
)
func initCmd() *cobra.Command {
var name string
cmd := &cobra.Command{
Use: "init",
Short: "create a new mder folder",
Run: func(cmd *cobra.Command, args []string) {
if name == "" {
if len(args) != 0 {
name = args[0]
}
}
var rule = fmt.Sprintf("[a-zA-Z0-9_]{%d}", len(name))
var reg = regexp.MustCompilePOSIX(rule)
if !reg.MatchString(name) {
sfault("folder name must be %s", rule)
}
if err := cloneTemplate(name); err != nil {
sfault("clone template repository failed: %v", err)
}
sout("create folder %s success.", name)
},
}
cmd.Flags().StringVar(&name, "name", "", "Name of the folder to create")
return cmd
}