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