Salome HOME
sat test : replace module by grid and type by session
[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     esac
50
51     COMPREPLY=( $(compgen -W "${opts2}" -- ${cur}) )
52 }
53
54 _show_products()
55 {
56     if [[ $appli != $prev ]]
57     then
58         opts=$(for x in `$SAT_PATH/sat -s config $appli -nv APPLICATION.products`
59             do echo ${x}; done)
60
61         COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
62    fi
63 }
64
65 _salomeTools_complete()
66 {
67     if [[ "${SAT_PATH}x" == "x" ]]
68     then
69         return 0
70     fi
71
72     local cur opts args command
73     COMPREPLY=()
74     argc="${COMP_CWORD}"
75     cur="${COMP_WORDS[COMP_CWORD]}"
76     
77     # second argument => show available APPLICATION
78     if [[ ${argc} > 1 ]]
79     then
80         command="${COMP_WORDS[1]}"
81     fi
82
83     if [[ ${argc} > 1 ]]
84     then
85         if [[ ${command%%-*} == "" ]]
86         then
87             command="${COMP_WORDS[2]}"
88             argc="$((( argc - 1)))"
89         fi
90     fi
91
92     # first argument => show available commands
93     if [[ ${argc} == 1 ]]
94     then
95         opts="config log testcommand source patch prepare environ clean configure make makeinstall compile launcher run jobs job shell test --help"
96         COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
97         return 0
98     fi
99
100     if [[ ${argc} == 2 ]]
101     then
102         # get list of APPLICATIONS
103         _show_applications
104         return 0
105     fi
106     
107     # option depending on command
108     local prev="${COMP_WORDS[COMP_CWORD-1]}"
109     
110     if [[ ${prev} == "--value" || ${prev} == "-v" ]]
111     then
112         if [[ ${argc} == 4 ]]
113         then
114             # with application
115             opts=$(for x in `$SAT_PATH/sat config ${COMP_WORDS[COMP_CWORD-2]} -s ${COMP_WORDS[COMP_CWORD]}`
116                 do echo ${x} ; done)
117             COMPREPLY=( $(compgen -W "${opts}" -S "." -- ${cur}) )
118         else
119             # without application
120             opts=$(for x in `$SAT_PATH/sat config -s ${COMP_WORDS[COMP_CWORD]}`
121                 do echo ${x} ; done)
122             COMPREPLY=( $(compgen -W "${opts}" -S "." -- ${cur}) )
123         fi
124         
125         return 0
126     fi
127       
128     # show list of products
129     if [[ ${prev} == "--product" || ${prev} == "-p" ]]
130     then
131         appli="${COMP_WORDS[2]}"
132         if [[ ${command} != "source" ]]
133         then
134             opts=$(for x in `$SAT_PATH/sat config $appli -nv APPLICATION.products`
135                 do echo ${x}; done)
136
137                COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
138             return 0
139         fi
140     fi
141
142     # show argument for each command
143     case "${command}" in
144         config)
145             opts="--value --list --copy --edit --no_label --info"
146             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
147             return 0        
148             ;;
149         log)
150             opts="--clean --last --terminal --last"
151             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
152             return 0
153             ;;
154         clean)
155             opts="--products --sources --build --install --all --sources_without_dev"
156             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
157             return 0
158             ;;
159         source)
160             opts="--products"
161             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
162             return 0
163             ;;
164         patch)
165             opts="--products"
166             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
167             return 0
168             ;;
169         prepare)
170             opts="--products --force --force_patch"
171             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
172             return 0
173             ;;
174         environ)
175             opts="--products --shell --prefix --target"
176             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
177             return 0
178             ;;
179         configure)
180             opts="--products --option"
181             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
182             return 0
183             ;;
184         make)
185             opts="--products --option"
186             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
187             return 0
188             ;;
189         makeinstall)
190             opts="--products"
191             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
192             return 0
193             ;;
194         compile)
195             opts="--products --with_fathers --with_children --clean_all --make_flags --show --stop_first_fail"
196             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
197             return 0
198             ;;
199         launcher)
200             opts="--name --catalog --gencat"
201             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
202             return 0
203             ;;
204         jobs)
205             opts="--name --only_jobs --list --completion --test_connection --input_boards --publish"
206             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
207             return 0
208             ;;
209         shell)
210             opts="--command"
211             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
212             return 0
213             ;;
214         job)
215             opts="--jobs_config --name"
216             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
217             return 0
218             ;;
219         test)
220             opts="--base --launcher --grid --session --display"
221             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
222             return 0
223             ;;
224         *) return 0 ;;
225     esac
226     
227 }
228
229 # activation of auto-completion for the sat command
230 complete -F _salomeTools_complete sat
231 complete -F _salomeTools_complete ./sat
232