-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.go
More file actions
68 lines (61 loc) · 1.6 KB
/
init.go
File metadata and controls
68 lines (61 loc) · 1.6 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main
import (
"fmt"
"log"
"os"
"path/filepath"
)
var initCmd = &Command{
Run: initProject,
Name: "init",
Short: "initializes empty Tizen project.",
UsageLine: "",
Long: `
`,
}
var projectDirs = []string{
"bin",
"shared",
}
// creates all project files
func createFile(path string, file PackageFile) error {
f, err := os.Create(path)
if err != nil {
return fmt.Errorf("Unable to write %s, aborting\n", file.PackagePath())
}
bytes, err := file.MarshalBinary()
if err != nil {
f.Close()
return fmt.Errorf("Marshaling %s failed.\n%v", file.PackagePath(), err)
}
_, err = f.Write(bytes)
if err != nil {
f.Close()
return fmt.Errorf("File write failed")
}
return f.Close()
}
func initProject(context *Context) {
if context.Manifest != nil {
log.Fatalf("Tizen mainfest found in %s. Unable to init project.\n", context.ProjectRootPath)
}
defaultManifest := NewTizenManifest(filepath.Base(context.ProjectRootPath))
defaultProjectFiles := make([]PackageFile, 1)
defaultProjectFiles[0] = defaultManifest
// create project dirs
for _, dir := range projectDirs {
fullPath := filepath.Join(context.ProjectRootPath, dir)
err := os.Mkdir(fullPath, 0777)
if err != nil {
log.Fatalf("Unable to create Tizen project directories\n%v", err)
}
}
// create project files
for _, pf := range defaultProjectFiles {
fullPath := filepath.Join(context.ProjectRootPath, pf.PackagePath())
if err := createFile(fullPath, pf); err != nil {
log.Fatal("Unable to create Tizen project files: ", err)
}
}
fmt.Println("Initialized empty Tizen project in: ", context.ProjectRootPath)
}