Salome HOME
Improve the application command
[tools/sat.git] / complete_sat.sh
1 #!/bin/bash
2 #  Copyright (C) 2010-2012  CEA/DEN
3 #
4 #  This library is free software; you can redistribute it and/or
5 #  modify it under the terms of the GNU Lesser General Public
6 #  License as published by the Free Software Foundation; either
7 #  version 2.1 of the License.
8 #
9 #  This library is distributed in the hope that it will be useful,
10 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 #  Lesser General Public License for more details.
13 #
14 #  You should have received a copy of the GNU Lesser General Public
15 #  License along with this library; if not, write to the Free Software
16 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17
18 # Completion Function for salomeTools (sat)
19
20 export SAT_PATH=$(cd `dirname "${BASH_SOURCE}"` && pwd)
21
22 _show_applications()
23 {
24     local opts2=$(for x in `$SAT_PATH/sat config -nl`
25         do
26             echo ${x}
27         done)
28
29     # additional options for command working without applications
30     case "${command}" in
31         config)
32             opts2=$(echo --list --value --edit --info $opts2)
33             ;;
34         log)
35             opts2=$(echo --clean --full --last --terminal $opts2)
36             ;;
37         jobs)
38             opts2=$(echo --name --only_jobs --list --completion --test_connection --input_boards --publish $opts2)
39             ;;
40         shell)
41             opts2=$(echo --command --sat $opts2)
42             ;;
43         job)
44             opts2=$(echo --jobs_config --name $opts2)
45             ;;
46         test)
47             opts2=$(echo --base --display --grid --launcher --session $opts2)
48             ;;
49         package)
50             opts2=$(echo --name --project --salometools $opts2)
51             ;;
52         find_duplicates)
53             opts2=$(echo --path --exclude-file --exclude-extension --exclude-path $opts2)
54             ;;
55     esac
56
57     COMPREPLY=( $(compgen -W "${opts2}" -- ${cur}) )
58 }
59
60 _show_products()
61 {
62     if [[ $appli != $prev ]]
63     then
64         opts=$(for x in `$SAT_PATH/sat -s config $appli -nv APPLICATION.products`
65             do echo ${x}; done)
66
67         COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
68    fi
69 }
70
71 _salomeTools_complete()
72 {
73     if [[ "${SAT_PATH}x" == "x" ]]
74     then
75         return 0
76     fi
77
78     local cur opts args command
79     COMPREPLY=()
80     argc="${COMP_CWORD}"
81     cur="${COMP_WORDS[COMP_CWORD]}"
82     
83     # second argument => show available APPLICATION
84     if [[ ${argc} > 1 ]]
85     then
86         command="${COMP_WORDS[1]}"
87     fi
88
89     if [[ ${argc} > 1 ]]
90     then
91         if [[ ${command%%-*} == "" ]]
92         then
93             command="${COMP_WORDS[2]}"
94             argc="$((( argc - 1)))"
95         fi
96     fi
97
98     # first argument => show available commands
99     if [[ ${argc} == 1 ]]
100     then
101         opts="config log testcommand source patch prepare environ clean configure make makeinstall compile launcher run jobs job shell test package generate find_duplicates --help"
102         COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
103         return 0
104     fi
105
106     if [[ ${argc} == 2 ]]
107     then
108         # get list of APPLICATIONS
109         _show_applications
110         return 0
111     fi
112     
113     # option depending on command
114     local prev="${COMP_WORDS[COMP_CWORD-1]}"
115     
116     if [[ ${prev} == "--value" || ${prev} == "-v" ]]
117     then
118         if [[ ${argc} == 4 ]]
119         then
120             # with application
121             opts=$(for x in `$SAT_PATH/sat config ${COMP_WORDS[COMP_CWORD-2]} -s ${COMP_WORDS[COMP_CWORD]}`
122                 do echo ${x} ; done)
123             COMPREPLY=( $(compgen -W "${opts}" -S "." -- ${cur}) )
124         else
125             # without application
126             opts=$(for x in `$SAT_PATH/sat config -s ${COMP_WORDS[COMP_CWORD]}`
127                 do echo ${x} ; done)
128             COMPREPLY=( $(compgen -W "${opts}" -S "." -- ${cur}) )
129         fi
130         
131         return 0
132     fi
133       
134     # show list of products
135     if [[ ${prev} == "--product" || ${prev} == "-p" ]]
136     then
137         appli="${COMP_WORDS[2]}"
138         if [[ ${command} != "source" ]]
139         then
140             opts=$(for x in `$SAT_PATH/sat config $appli -nv APPLICATION.products`
141                 do echo ${x}; done)
142
143                COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
144             return 0
145         fi
146     fi
147
148     # show argument for each command
149     case "${command}" in
150         config)
151             opts="--value --list --copy --edit --no_label --info"
152             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
153             return 0        
154             ;;
155         log)
156             opts="--clean --last --terminal --last"
157             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
158             return 0
159             ;;
160         clean)
161             opts="--products --sources --build --install --all --sources_without_dev"
162             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
163             return 0
164             ;;
165         source)
166             opts="--products"
167             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
168             return 0
169             ;;
170         patch)
171             opts="--products"
172             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
173             return 0
174             ;;
175         prepare)
176             opts="--products --force --force_patch"
177             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
178             return 0
179             ;;
180         environ)
181             opts="--products --shell --prefix --target"
182             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
183             return 0
184             ;;
185         configure)
186             opts="--products --option"
187             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
188             return 0
189             ;;
190         make)
191             opts="--products --option"
192             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
193             return 0
194             ;;
195         makeinstall)
196             opts="--products"
197             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
198             return 0
199             ;;
200         compile)
201             opts="--products --with_fathers --with_children --clean_all --make_flags --show --stop_first_fail"
202             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
203             return 0
204             ;;
205         launcher)
206             opts="--name --catalog --gencat"
207             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
208             return 0
209             ;;
210         jobs)
211             opts="--name --only_jobs --list --completion --test_connection --input_boards --publish"
212             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
213             return 0
214             ;;
215         shell)
216             opts="--command"
217             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
218             return 0
219             ;;
220         job)
221             opts="--jobs_config --name"
222             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
223             return 0
224             ;;
225         test)
226             opts="--base --launcher --grid --session --display"
227             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
228             return 0
229             ;;
230         package)
231             opts="--name --binaries --sources --project --salometools --with_vcs"
232             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
233             return 0
234             ;;
235         generate)
236             opts="--products --yacsgen"
237             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
238             return 0
239             ;;
240         find_duplicates)
241             opts="--path --sources --exclude-file --exclude-extension --exclude-path"
242             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
243             return 0
244             ;;
245         *) return 0 ;;
246     esac
247     
248 }
249
250 # activation of auto-completion for the sat command
251 complete -F _salomeTools_complete sat
252 complete -F _salomeTools_complete ./sat
253