@@ -93,72 +93,66 @@ func ChooseVersion(binDir string, program search.Program) (string, error) {
93
93
return version , err
94
94
}
95
95
96
- // switchTt switches 'tt' program .
97
- func switchTt (switchCtx SwitchCtx ) error {
98
- log . Infof ( "Switching to %s %s." , switchCtx .Program , switchCtx . Version )
96
+ // switchHeaders makes symlink for required version of headers .
97
+ func switchHeaders (switchCtx * SwitchCtx , versionStr string ) error {
98
+ includeDir := filepath . Join ( switchCtx .IncDir , "include" )
99
99
100
- ttVersion := switchCtx .Version
101
- if ! strings .HasPrefix (switchCtx .Version , "v" ) {
102
- ttVersion = "v" + ttVersion
100
+ if ! util .IsDir (filepath .Join (includeDir , versionStr )) {
101
+ return fmt .Errorf ("headers %s is not installed in current environment" , versionStr )
103
102
}
104
- versionStr := search .ProgramTt .String () + version .FsSeparator + ttVersion
105
103
106
- if util .IsRegularFile (filepath .Join (switchCtx .BinDir , versionStr )) {
107
- err := util .CreateSymlink (versionStr , filepath .Join (switchCtx .BinDir , "tt" ), true )
108
- if err != nil {
109
- return fmt .Errorf ("failed to switch version: %s" , err )
110
- }
111
- log .Infof ("Done" )
112
- } else {
113
- return fmt .Errorf ("%s %s is not installed in current environment" ,
114
- switchCtx .Program , switchCtx .Version )
104
+ err := util .CreateSymlink (versionStr ,
105
+ filepath .Join (includeDir , switchCtx .Program .Exec ()),
106
+ true )
107
+ if err != nil {
108
+ return fmt .Errorf ("failed create symlink: %s" , err )
115
109
}
116
110
return nil
117
111
}
118
112
119
- // switchTarantool switches 'tarantool' program.
120
- func switchTarantool (switchCtx SwitchCtx , enterprise bool ) error {
121
- log .Infof ("Switching to %s %s." , switchCtx .Program , switchCtx .Version )
122
- var versionStr string
123
- if enterprise {
124
- versionStr = search .ProgramEe .String () + version .FsSeparator + switchCtx .Version
125
- } else {
126
- versionStr = search .ProgramCe .String () + version .FsSeparator + switchCtx .Version
113
+ // switchBinary makes symlink for required binary version.
114
+ func switchBinary (switchCtx * SwitchCtx , versionStr string ) error {
115
+ newBinary := filepath .Join (switchCtx .BinDir , versionStr )
116
+ if ! util .IsRegularFile (newBinary ) {
117
+ return fmt .Errorf ("binary %s is not installed in current environment" , newBinary )
127
118
}
128
- if util .IsRegularFile (filepath .Join (switchCtx .BinDir , versionStr )) &&
129
- util .IsDir (filepath .Join (switchCtx .IncDir , "include" , versionStr )) {
130
- err := util .CreateSymlink (versionStr , filepath .Join (switchCtx .BinDir ,
131
- "tarantool" ), true )
132
- if err != nil {
133
- return fmt .Errorf ("failed to switch version: %s" , err )
134
- }
135
- err = util .CreateSymlink (versionStr , filepath .Join (switchCtx .IncDir ,
136
- "include" , "tarantool" ), true )
137
- if err != nil {
138
- return fmt .Errorf ("failed to switch version: %s" , err )
139
- }
140
- log .Infof ("Done" )
141
- } else {
142
- return fmt .Errorf ("%s %s is not installed in current environment" ,
143
- switchCtx .Program , switchCtx .Version )
119
+
120
+ err := util .CreateSymlink (versionStr ,
121
+ filepath .Join (switchCtx .BinDir , switchCtx .Program .Exec ()),
122
+ true )
123
+ if err != nil {
124
+ return fmt .Errorf ("failed create symlink: %s" , err )
144
125
}
145
126
return nil
146
127
}
147
128
148
129
// Switch switches binaries.
149
- func Switch (switchCtx SwitchCtx ) error {
150
- var err error
151
-
130
+ func Switch (switchCtx * SwitchCtx ) error {
152
131
switch switchCtx .Program {
153
132
case search .ProgramTt :
154
- err = switchTt (switchCtx )
155
- case search .ProgramCe :
156
- err = switchTarantool (switchCtx , false )
157
- case search .ProgramEe :
158
- err = switchTarantool (switchCtx , true )
159
- default :
133
+ if ! strings .HasPrefix (switchCtx .Version , "v" ) {
134
+ switchCtx .Version = "v" + switchCtx .Version
135
+ }
136
+
137
+ case search .ProgramUnknown :
160
138
return fmt .Errorf ("unknown application: %s" , switchCtx .Program )
161
139
}
162
140
163
- return err
141
+ versionStr := switchCtx .Program .String () + version .FsSeparator + switchCtx .Version
142
+ log .Infof ("Switching to %s" , versionStr )
143
+
144
+ err := switchBinary (switchCtx , versionStr )
145
+ if err != nil {
146
+ return fmt .Errorf ("failed to switch binary: %s" , err )
147
+ }
148
+
149
+ if switchCtx .Program .IsTarantool () {
150
+ err = switchHeaders (switchCtx , versionStr )
151
+ if err != nil {
152
+ return fmt .Errorf ("failed to switch headers: %s" , err )
153
+ }
154
+ }
155
+
156
+ log .Infof ("Done" )
157
+ return nil
164
158
}
0 commit comments