Next: , Previous: Saving open windows, Up: Executing external tools


16.6.4.3 Querying project switches

Some GPS shell commands can be used to query the default switches set by the user in the project file. These are get_tool_switches_as_string, get_tool_switches_as_list, or, more generally, get_attribute_as_string and get_attribute_as_list. The first two require a unique parameter which is the name of the tool as specified in the <tool> tag. This name is case-sensitive. The last two commands are more general and can be used to query the status of any attribute from the project. See their description by typing the following in the GPS shell console window:

     help Project.get_attribute_as_string
     help Project.get_attribute_as_list

The following is a short example on how to query the switches for the tool "Find" from the project, See Tool example. It first creates an object representing the current project, then passes this object as the first argument of the get_tool_switches_as_string command. The last external command is a simple output of these switches

     <?xml version="1.0" ?>
     <find_switches>
       <action name="Get switches for Find">
         <shell>Project %p</shell>
         <shell>Project.get_tool_switches_as_string %1 Find </shell>
         <external>echo %1</external>
       </action>
     </find_switches>

The following example shows how something similar can be done from Python, in a simpler manner. For a change, this function queries the Ada compiler switches for the current project, and prints them out in the messages window. The

     <?xml version="1.0" ?>
     <query_switches>
       <action name="Query compiler switches">
         <shell lang="python">GPS.Project("%p").get_attribute_as_list
           (package="compiler",
            attribute="default_switches",
            index="ada")</shell>
         <external>echo compiler switches= %1</external>
       </action>
     </query_switches>