init
This commit is contained in:
commit
23136281f1
|
@ -0,0 +1,4 @@
|
||||||
|
.vscode/
|
||||||
|
.idea/
|
||||||
|
*.exe
|
||||||
|
go.sum
|
|
@ -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()
|
||||||
|
}
|
|
@ -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
|
||||||
|
)
|
|
@ -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
|
||||||
|
}
|
|
@ -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