workEnv 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/WorkEnvs.rb ADDED
@@ -0,0 +1,75 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require 'cli_class_tool'
4
+
5
+ WORK_ENV_LIB_DIR = __FILE__.chomp(File.extname(__FILE__))
6
+
7
+ require_relative 'WorkEnvs/Common'
8
+ require_relative 'WorkEnvs/Core'
9
+ require_relative 'WorkEnvs/accessors'
10
+
11
+ ENV_LIST=Dir.entries(WORK_ENV_LIB_DIR + "/Envs/").sort().map(){|entry|
12
+ next if (!File.file?(WORK_ENV_LIB_DIR + "/Envs/" + entry) || entry !~ /\.rb$/ );
13
+ entry.sub(/.rb$/, "")
14
+ }.compact()
15
+
16
+ # Load base WorkEnv first
17
+ require_relative "WorkEnvs/Envs/Basic"
18
+
19
+ # Add forward declaration for all classes
20
+ ENV_LIST.each(){|e|
21
+ next if e == "Basic"
22
+ c = Class.new(WorkEnvs::BasicEnv)
23
+ WorkEnvs.const_set(e + "Env", c)
24
+ }
25
+
26
+ # Now truly load them
27
+ ENV_LIST.each(){|e|
28
+ next if e == "Basic"
29
+
30
+ require_relative "WorkEnvs/Envs/#{e}"
31
+ # Make sure the class in the rb file has the proper name
32
+ #
33
+ # To handle parents we were force to generate pre declaration of classes based on the file names
34
+ # So now we want to make sure each file declares the class linked to his name
35
+ expectedEnvClass = WorkEnvs.const_get(e + "Env")
36
+ envType = WorkEnvs::getEnvType(expectedEnvClass)
37
+ if envType == :dev || envType == nil then
38
+ raise("File #{e} did not set an ENV_TYPE for class #{e}Env.\n"+
39
+ "Make sure the class insided has the name #{e}Env or rename the file appropriately.")
40
+ end
41
+ }
42
+
43
+ if File.exist?(WorkEnvs::WORK_ENV_GLOBAL_DIR + "/extras/CustomEnvs.rb") then
44
+ $LOAD_PATH.push(WorkEnvs::WORK_ENV_GLOBAL_DIR + "/extras")
45
+ require 'CustomEnvs'
46
+ $LOAD_PATH.pop()
47
+ end
48
+
49
+ module WorkEnvs
50
+ WORK_ENV_DEFAULT_TYPE = "dev"
51
+ end
52
+
53
+ #Now all non objet functions
54
+ require_relative 'WorkEnvs/global'
55
+
56
+ module WorkEnvs
57
+ class WorkEnvsError < StandardError; end
58
+ end
59
+
60
+ require_relative 'WorkEnvs/Action'
61
+
62
+ module WorkEnvs
63
+ ACTION_CLASS = [ WorkEnvAction ]
64
+ extend CLIClassTool::Utils
65
+
66
+ def self.actionToString(sym)
67
+ return sym.to_s().gsub('_', '-')
68
+ end
69
+
70
+ def self.stringToAction(str)
71
+ action = str.gsub('-', '_').to_sym()
72
+ raise("Invalid action '#{str}'") if self.getActionAttr("ACTION_LIST").index(action) == nil
73
+ return action
74
+ end
75
+ end
@@ -0,0 +1,284 @@
1
+ export _WENV_CMD_AWK=$(([ -f /bin/awk ] && echo "/bin/awk") || echo "/usr/bin/awk")
2
+ export _WENV_CMD_SORT=$(([ -f /bin/sort ] && echo "/bin/sort") || echo "/usr/bin/sort")
3
+ export _WENV_CMD_EGREP=$(([ -f /bin/grep ] && echo "/bin/grep -E") || echo "/usr/bin/grep -E")
4
+ export _WENV_CMD_SED=$(([ -f /bin/sed ] && echo "/bin/sed") || echo "/usr/bin/sed")
5
+ _wenv_genoptlist(){
6
+ local COMMAND=$*
7
+ WENV_SKIP_UPDATES=1 ${COMMAND} --help 2>&1 | \
8
+ ${_WENV_CMD_AWK} 'BEGIN { found = 0 } { if(found == 1) print $$0; if($$1 == "Options:") {found = 1}}' | \
9
+ ${_WENV_CMD_EGREP} -e "^[[:space:]]*--" -e "^[[:space:]]*-[a-zA-Z0-9]" | \
10
+ ${_WENV_CMD_SED} -e 's/^[[:space:]]*//' -e 's/^-[^-], //' | \
11
+ ${_WENV_CMD_AWK} '{ print $1}' | \
12
+ ${_WENV_CMD_SED} -e 's/^\(.*\)\[no-\]\(.*$\)/\1\2\n\1no-\2/' | \
13
+ ${_WENV_CMD_SORT} -u
14
+ }
15
+
16
+ _wenv_compfile(){
17
+ compgen -f -- "$*"
18
+ }
19
+ _complete_wenv_config(){
20
+ local LAST=$1
21
+ local cur=$2
22
+ shift 2
23
+ case $LAST in
24
+ --package-db);;
25
+ --package-repo);;
26
+ --package-db-proto)
27
+ compgen -W "http https" -- "$cur";;
28
+ --package-repo-proto)
29
+ compgen -W "http https file" -- "$cur";;
30
+ -T|--table);;
31
+ -m|--machine);;
32
+ --config-file)
33
+ _wenv_compfile $cur;;
34
+ *)
35
+ echo $*
36
+ esac
37
+ }
38
+ _complete_wenv_env(){
39
+ COMPREPLY=( $( compgen -W "$(wenv list -n)" -- "$*"));
40
+ }
41
+ _complete_createEnv(){
42
+ local cur
43
+ local last
44
+ local OPT_LIST=$(_wenv_genoptlist wenv create)
45
+ local TYPE_LIST=$(wenv query --list-envs)
46
+ _get_comp_words_by_ref cur
47
+
48
+ last=$((--COMP_CWORD))
49
+ case "${COMP_WORDS[last]}" in
50
+ --name|-n);;
51
+ --type|-t)
52
+ COMPREPLY=( $( compgen -W "$TYPE_LIST" -- "$cur") );;
53
+ *)
54
+ COMPREPLY=( $(_complete_wenv_config "${COMP_WORDS[last]}" "$cur" $(compgen -W "$OPT_LIST" -- "$cur")) );;
55
+ esac
56
+
57
+ }
58
+ _complete_cleanEnv(){
59
+ local cur
60
+ local last
61
+ local OPT_LIST=$(_wenv_genoptlist wenv clean)
62
+ _get_comp_words_by_ref cur
63
+
64
+ last=$((--COMP_CWORD))
65
+ case "${COMP_WORDS[last]}" in
66
+ --name|-n)
67
+ _complete_wenv_env $cur;;
68
+ *)
69
+ COMPREPLY=( $(_complete_wenv_config "${COMP_WORDS[last]}" "$cur" $(compgen -W "$OPT_LIST" -- "$cur")) );;
70
+ esac
71
+
72
+ }
73
+ _complete_configEnv(){
74
+ local cur
75
+ local last
76
+ local OPT_LIST=$(_wenv_genoptlist wenv config)
77
+ _get_comp_words_by_ref cur
78
+
79
+ last=$((--COMP_CWORD))
80
+ case "${COMP_WORDS[last]}" in
81
+ --name|-n)
82
+ _complete_wenv_env $cur;;
83
+ *)
84
+ COMPREPLY=( $(_complete_wenv_config "${COMP_WORDS[last]}" "$cur" $(compgen -W "$OPT_LIST" -- "$cur")) );;
85
+ esac
86
+
87
+ }
88
+
89
+
90
+ _complete_helpEnv(){
91
+ local cur
92
+ local last
93
+ local OPT_LIST=$(_wenv_genoptlist wenv help)
94
+ local CMD_LIST=$(wenv list_actions)
95
+ _get_comp_words_by_ref cur
96
+ last=$((COMP_CWORD - 1))
97
+ case "${COMP_WORDS[last]}" in
98
+ -*)
99
+ COMPREPLY=( $( compgen -W "$OPT_LIST" -- "$cur") );;
100
+ *)
101
+ COMPREPLY=( $( compgen -W "$CMD_LIST" -- "$cur") );;
102
+ esac;
103
+ }
104
+
105
+ _complete_listEnv(){
106
+ local cur
107
+ local last
108
+ local OPT_LIST=$(_wenv_genoptlist wenv list)
109
+ _get_comp_words_by_ref cur
110
+
111
+ last=$((--COMP_CWORD))
112
+ case "${COMP_WORDS[last]}" in
113
+ *)
114
+ COMPREPLY=( $(_complete_wenv_config "${COMP_WORDS[last]}" "$cur" $(compgen -W "$OPT_LIST" -- "$cur")) );;
115
+ esac
116
+
117
+ }
118
+
119
+ _complete_queryEnv(){
120
+ local cur
121
+ local last
122
+ local OPT_LIST=$(_wenv_genoptlist wenv query)
123
+ local TYPE_LIST=$(wenv query --list-envs)
124
+ _get_comp_words_by_ref cur
125
+
126
+ last=$((--COMP_CWORD))
127
+ case "${COMP_WORDS[last]}" in
128
+ --version|-v);;
129
+ --sha1|-s);;
130
+ --machine|-m);;
131
+ --branch|-B);;
132
+ --sub-sha1);;
133
+ --type|-t)
134
+ COMPREPLY=( $( compgen -W "$TYPE_LIST" -- "$cur") );;
135
+ --copy-env|-c)
136
+ COMPREPLY=( $( compgen -f -- "$cur"));;
137
+ --download|-d)
138
+ COMPREPLY=( $( compgen -d -- "$cur"));;
139
+ --hudson|-H|-D|--dump-infos|--copy-env)
140
+ COMPREPLY=( $( compgen -f -- "$cur"));;
141
+ --hudson-all)
142
+ COMPREPLY=( $( compgen -d -- "$cur"));;
143
+ *)
144
+ COMPREPLY=( $( compgen -W "$OPT_LIST" -- "$cur") );;
145
+ esac
146
+
147
+ }
148
+ _complete_rmEnv(){
149
+ local cur
150
+ local last
151
+ local OPT_LIST=$(_wenv_genoptlist wenv rm)
152
+ _get_comp_words_by_ref cur
153
+
154
+ last=$((--COMP_CWORD))
155
+ case "${COMP_WORDS[last]}" in
156
+ --name|-n)
157
+ _complete_wenv_env $cur;;
158
+ *)
159
+ COMPREPLY=( $( compgen -W "$OPT_LIST" -- "$cur") );;
160
+ esac
161
+
162
+ }
163
+ _complete_renameEnv(){
164
+ local cur
165
+ local last
166
+ local OPT_LIST=$(_wenv_genoptlist wenv rename)
167
+ _get_comp_words_by_ref cur
168
+
169
+ last=$((--COMP_CWORD))
170
+ case "${COMP_WORDS[last]}" in
171
+ --name|-n|--new-name|-N)
172
+ _complete_wenv_env $cur;;
173
+ *)
174
+ COMPREPLY=( $( compgen -W "$OPT_LIST" -- "$cur") );;
175
+ esac
176
+
177
+ }
178
+ _complete_updateEnv(){
179
+ local cur
180
+ local last
181
+ local OPT_LIST=$(_wenv_genoptlist wenv update)
182
+ _get_comp_words_by_ref cur
183
+
184
+ last=$((--COMP_CWORD))
185
+ case "${COMP_WORDS[last]}" in
186
+ --version|-v);;
187
+ --sha1|-s);;
188
+ --date|-d);;
189
+ --branch|-B);;
190
+ --options|-o);;
191
+ --sub-sha1);;
192
+ --name|-n)
193
+ _complete_wenv_env $cur;;
194
+ --copy-env|-c)
195
+ COMPREPLY=( $( compgen -f -- "$cur"));;
196
+ --hudson|-H|-D|--dump-infos|--copy-env)
197
+ COMPREPLY=( $( compgen -f -- "$cur"));;
198
+ --hudson-all)
199
+ COMPREPLY=( $( compgen -d -- "$cur"));;
200
+ *)
201
+ COMPREPLY=( $( compgen -W "$OPT_LIST" -- "$cur") );;
202
+ esac
203
+
204
+ }
205
+ _complete_switchEnv(){
206
+ local cur
207
+ local last
208
+ _get_comp_words_by_ref cur
209
+
210
+ last=$((--COMP_CWORD))
211
+ case "${COMP_WORDS[last]}" in
212
+ --name|-n)
213
+ _complete_wenv_env $cur;;
214
+ *)
215
+ case "$cur" in
216
+ -*)
217
+ COMPREPLY=( $( compgen -W "--name" -- "$cur"));;
218
+ *)
219
+ _complete_wenv_env $cur;;
220
+ esac;;
221
+ esac
222
+ }
223
+
224
+ _complete_testEnv(){
225
+ local cur
226
+ local last
227
+ local OPT_LIST=$(_wenv_genoptlist wenv test)
228
+ local TYPE_LIST=$(wenv query --list-envs)
229
+ _get_comp_words_by_ref cur
230
+
231
+ last=$((--COMP_CWORD))
232
+ case "${COMP_WORDS[last]}" in
233
+ --name|-n)
234
+ _complete_wenv_env $cur;;
235
+ --type|-t)
236
+ COMPREPLY=( $( compgen -W "$TYPE_LIST" -- "$cur") );;
237
+ *)
238
+ COMPREPLY=( $(_complete_wenv_config "${COMP_WORDS[last]}" "$cur" $(compgen -W "$OPT_LIST" -- "$cur")) );;
239
+ esac
240
+
241
+ }
242
+
243
+ _complete_package_lookupEnv(){
244
+ local cur
245
+ local last
246
+ local OPT_LIST=$(_wenv_genoptlist wenv package-lookup)
247
+ local TYPE_LIST=$(wenv query --list-envs)
248
+ _get_comp_words_by_ref cur
249
+
250
+ last=$((--COMP_CWORD))
251
+ case "${COMP_WORDS[last]}" in
252
+ --package|-p)
253
+ ;;
254
+ --type|-t)
255
+ COMPREPLY=( $( compgen -W "$TYPE_LIST" -- "$cur") );;
256
+ *)
257
+ COMPREPLY=( $(_complete_wenv_config "${COMP_WORDS[last]}" "$cur" $(compgen -W "$OPT_LIST" -- "$cur")) );;
258
+ esac
259
+
260
+ }
261
+
262
+ _complete_wEnv(){
263
+ local cur
264
+ local last
265
+ local OPT_LIST=$(_wenv_genoptlist wenv)
266
+ local CMD_LIST=$(wenv list_actions)
267
+ _get_comp_words_by_ref cur
268
+ last=$((COMP_CWORD - 1))
269
+ if [ $last -eq 0 ]; then
270
+ case "${COMP_WORDS[1]}" in
271
+ -*)
272
+
273
+ COMPREPLY=( $( compgen -W "$OPT_LIST" -- "$cur") );;
274
+ *)
275
+ COMPREPLY=( $( compgen -W "$CMD_LIST" -- "$cur") );;
276
+ esac;
277
+ else
278
+ local cmd_name=$( compgen -W "$CMD_LIST" -- "${COMP_WORDS[1]}" | sed -e 's/-/_/g')
279
+ completion_func="_complete_${cmd_name}Env"
280
+ declare -f $completion_func > /dev/null && $completion_func
281
+ fi
282
+ }
283
+
284
+ complete -F _complete_wEnv -o nospace wenv
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: workEnv
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nicolas Morey
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 2026-09-09 00:00:00.000000000 Z
11
+ dependencies: []
12
+ description: This set of scripts allows to work easily on a single workstation using
13
+ multiple versions of Work Tools. These scripts will configure your environment for
14
+ you (PATH, Licenses, etc.), but also allow to fetch and install coherent set of
15
+ tools.
16
+ email: nicolas@morey.ovh
17
+ executables:
18
+ - wenv
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - LICENSE
23
+ - bin/wenv
24
+ - lib/WorkEnvs.rb
25
+ - lib/WorkEnvs/Action.rb
26
+ - lib/WorkEnvs/Common.rb
27
+ - lib/WorkEnvs/Common/Arch.rb
28
+ - lib/WorkEnvs/Common/Config.rb
29
+ - lib/WorkEnvs/Common/Confirm.rb
30
+ - lib/WorkEnvs/Common/DBInterface.rb
31
+ - lib/WorkEnvs/Common/Defines.rb
32
+ - lib/WorkEnvs/Common/Dependencies.rb
33
+ - lib/WorkEnvs/Common/EnvOpts.rb
34
+ - lib/WorkEnvs/Common/Package.rb
35
+ - lib/WorkEnvs/Common/PackageDownloader.rb
36
+ - lib/WorkEnvs/Common/VersionSelector.rb
37
+ - lib/WorkEnvs/Core.rb
38
+ - lib/WorkEnvs/Envs/Any.rb
39
+ - lib/WorkEnvs/Envs/Basic.rb
40
+ - lib/WorkEnvs/accessors.rb
41
+ - lib/WorkEnvs/global.rb
42
+ - workrc-completion.sh
43
+ homepage: https://github.com/nmorey/workEnv
44
+ licenses:
45
+ - GPL-3.0-or-later
46
+ metadata: {}
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '2.7'
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubygems_version: 4.0.16
62
+ specification_version: 4
63
+ summary: A CLI tool and framework to create, switch, and manage isolated, modular
64
+ development environments.
65
+ test_files: []