-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
90 lines (74 loc) · 1.85 KB
/
main.go
File metadata and controls
90 lines (74 loc) · 1.85 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package main
import (
"fmt"
"os"
"path/filepath"
"github.com/codegangsta/cli"
)
// Package ...
var Package = func(c *cli.Context) {
inputPath := ""
if c.IsSet("sfprojects") {
inputPath = c.String("sfprojects")
} else {
Exit("sfprojects must be set")
}
outputPath := ""
if c.IsSet("output") {
outputPath = c.String("output")
} else {
Exit("Output must be set")
}
prepareOutput(outputPath)
projectFilesToProcess := findProjectFiles(inputPath)
var sfApps []*SfApp
fmt.Printf("Scanning %s for ServiceFabric applications ...\n", inputPath)
for _, value := range projectFilesToProcess {
sfApp := &SfApp{}
sfApp.Init(value)
sfApps = append(sfApps, sfApp)
}
for _, v := range sfApps {
v.ReadManifest()
fmt.Printf("%s - %s\n", v.applicationName, v.appManifestFile)
}
}
func prepareOutput(path string) {
exists, info, err := CheckPath(path)
if err != nil {
Exit("Something went wrong clearing output folder")
}
if exists && info.IsDir() {
err = os.RemoveAll(path)
if err != nil {
Exit("Somthing went wrong clearing output folder")
}
} else if exists && !info.IsDir() {
err = os.Remove(path)
if err != nil {
Exit("Somthing went wrong clearing output folder")
}
}
err = os.MkdirAll(path, os.ModeDir)
if err != nil {
Exit("Somthing went wrong creating output folder")
}
}
func findProjectFiles(path string) []string {
exist, fileInfo, err := CheckPath(path)
if err != nil {
Exit("Should not have happened")
}
var projectFilesToProcess []string
if exist == true {
if fileInfo.IsDir() {
ignoreDirs := []string{".git", "bin", "obj", "pkg", "node_modules", "packages", "Backup"}
err = filepath.Walk(path, FindFiles(ignoreDirs, "*.sfproj", &projectFilesToProcess))
} else {
projectFilesToProcess = append(projectFilesToProcess, "ye")
}
} else {
Exit("Invalid path given")
}
return projectFilesToProcess
}