-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
command_new.go
45 lines (35 loc) · 657 Bytes
/
command_new.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main
import (
"fmt"
"os"
"os/exec"
"path/filepath"
"github.com/urfave/cli"
)
var commandNew = cli.Command{
Name: "new",
Action: doNew,
}
func check(e error) {
if e != nil {
fmt.Println(e)
os.Exit(1)
}
}
func doNew(c *cli.Context) error {
name := c.Args().Get(0)
target := compileTargetPath(name)
err := exec.Command("mkdir", "-p", target).Run()
check(err)
err = os.Chdir(target)
check(err)
err = exec.Command("git", "init").Run()
check(err)
f, err := os.Create(filepath.Join(target, "README.md"))
check(err)
defer f.Close()
_, err = f.WriteString("# " + name + "\n")
f.Sync()
fmt.Println(target)
return nil
}