init
This commit is contained in:
commit
23136281f1
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
.vscode/
|
||||
.idea/
|
||||
*.exe
|
||||
go.sum
|
21
cmd.go
Normal file
21
cmd.go
Normal file
@ -0,0 +1,21 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var (
|
||||
rootCmd = &cobra.Command{
|
||||
Use: "mder",
|
||||
Short: "mder is a very fast static site generator",
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
// create a new mder folder
|
||||
rootCmd.AddCommand(initCmd())
|
||||
}
|
||||
|
||||
func main() {
|
||||
rootCmd.Execute()
|
||||
}
|
10
go.mod
Normal file
10
go.mod
Normal file
@ -0,0 +1,10 @@
|
||||
module mder
|
||||
|
||||
go 1.18
|
||||
|
||||
require github.com/spf13/cobra v1.5.0
|
||||
|
||||
require (
|
||||
github.com/inconshreveable/mousetrap v1.0.0 // indirect
|
||||
github.com/spf13/pflag v1.0.5 // indirect
|
||||
)
|
25
init.go
Normal file
25
init.go
Normal file
@ -0,0 +1,25 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"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 err := cloneTemplate(name); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
_, _ = fmt.Fprintf(os.Stdout, "create folder %s success.\n", name)
|
||||
},
|
||||
}
|
||||
|
||||
cmd.Flags().StringVar(&name, "name", "mder", "Name of the folder to create")
|
||||
return cmd
|
||||
}
|
16
utils.go
Normal file
16
utils.go
Normal file
@ -0,0 +1,16 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
func cloneTemplate(base string) error {
|
||||
_, err := exec.Command("git", "clone", "https://gitter.top/mder/template", base).Output()
|
||||
if err != nil {
|
||||
_, _ = fmt.Fprintf(os.Stderr, "get latest template failed: %v\n", err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
Loading…
Reference in New Issue
Block a user