-
Notifications
You must be signed in to change notification settings - Fork 11
/
main.go
161 lines (134 loc) · 3.99 KB
/
main.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
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
package main
// Copyright 2013-2014 Vubeology, Inc.
//===============================================
import (
"flag"
"fmt"
"log"
"os"
"runtime"
"strings"
"github.com/vube/depman/add"
"github.com/vube/depman/colors"
"github.com/vube/depman/create"
"github.com/vube/depman/dep"
"github.com/vube/depman/install"
"github.com/vube/depman/result"
"github.com/vube/depman/showfrozen"
"github.com/vube/depman/timelock"
"github.com/vube/depman/update"
"github.com/vube/depman/upgrade"
"github.com/vube/depman/util"
)
// Version number
// This should ALWAYS have 3 parts, (e.g. X.Y.Z) this is so upgrade.Check() works correctly
const VERSION string = "2.9.5"
//===============================================
func main() {
var help bool
var path string
var command string
var arguments []string
var deps dep.DependencyMap
var err error
log.SetFlags(0)
flag.BoolVar(&help, "help", false, "Display help")
flag.StringVar(&path, "path", ".", "Directory or full path to deps.json")
util.Parse()
util.Version(VERSION)
fmt.Println(colors.Red("Depman was deprecated on 25 February 2015"))
fmt.Println(colors.Red("We recommend using 'godep' instead: https://github.com/tools/godep"))
util.GoPathIsSet()
if timelock.Clear() {
return
}
timelock.Read()
// check for a new version of depman
go upgrade.Check(VERSION)
runtime.Gosched()
defer upgrade.Print()
path = dep.GetPath(path)
if flag.NArg() > 0 {
command = strings.ToLower(flag.Arg(0))
}
if flag.NArg() > 1 {
arguments = flag.Args()[1:]
}
if help {
command = "help"
}
// switch to check for deps.json
switch command {
case "add", "", "install", "update", "show-frozen":
// check for deps.json
util.CheckPath(path)
deps, err = dep.Read(path)
if err != nil {
util.Fatal(colors.Red("Error Reading deps.json: " + err.Error()))
}
}
// switch to exec the sub command
switch command {
case "init", "create":
create.Create(path)
case "add":
if len(arguments) < 1 {
util.Print(colors.Red("Add command requires 1 argument: Add [nickname]"))
Help()
} else {
add.Add(deps, arguments[0])
}
case "update":
if len(arguments) < 2 {
util.Print(colors.Red("Update command requires 2 arguments: Update [nickname] [branch]"))
Help()
} else {
update.Update(deps, arguments[0], arguments[1])
}
case "install", "":
install.Install(deps)
case "self-upgrade":
upgrade.Self(VERSION)
case "show-frozen":
var recursive bool
flagset := flag.NewFlagSet("show-frozen", flag.ExitOnError)
flagset.BoolVar(&recursive, "recursive", false, "descend recursively (depth-first) into dependencies")
flagset.Parse(flag.Args()[1:])
if recursive {
fmt.Println(showfrozen.ReadRecursively(deps, nil))
} else {
fmt.Print(showfrozen.Read(deps))
}
default:
result.RegisterError()
log.Println(colors.Red("Unknown Command: " + command))
fallthrough
case "help":
Help()
}
timelock.Write()
if result.ShouldExitWithError() {
os.Exit(1)
} else {
util.Print("Success")
}
}
//===============================================
// Help prints the help message for depman
func Help() {
log.Println("")
log.Println("Commands:")
log.Println(" Init : Create an empty deps.json")
log.Println(" Add [nickname] : Add a dependency (interactive)")
log.Println(" Install : Install all the dependencies listed in deps.json (default)")
log.Println(" Update [nickname] [branch] : Update [nickname] to use the latest commit in [branch]")
log.Println(" Self-Upgrade : Upgrade depman to the latest version on the master branch")
log.Println(" Help : Display this help")
log.Println(" Show-Frozen : Show dependencies as resolved to commit IDs")
log.Println("")
log.Println("Example: depman --verbose install")
log.Println("")
//log.Println(" freeze : For each dependency change tag and branch versions to commits (not yet implemented)")
log.Println("Options:")
flag.PrintDefaults()
}