@@ -40,65 +40,91 @@ func initInstallCommand() *cobra.Command {
40
40
Run : runInstallCommand ,
41
41
}
42
42
installCommand .Flags ().BoolVar (& installFlags .noDeps , "no-deps" , false , "Do not install dependencies." )
43
+ installCommand .Flags ().BoolVar (& installFlags .gitURL , "git-url" , false , "Enter git url for libraries hosted on repositories" )
44
+ installCommand .Flags ().BoolVar (& installFlags .zipPath , "zip-path" , false , "Enter a path to zip file" )
43
45
return installCommand
44
46
}
45
47
46
48
var installFlags struct {
47
- noDeps bool
49
+ noDeps bool
50
+ gitURL bool
51
+ zipPath bool
48
52
}
49
53
50
54
func runInstallCommand (cmd * cobra.Command , args []string ) {
51
55
instance := instance .CreateInstanceIgnorePlatformIndexErrors ()
52
- libRefs , err := ParseLibraryReferenceArgsAndAdjustCase (instance , args )
53
- if err != nil {
54
- feedback .Errorf ("Arguments error: %v" , err )
55
- os .Exit (errorcodes .ErrBadArgument )
56
- }
57
-
58
- toInstall := map [string ]* rpc.LibraryDependencyStatus {}
59
- if installFlags .noDeps {
60
- for _ , libRef := range libRefs {
61
- toInstall [libRef .Name ] = & rpc.LibraryDependencyStatus {
62
- Name : libRef .Name ,
63
- VersionRequired : libRef .Version ,
64
- }
56
+ if installFlags .zipPath {
57
+ ziplibraryInstallReq := & rpc.ZipLibraryInstallReq {
58
+ Instance : instance ,
59
+ Path : args [0 ],
60
+ }
61
+ err := lib .ZipLibraryInstall (context .Background (), ziplibraryInstallReq , output .TaskProgress ())
62
+ if err != nil {
63
+ feedback .Errorf ("Error installing Zip Library: %v" , err )
64
+ os .Exit (errorcodes .ErrGeneric )
65
+ }
66
+ } else if installFlags .gitURL {
67
+ gitlibraryInstallReq := & rpc.GitLibraryInstallReq {
68
+ Instance : instance ,
69
+ Url : args [0 ],
70
+ }
71
+ err := lib .GitLibraryInstall (context .Background (), gitlibraryInstallReq , output .TaskProgress ())
72
+ if err != nil {
73
+ feedback .Errorf ("Error installing Git Library: %v" , err )
74
+ os .Exit (errorcodes .ErrGeneric )
65
75
}
66
76
} else {
67
- for _ , libRef := range libRefs {
68
- depsResp , err := lib .LibraryResolveDependencies (context .Background (), & rpc.LibraryResolveDependenciesReq {
69
- Instance : instance ,
70
- Name : libRef .Name ,
71
- Version : libRef .Version ,
72
- })
73
- if err != nil {
74
- feedback .Errorf ("Error resolving dependencies for %s: %s" , libRef , err )
75
- os .Exit (errorcodes .ErrGeneric )
77
+ libRefs , err := ParseLibraryReferenceArgsAndAdjustCase (instance , args )
78
+ if err != nil {
79
+ feedback .Errorf ("Arguments error: %v" , err )
80
+ os .Exit (errorcodes .ErrBadArgument )
81
+ }
82
+
83
+ toInstall := map [string ]* rpc.LibraryDependencyStatus {}
84
+ if installFlags .noDeps {
85
+ for _ , libRef := range libRefs {
86
+ toInstall [libRef .Name ] = & rpc.LibraryDependencyStatus {
87
+ Name : libRef .Name ,
88
+ VersionRequired : libRef .Version ,
89
+ }
76
90
}
77
- for _ , dep := range depsResp .GetDependencies () {
78
- feedback .Printf ("%s depends on %s@%s" , libRef , dep .GetName (), dep .GetVersionRequired ())
79
- if existingDep , has := toInstall [dep .GetName ()]; has {
80
- if existingDep .GetVersionRequired () != dep .GetVersionRequired () {
81
- // TODO: make a better error
82
- feedback .Errorf ("The library %s is required in two different versions: %s and %s" ,
83
- dep .GetName (), dep .GetVersionRequired (), existingDep .GetVersionRequired ())
84
- os .Exit (errorcodes .ErrGeneric )
91
+ } else {
92
+ for _ , libRef := range libRefs {
93
+ depsResp , err := lib .LibraryResolveDependencies (context .Background (), & rpc.LibraryResolveDependenciesReq {
94
+ Instance : instance ,
95
+ Name : libRef .Name ,
96
+ Version : libRef .Version ,
97
+ })
98
+ if err != nil {
99
+ feedback .Errorf ("Error resolving dependencies for %s: %s" , libRef , err )
100
+ os .Exit (errorcodes .ErrGeneric )
101
+ }
102
+ for _ , dep := range depsResp .GetDependencies () {
103
+ feedback .Printf ("%s depends on %s@%s" , libRef , dep .GetName (), dep .GetVersionRequired ())
104
+ if existingDep , has := toInstall [dep .GetName ()]; has {
105
+ if existingDep .GetVersionRequired () != dep .GetVersionRequired () {
106
+ // TODO: make a better error
107
+ feedback .Errorf ("The library %s is required in two different versions: %s and %s" ,
108
+ dep .GetName (), dep .GetVersionRequired (), existingDep .GetVersionRequired ())
109
+ os .Exit (errorcodes .ErrGeneric )
110
+ }
85
111
}
112
+ toInstall [dep .GetName ()] = dep
86
113
}
87
- toInstall [dep .GetName ()] = dep
88
114
}
89
115
}
90
- }
91
116
92
- for _ , library := range toInstall {
93
- libraryInstallReq := & rpc.LibraryInstallReq {
94
- Instance : instance ,
95
- Name : library .Name ,
96
- Version : library .VersionRequired ,
97
- }
98
- err := lib .LibraryInstall (context .Background (), libraryInstallReq , output .ProgressBar (), output .TaskProgress ())
99
- if err != nil {
100
- feedback .Errorf ("Error installing %s: %v" , library , err )
101
- os .Exit (errorcodes .ErrGeneric )
117
+ for _ , library := range toInstall {
118
+ libraryInstallReq := & rpc.LibraryInstallReq {
119
+ Instance : instance ,
120
+ Name : library .Name ,
121
+ Version : library .VersionRequired ,
122
+ }
123
+ err := lib .LibraryInstall (context .Background (), libraryInstallReq , output .ProgressBar (), output .TaskProgress ())
124
+ if err != nil {
125
+ feedback .Errorf ("Error installing %s: %v" , library , err )
126
+ os .Exit (errorcodes .ErrGeneric )
127
+ }
102
128
}
103
129
}
104
130
}
0 commit comments