@@ -16,7 +16,6 @@ var tagsMode bool
16
16
var installedMode bool
17
17
var check bool
18
18
var plan bool
19
- var toolStatus map [string ]tool.ToolStatus = make (map [string ]tool.ToolStatus )
20
19
var requestedTools tool.Tools
21
20
var plannedTools tool.Tools
22
21
var reinstall bool
@@ -28,11 +27,11 @@ func initInstallCmd() {
28
27
rootCmd .AddCommand (installCmd )
29
28
30
29
installCmd .Flags ().StringVarP (& installMode , "mode" , "m" , "default" , "How to install (default, tags, installed)" )
31
- installCmd .Flags ().BoolVarP ( & defaultMode , "default" , "d" , false , "Install default tools" )
32
- installCmd .Flags ().BoolVarP ( & tagsMode , "tags" , "t" , false , "Install tool(s) matching tag" )
30
+ installCmd .Flags ().BoolVarP ( & defaultMode , "default" , "" , false , "Install default tools" )
31
+ installCmd .Flags ().BoolVarP ( & tagsMode , "tags" , "" , false , "Install tool(s) matching tag" )
33
32
installCmd .Flags ().BoolVarP ( & installedMode , "installed" , "i" , false , "Update installed tool(s)" )
34
- installCmd .Flags ().BoolVarP ( & plan , "plan" , "p" , false , "Show tool(s) planned installation" )
35
- installCmd .Flags ().BoolVarP ( & check , "check" , "c" , false , "Abort after checking versions" )
33
+ installCmd .Flags ().BoolVarP ( & plan , "plan" , "" , false , "Show tool(s) planned installation" )
34
+ installCmd .Flags ().BoolVarP ( & check , "check" , "c" , false , "Abort after checking versions" )
36
35
installCmd .Flags ().BoolVarP ( & reinstall , "reinstall" , "r" , false , "Reinstall tool(s)" )
37
36
installCmd .MarkFlagsMutuallyExclusive ("mode" , "default" , "tags" , "installed" )
38
37
installCmd .MarkFlagsMutuallyExclusive ("check" , "plan" )
@@ -43,8 +42,8 @@ var installCmd = &cobra.Command{
43
42
Aliases : []string {"i" },
44
43
Short : "Install tools" ,
45
44
Long : header + "\n Install and update tools" ,
46
- ValidArgs : tools .GetNames (),
47
45
Args : cobra .OnlyValidArgs ,
46
+ ValidArgs : tools .GetNames (),
48
47
RunE : func (cmd * cobra.Command , args []string ) error {
49
48
50
49
// Validation checks
@@ -56,31 +55,7 @@ var installCmd = &cobra.Command{
56
55
}
57
56
58
57
assertMetadataFileExists ()
59
- tools , err := tool .LoadFromFile (metadataFile )
60
- if err != nil {
61
- return fmt .Errorf ("Failed to load metadata from file %s: %s\n " , metadataFile , err )
62
- }
63
-
64
- // Fill default values and replace variables
65
- for index , tool := range tools .Tools {
66
- log .Tracef ("Getting status for requested tool %s" , tool .Name )
67
- tools .Tools [index ].ReplaceVariables (prefix + "/" + target , arch , alt_arch )
68
-
69
- err := tools .Tools [index ].GetBinaryStatus ()
70
- if err != nil {
71
- return fmt .Errorf ("Unable to determine binary status of %s: %s" , tool .Name , err )
72
- }
73
-
74
- err = tools .Tools [index ].GetMarkerFileStatus (cacheDirectory )
75
- if err != nil {
76
- return fmt .Errorf ("Unable to determine marker file status of %s: %s" , tool .Name , err )
77
- }
78
-
79
- err = tools .Tools [index ].GetVersionStatus ()
80
- if err != nil {
81
- return fmt .Errorf ("Unable to determine version status of %s: %s" , tool .Name , err )
82
- }
83
- }
58
+ assertMetadataIsLoaded ()
84
59
85
60
if defaultMode {
86
61
installMode = "default"
@@ -92,6 +67,8 @@ var installCmd = &cobra.Command{
92
67
installMode = "only-installed"
93
68
}
94
69
70
+ log .Debugf ("Using install mode %s" , installMode )
71
+
95
72
// Collect requested tools based on mode
96
73
if len (args ) > 0 && installMode == "default" {
97
74
installMode = "list"
@@ -106,8 +83,23 @@ var installCmd = &cobra.Command{
106
83
requestedTools = tools .GetByTags ([]string {"category/default" })
107
84
108
85
} else if installMode == "only-installed" {
109
- for _ , tool := range tools .Tools {
110
- if toolStatus [tool .Name ].BinaryPresent {
86
+ log .Debugf ("Collecting installed tools" )
87
+ for index , tool := range tools .Tools {
88
+ log .Tracef ("Getting status for requested tool %s" , tool .Name )
89
+ tools .Tools [index ].ReplaceVariables (prefix + "/" + target , arch , alt_arch )
90
+
91
+ err := tools .Tools [index ].GetBinaryStatus ()
92
+ if err != nil {
93
+ return fmt .Errorf ("Unable to determine binary status of %s: %s" , tool .Name , err )
94
+ }
95
+
96
+ err = tools .Tools [index ].GetMarkerFileStatus (cacheDirectory )
97
+ if err != nil {
98
+ return fmt .Errorf ("Unable to determine marker file status of %s: %s" , tool .Name , err )
99
+ }
100
+
101
+ if tools .Tools [index ].Status .MarkerFilePresent && tools .Tools [index ].Status .BinaryPresent {
102
+ log .Tracef ("Adding %s to requested tools" , tool .Name )
111
103
requestedTools .Tools = append (requestedTools .Tools , tool )
112
104
}
113
105
}
@@ -124,13 +116,39 @@ var installCmd = &cobra.Command{
124
116
}
125
117
log .Debugf ("Planned %d tool(s)" , len (plannedTools .Tools ))
126
118
119
+ // Populate status of planned tools
120
+ // TODO: Display spinner
121
+ for index , tool := range plannedTools .Tools {
122
+ log .Tracef ("Getting status for requested tool %s" , tool .Name )
123
+ plannedTools .Tools [index ].ReplaceVariables (prefix + "/" + target , arch , alt_arch )
124
+
125
+ err := plannedTools .Tools [index ].GetBinaryStatus ()
126
+ if err != nil {
127
+ return fmt .Errorf ("Unable to determine binary status of %s: %s" , tool .Name , err )
128
+ }
129
+
130
+ err = plannedTools .Tools [index ].GetMarkerFileStatus (cacheDirectory )
131
+ if err != nil {
132
+ return fmt .Errorf ("Unable to determine marker file status of %s: %s" , tool .Name , err )
133
+ }
134
+
135
+ if plannedTools .Tools [index ].Status .BinaryPresent && plannedTools .Tools [index ].Status .MarkerFilePresent {
136
+ // TODO: Run version check in parallel
137
+ err := plannedTools .Tools [index ].GetVersionStatus ()
138
+ if err != nil {
139
+ return fmt .Errorf ("Unable to determine version status of %s: %s" , tool .Name , err )
140
+ }
141
+ }
142
+ }
143
+
127
144
// Terminate if checking or planning
128
145
if plan || check {
129
- plannedTools .ListWithStatus (toolStatus )
146
+ // TODO: Improve output
147
+ plannedTools .ListWithStatus ()
130
148
}
131
149
if check {
132
150
for _ , tool := range plannedTools .Tools {
133
- if ! toolStatus [ tool .Name ] .BinaryPresent || ! toolStatus [ tool .Name ] .VersionMatches {
151
+ if ! tool .Status .BinaryPresent || ! tool .Status .VersionMatches {
134
152
return fmt .Errorf ("Found missing or outdated tool" )
135
153
}
136
154
}
0 commit comments