@@ -46,12 +46,18 @@ func fillSubCommandsInfo(cmd *cobra.Command, modulesInfo *ModulesInfo) {
46
46
// GetModulesInfo collects information about available modules (both external and internal).
47
47
func GetModulesInfo (cmdCtx * cmdcontext.CmdCtx , rootCmd * cobra.Command ,
48
48
cliOpts * config.CliOpts ) (ModulesInfo , error ) {
49
- modulesDir , err := getExternalModulesDir (cmdCtx , cliOpts )
49
+ modulesDirs , err := getConfigModulesDirs (cmdCtx , cliOpts )
50
50
if err != nil {
51
51
return nil , err
52
52
}
53
53
54
- externalModules , err := getExternalModules (modulesDir )
54
+ modulesEnvDirs , err := getEnvironmentModulesDirs ()
55
+ if err != nil {
56
+ return nil , err
57
+ }
58
+ modulesDirs = append (modulesDirs , modulesEnvDirs ... )
59
+
60
+ externalModules , err := getExternalModules (modulesDirs )
55
61
if err != nil {
56
62
return nil , fmt .Errorf (
57
63
"failed to get available external modules information: %s" , err )
@@ -72,45 +78,69 @@ func GetModulesInfo(cmdCtx *cmdcontext.CmdCtx, rootCmd *cobra.Command,
72
78
return modulesInfo , nil
73
79
}
74
80
75
- // getExternalModulesDir returns the directory where external modules are located.
76
- func getExternalModulesDir (cmdCtx * cmdcontext.CmdCtx , cliOpts * config.CliOpts ) (string , error ) {
81
+ // collectDirectoriesList checks list to ensure that all items is directories.
82
+ func collectDirectoriesList (paths []string ) ([]string , error ) {
83
+ dirs := make ([]string , 0 , len (paths ))
84
+ // We return an error only if the following conditions are met:
85
+ // 1. If a directory field is specified;
86
+ // 2. Specified path exists;
87
+ // 3. Path points to not a directory.
88
+ for _ , dir := range paths {
89
+ if info , err := os .Stat (dir ); err == nil {
90
+ // TODO: Add warning in next patches, discussion
91
+ // what if the file exists, but access is denied, etc.
92
+ // FIXME: resolve this question while prepare list:
93
+ // https://github.com/tarantool/tt/issues/1014
94
+ if ! info .IsDir () {
95
+ return dirs , fmt .Errorf ("specified path in configuration file is not a directory" )
96
+ }
97
+ dirs = append (dirs , dir )
98
+ }
99
+ }
100
+
101
+ return dirs , nil
102
+ }
103
+
104
+ // getConfigModulesDirs returns from configuration the list of directories,
105
+ // where external modules are located.
106
+ func getConfigModulesDirs (cmdCtx * cmdcontext.CmdCtx , cliOpts * config.CliOpts ) ([]string , error ) {
77
107
// Configuration file not detected - ignore and work on.
78
108
// TODO: Add warning in next patches, discussion
79
109
// what if the file exists, but access is denied, etc.
80
110
if _ , err := os .Stat (cmdCtx .Cli .ConfigPath ); err != nil {
81
111
if ! os .IsNotExist (err ) {
82
- return "" , fmt .Errorf ("failed to get access to configuration file: %s" , err )
112
+ return [] string {} , fmt .Errorf ("failed to get access to configuration file: %s" , err )
83
113
}
84
114
85
- return "" , nil
115
+ return [] string {} , nil
86
116
}
87
117
88
118
// Unspecified `modules` field is not considered an error.
89
119
if cliOpts .Modules == nil {
90
- return "" , nil
120
+ return [] string {} , nil
91
121
}
92
122
93
- // We return an error only if the following conditions are met:
94
- // 1. If a directory field is specified;
95
- // 2. Specified path exists;
96
- // 3. Path points to not a directory.
97
- // FIXME: Add working with a list https://github.com/tarantool/tt/issues/1014
98
- modulesDir := cliOpts .Modules .Directories [0 ]
99
- if info , err := os .Stat (modulesDir ); err == nil {
100
- // TODO: Add warning in next patches, discussion
101
- // what if the file exists, but access is denied, etc.
102
- if ! info .IsDir () {
103
- return "" , fmt .Errorf ("specified path in configuration file is not a directory" )
104
- }
105
- }
123
+ return collectDirectoriesList (cliOpts .Modules .Directories )
124
+ }
106
125
107
- return modulesDir , nil
126
+ func getEnvironmentModulesDirs () ([]string , error ) {
127
+ env_var := os .Getenv ("TT_CLI_MODULES_PATH" )
128
+ if env_var == "" {
129
+ return []string {}, nil
130
+ }
131
+ paths := strings .Split (env_var , ":" )
132
+ return collectDirectoriesList (paths )
108
133
}
109
134
110
135
// getExternalModules returns map of available modules by
111
136
// parsing the contents of the path folder.
112
- func getExternalModules (path string ) (map [string ]string , error ) {
137
+ func getExternalModules (paths [] string ) (map [string ]string , error ) {
113
138
modules := make (map [string ]string )
139
+ if len (paths ) == 0 {
140
+ return modules , nil
141
+ }
142
+ // FIXME: Work with list at https://github.com/tarantool/tt/issues/1014
143
+ path := paths [0 ]
114
144
115
145
// If the directory doesn't exist, it is not an error.
116
146
// TODO: Add warning in next patches, discussion
0 commit comments