rospack_cmdline.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2008, Willow Garage, Inc.
00003  * 
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions are met:
00006  *   * Redistributions of source code must retain the above copyright notice,
00007  *     this list of conditions and the following disclaimer.
00008  *   * Redistributions in binary form must reproduce the above copyright
00009  *     notice, this list of conditions and the following disclaimer in the
00010  *     documentation and/or other materials provided with the distribution.
00011  *   * Neither the names of Stanford University or Willow Garage, Inc. nor the names of its
00012  *     contributors may be used to endorse or promote products derived from
00013  *     this software without specific prior written permission.
00014  *
00015  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00016  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00017  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00018  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00019  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00020  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00021  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00022  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00023  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00024  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00025  * POSSIBILITY OF SUCH DAMAGE.
00026  */
00027 
00028 #include "rospack/rospack.h"
00029 #include "utils.h"
00030 
00031 #include <boost/program_options.hpp>
00032 #include <boost/algorithm/string.hpp>
00033 #include <algorithm>
00034 #include <iostream>
00035 #include <stdlib.h>
00036 #include <stdio.h>
00037 
00038 namespace po = boost::program_options;
00039 
00040 namespace rospack
00041 {
00042 
00043 bool parse_args(int argc, char** argv, 
00044                 rospack::Rosstackage& rp,
00045                 po::variables_map& vm);
00046 
00047 bool
00048 rospack_run(int argc, char** argv, rospack::Rosstackage& rp, std::string& output)
00049 {
00050   po::variables_map vm;
00051 
00052   if(!parse_args(argc, argv, rp, vm))
00053     return false;
00054 
00055   bool quiet = (vm.count("quiet")==1);
00056   rp.setQuiet(quiet);
00057 
00058   std::string command;
00059   std::string package;
00060   bool package_given = false;
00061   bool deps_only = false;
00062   std::string lang;
00063   std::string attrib;
00064   std::string top;
00065   std::string target;
00066   bool zombie_only = false;
00067   std::string length_str;
00068   int length;
00069   if(vm.count("command"))
00070     command = vm["command"].as<std::string>();
00071   if(!command.size())
00072   {
00073     rp.logError( "no command given.  Try 'rospack help'");
00074     return true;
00075   }
00076   // For some commands, we force a crawl.  Definitely anything that does a
00077   // depends-on calculation.
00078   bool force = false;
00079   if((command == "profile") ||
00080      (command == "depends-on") ||
00081      (command == "depends-on1") ||
00082      (command == "langs") ||
00083      (command == "list-duplicates"))
00084     force = true;
00085 
00086   if(vm.count("package"))
00087   {
00088     package = vm["package"].as<std::string>();
00089     package_given = true;
00090   }
00091   else
00092   {
00093     // try to determine package from directory context
00094     rp.inStackage(package);
00095   }
00096   if(vm.count("deps-only"))
00097     deps_only = true;
00098   if(vm.count("lang"))
00099     lang = vm["lang"].as<std::string>();
00100   if(vm.count("attrib"))
00101     attrib = vm["attrib"].as<std::string>();
00102   if(vm.count("top"))
00103     top = vm["top"].as<std::string>();
00104   if(vm.count("target"))
00105     target = vm["target"].as<std::string>();
00106   if(vm.count("zombie-only"))
00107     zombie_only = true;
00108   if(vm.count("length"))
00109   {
00110     length_str = vm["length"].as<std::string>();
00111     length = atoi(length_str.c_str());
00112   }
00113   else
00114   {
00115     if(zombie_only)
00116       length = -1;
00117     else
00118       length = 20;
00119   }
00120 
00121   // COMMAND: help
00122   if(command == "help" || vm.count("help"))
00123   {
00124     if(package_given || (command != "help" && vm.count("help"))) {
00125       if (command == "help") {
00126         command = vm["package"].as<std::string>();
00127       }
00128       output.append("Usage: rospack ");
00129       output.append(command);
00130       if(command == "help")
00131         output.append("[command]\n\nPrint help message.");
00132       else if(command == "find")
00133         output.append("\n\nPrint absolute path to the package");
00134       else if(command == "list")
00135         output.append("\n\nPrint newline-separated list <package-name> <package-dir> for all packages.");
00136       else if(command == "list-names")
00137         output.append("\n\nPrint newline-separated list of packages names for all packages.");
00138       else if(command == "list-duplicates")
00139         output.append("\n\nPrint newline-separated list of names of packages that are found more than once during the search.");
00140       else if(command == "langs")
00141         output.append("\n\nPrint space-separated list of available language-specific client libraries.");
00142       else if(command == "depends" || command == "deps")
00143         output.append("[package]\n\nPrint newline-separated, ordered list of all dependencies of the package.");
00144       else if(command == "depends1" || command == "deps1")
00145         output.append("[package]\n\nPrint newline-separated, ordered list of immediate dependencies of the package.");
00146       else if(command == "depends-manifest" || command == "deps-manifest")
00147         output.append("[package]\n\nPrint space-separated, ordered list of manifest.xml files for all dependencies of the package. Used internally by rosbuild.");
00148       else if(command == "depends-indent" || command == "deps-indent")
00149         output.append("[package]\n\nPrint newline-separated, indented list of the entire dependency chain for the package.");
00150       else if(command == "depends-why" || command == "deps-why")
00151         output.append("--target=TARGET [package]\n\nPrint newline-separated presentation of all dependency chains from the package to TARGET. ");
00152       else if(command == "depends-msgsrv" || command == "deps-msgsrv")
00153         output.append("[package]\n\nPrint space-separated list of message-generation marker files for all dependencies of the package.  Used internally by rosbuild.");
00154       else if(command == "rosdep" || command == "rosdeps")
00155         output.append("[package]\n\nPrint newline-separated list of all [rosdep] tags from the manifest.xml of the package and all of its dependencies.");
00156       else if(command == "rosdep0" || command == "rosdeps0")
00157         output.append("[package]\n\nPrint newline-separated list of all [rosdep] tags from the manifest.xml of just the package itself.");
00158       else if(command == "vcs")
00159         output.append("[package]\n\nPrint newline-separated list of all [versioncontrol] tags from the manifest.xml of the package and all of its dependencies.");
00160       else if(command == "vcs0")
00161         output.append("[package]\n\nPrint newline-separated list of all [versioncontrol] tags from the manifest.xml of just the package itself.");
00162       else if(command == "depends-on")
00163         output.append("[package]\n\nPrint newline-separated list of all packages that depend on the package. ");
00164       else if(command == "depends-on1")
00165         output.append("[package]\n\nPrint newline-separated list of all packages that directly depend on the package.");
00166       else if(command == "export")
00167         output.append("[--deps-only] --lang=<lang> --attrib=<attrib> [package]\n\nPrint Space-separated list of [export][LANGUAGE ATTRIBUTE=\"\"/][/export] values from the manifest.xml of the package and its dependencies.\n\nIf --deps-only is provided, then the package itself is excluded.");
00168       else if(command == "plugins")
00169         output.append("--attrib=<attrib> [--top=<toppkg>] [package]\n\nExamine packages that depend directly on the given package, giving name and the exported attribute with the name <attrib>\n\nIf --top=<toppkg> is given, then in addition to depending directly on the given package, to be scanned for exports, a package must also be a dependency of <toppkg>, or be <toppkg> itself.");
00170       else if(command == "cflags-only-I")
00171         output.append("[--deps-only] [package]\n\nPrint Space-separated list of [export][LANGUAGE ATTRIBUTE=\"\"/][/export] values from the manifest.xml of the package and its dependencies.\n\nIf --deps-only is provided, then the package itself is excluded.");
00172       else if(command == "cflags-only-other")
00173         output.append("[--deps-only] [package]\n\nPrint space-separated list of export/cpp/cflags that don't start with -I.\n\nIf --deps-only is provided, then the package itself is excluded.");
00174       else if(command == "libs-only-L")
00175         output.append("[--deps-only] [package]\n\nPrint space-separated list of export/cpp/libs that start with -L.\n\nIf --deps-only is provided, then the package itself is excluded.");
00176       else if(command == "libs-only-l")
00177         output.append("[--deps-only] [package]\n\nPrint space-separated list of export/cpp/libs that start with -l.\n\nIf --deps-only is provided, then the package itself is excluded.");
00178       else if(command == "libs-only-other")
00179         output.append("[--deps-only] [package]\n\nPrint space-separated list of export/cpp/libs that don't start with -l or -L.\n\nIf --deps-only is provided, then the package itself is excluded.");
00180       else if(command == "profile")
00181         output.append("[--length=<length>] [--zombie-only]\n\nForce a full crawl of package directories and report the directories that took the longest time to crawl.\n\n--length=N how many directories to display\n\n--zombie-only Only print directories that do not have any manifests.");
00182       output.append("\n");
00183     } else {
00184         output.append(rp.usage());
00185     }
00186     return true;
00187   }
00188 
00189   std::vector<std::string> search_path;
00190   if(!rp.getSearchPathFromEnv(search_path))
00191     return false;
00192 
00193   // COMMAND: profile
00194   if(command == "profile")
00195   {
00196     if(package_given || target.size() || top.size() || 
00197        deps_only || lang.size() || attrib.size())
00198     {
00199       rp.logError( "invalid option(s) given");
00200       return false;
00201     }
00202     std::vector<std::string> dirs;
00203     if(rp.profile(search_path, zombie_only, length, dirs))
00204       return false;
00205     for(std::vector<std::string>::const_iterator it = dirs.begin();
00206         it != dirs.end();
00207         ++it)
00208       output.append((*it) + "\n");
00209     return true;
00210   }
00211 
00212   // We crawl here because profile (above) does its own special crawl.
00213   rp.crawl(search_path, force);
00214   
00215   // COMMAND: find [package]
00216   if(command == "find")
00217   {
00218     if(!package.size())
00219     {
00220       rp.logError( "no package/stack given");
00221       return false;
00222     }
00223     if(target.size() || top.size() || length_str.size() || 
00224        zombie_only || deps_only || lang.size() || attrib.size())
00225     {
00226       rp.logError( "invalid option(s) given");
00227       return false;
00228     }
00229     std::string path;
00230     if(!rp.find(package, path))
00231       return false;
00232     output.append(path + "\n");
00233     return true;
00234   }
00235   // COMMAND: list
00236   else if(command == "list")
00237   {
00238     if(package_given || target.size() || top.size() || length_str.size() || 
00239        zombie_only || deps_only || lang.size() || attrib.size())
00240     {
00241       rp.logError( "invalid option(s) given");
00242       return false;
00243     }
00244     std::set<std::pair<std::string, std::string> > list;
00245     rp.list(list);
00246     for(std::set<std::pair<std::string, std::string> >::const_iterator it = list.begin();
00247         it != list.end();
00248         ++it)
00249     {
00250       output.append(it->first + " " + it->second + "\n");
00251     }
00252     return true;
00253   }
00254   // COMMAND: list-names
00255   else if(command == "list-names")
00256   {
00257     if(package_given || target.size() || top.size() || length_str.size() || 
00258        zombie_only || deps_only || lang.size() || attrib.size())
00259     {
00260       rp.logError( "invalid option(s) given");
00261       return false;
00262     }
00263     std::set<std::pair<std::string, std::string> > list;
00264     rp.list(list);
00265     for(std::set<std::pair<std::string, std::string> >::const_iterator it = list.begin();
00266         it != list.end();
00267         ++it)
00268     {
00269       output.append(it->first + "\n");
00270     }
00271     return true;
00272   }
00273   // COMMAND: list-duplicates
00274   else if(command == "list-duplicates")
00275   {
00276     if(package_given || target.size() || top.size() || length_str.size() || 
00277        zombie_only || deps_only || lang.size() || attrib.size())
00278     {
00279       rp.logError( "invalid option(s) given");
00280       return false;
00281     }
00282     std::vector<std::string> dups;
00283     rp.listDuplicates(dups);
00284     // if there are dups, list-duplicates prints them and returns non-zero
00285     for(std::vector<std::string>::const_iterator it = dups.begin();
00286         it != dups.end();
00287         ++it)
00288     {
00289       output.append(*it + "\n");
00290     }
00291     return true;
00292   }
00293   // COMMAND: langs
00294   else if(rp.getName() == ROSPACK_NAME && command == "langs")
00295   {
00296     if(package_given || target.size() || top.size() || length_str.size() || 
00297        zombie_only || deps_only || lang.size() || attrib.size())
00298     {
00299       rp.logError( "invalid option(s) given");
00300       return false;
00301     }
00302     std::vector<std::string> deps;
00303     if(!rp.depsOn("roslang", true, deps))
00304       return false;
00305     const char* ros_lang_disable;
00306     if((ros_lang_disable = getenv("ROS_LANG_DISABLE")))
00307     {
00308       std::vector<std::string> disable_langs;
00309     // I can't see that boost filesystem has an elegant cross platform
00310     // representation for this anywhere like qt/python have.
00311     #if defined(WIN32)
00312       const char *path_delim = ";";
00313     #else //!defined(WIN32)
00314       const char *path_delim = ":";
00315     #endif
00316       boost::split(disable_langs, ros_lang_disable,
00317                    boost::is_any_of(path_delim),
00318                    boost::token_compress_on);
00319       std::vector<std::string>::iterator it = deps.begin();
00320       while(it != deps.end())
00321       {
00322         if(std::find(disable_langs.begin(), disable_langs.end(), *it) != 
00323            disable_langs.end())
00324           it = deps.erase(it);
00325         else
00326           ++it;
00327       }
00328     }
00329     for(std::vector<std::string>::const_iterator it = deps.begin();
00330         it != deps.end();
00331         ++it)
00332     {
00333       if(it != deps.begin())
00334         output.append(" ");
00335       output.append(*it);
00336     }
00337     output.append("\n");
00338     return true;
00339   }
00340   // COMMAND: depends [package] (alias: deps)
00341   else if(command == "depends" || command == "deps" || 
00342           command == "depends1" || command == "deps1")
00343   {
00344     if(!package.size())
00345     {
00346       rp.logError( "no package/stack given");
00347       return false;
00348     }
00349     if(target.size() || top.size() || length_str.size() || 
00350        zombie_only || deps_only || lang.size() || attrib.size())
00351     {
00352       rp.logError( "invalid option(s) given");
00353       return false;
00354     }
00355     std::vector<std::string> deps;
00356     if(!rp.deps(package, (command == "depends1" || command == "deps1"), deps))
00357       return false;
00358     for(std::vector<std::string>::const_iterator it = deps.begin();
00359         it != deps.end();
00360         ++it)
00361       output.append(*it + "\n");
00362     return true;
00363   }
00364   // COMMAND: depends-manifests [package] (alias: deps-manifests)
00365   else if(command == "depends-manifests" || command == "deps-manifests")
00366   {
00367     if(!package.size())
00368     {
00369       rp.logError( "no package/stack given");
00370       return false;
00371     }
00372     if(target.size() || top.size() || length_str.size() || 
00373        zombie_only || deps_only || lang.size() || attrib.size())
00374     {
00375       rp.logError( "invalid option(s) given");
00376       return false;
00377     }
00378     std::vector<std::string> manifests;
00379     if(!rp.depsManifests(package, false, manifests))
00380       return false;
00381     for(std::vector<std::string>::const_iterator it = manifests.begin();
00382         it != manifests.end();
00383         ++it)
00384     {
00385       if(it != manifests.begin())
00386         output.append(" ");
00387       output.append(*it);
00388     }
00389     output.append("\n");
00390     return true;
00391   }
00392   // COMMAND: depends-msgsrv [package] (alias: deps-msgsrv)
00393   else if(rp.getName() == ROSPACK_NAME && 
00394           (command == "depends-msgsrv" || command == "deps-msgsrv"))
00395   {
00396     if(!package.size())
00397     {
00398       rp.logError( "no package given");
00399       return false;
00400     }
00401     if(target.size() || top.size() || length_str.size() || 
00402        zombie_only || deps_only || lang.size() || attrib.size())
00403     {
00404       rp.logError( "invalid option(s) given");
00405       return false;
00406     }
00407     std::vector<std::string> gens;
00408     if(!rp.depsMsgSrv(package, false, gens))
00409       return false;
00410     for(std::vector<std::string>::const_iterator it = gens.begin();
00411         it != gens.end();
00412         ++it)
00413     {
00414       if(it != gens.begin())
00415         output.append(" ");
00416       output.append(*it);
00417     }
00418     output.append("\n");
00419     return true;
00420   }
00421   // COMMAND: depends-indent [package] (alias: deps-indent)
00422   else if(command == "depends-indent" || command == "deps-indent")
00423   {
00424     if(!package.size())
00425     {
00426       rp.logError( "no package/stack given");
00427       return false;
00428     }
00429     if(target.size() || top.size() || length_str.size() || 
00430        zombie_only || deps_only || lang.size() || attrib.size())
00431     {
00432       rp.logError( "invalid option(s) given");
00433       return false;
00434     }
00435     std::vector<std::string> deps;
00436     if(!rp.depsIndent(package, false, deps))
00437       return false;
00438     for(std::vector<std::string>::const_iterator it = deps.begin();
00439         it != deps.end();
00440         ++it)
00441       output.append(*it + "\n");
00442     return true;
00443   }
00444   // COMMAND: depends-why [package] (alias: deps-why)
00445   else if(command == "depends-why" || command == "deps-why")
00446   {
00447     if(!package.size() || !target.size())
00448     {
00449       rp.logError( "no package/stack or target given");
00450       return false;
00451     }
00452     if(top.size() || length_str.size() || 
00453        zombie_only || deps_only || lang.size() || attrib.size())
00454     {
00455       rp.logError( "invalid option(s) given");
00456       return false;
00457     }
00458     std::string why_output;
00459     if(!rp.depsWhy(package, target, why_output))
00460       return false;
00461     output.append(why_output);
00462     return true;
00463   }
00464   // COMMAND: rosdep [package] (alias: rosdeps)
00465   // COMMAND: rosdep0 [package] (alias: rosdeps0)
00466   else if(rp.getName() == ROSPACK_NAME && 
00467           (command == "rosdep" || command == "rosdeps" ||
00468            command == "rosdep0" || command == "rosdeps0"))
00469   {
00470     if(!package.size())
00471     {
00472       rp.logError( "no package given");
00473       return false;
00474     }
00475     if(target.size() || top.size() || length_str.size() || 
00476        zombie_only || deps_only || lang.size() || attrib.size())
00477     {
00478       rp.logError( "invalid option(s) given");
00479       return false;
00480     }
00481     std::set<std::string> rosdeps;
00482     if(!rp.rosdeps(package, (command == "rosdep0" || command == "rosdeps0"), rosdeps))
00483       return false;
00484     for(std::set<std::string>::const_iterator it = rosdeps.begin();
00485         it != rosdeps.end();
00486         ++it)
00487       output.append(*it + "\n");
00488     return true;
00489   }
00490   // COMMAND: vcs [package]
00491   // COMMAND: vcs0 [package]
00492   else if(rp.getName() == ROSPACK_NAME && 
00493           (command == "vcs" || command == "vcs0"))
00494   {
00495     if(!package.size())
00496     {
00497       rp.logError( "no package given");
00498       return false;
00499     }
00500     if(target.size() || top.size() || length_str.size() || 
00501        zombie_only || deps_only || lang.size() || attrib.size())
00502     {
00503       rp.logError( "invalid option(s) given");
00504       return false;
00505     }
00506     std::vector<std::string> vcs;
00507     if(!rp.vcs(package, (command == "vcs0"), vcs))
00508       return false;
00509     for(std::vector<std::string>::const_iterator it = vcs.begin();
00510         it != vcs.end();
00511         ++it)
00512       output.append(*it + "\n");
00513     return true;
00514   }
00515   // COMMAND: depends-on [package]
00516   // COMMAND: depends-on1 [package]
00517   else if(command == "depends-on" || command == "depends-on1")
00518   {
00519     if(!package.size())
00520     {
00521       rp.logError( "no package/stack given");
00522       return false;
00523     }
00524     if(target.size() || top.size() || length_str.size() || 
00525        zombie_only || deps_only || lang.size() || attrib.size())
00526     {
00527       rp.logError( "invalid option(s) given");
00528       return false;
00529     }
00530     std::vector<std::string> deps;
00531     if(!rp.depsOn(package, (command == "depends-on1"), deps))
00532       return false;
00533     for(std::vector<std::string>::const_iterator it = deps.begin();
00534         it != deps.end();
00535         ++it)
00536       output.append(*it + "\n");
00537     return true;
00538   }
00539   // COMMAND: export [--deps-only] --lang=<lang> --attrib=<attrib> [package]
00540   else if(rp.getName() == ROSPACK_NAME && command == "export")
00541   {
00542     if(!package.size() || !lang.size() || !attrib.size())
00543     {
00544       rp.logError( "no package / lang / attrib given");
00545       return false;
00546     }
00547     if(target.size() || top.size() || length_str.size() || zombie_only)
00548     {
00549       rp.logError( "invalid option(s) given");
00550       return false;
00551     }
00552     std::vector<std::string> flags;
00553     if(!rp.exports(package, lang, attrib, deps_only, flags))
00554       return false;
00555     for(std::vector<std::string>::const_iterator it = flags.begin();
00556         it != flags.end();
00557         ++it)
00558     {
00559       if(it != flags.begin())
00560         output.append(" ");
00561       output.append(*it);
00562     }
00563     output.append("\n");
00564     return true;
00565   }
00566   // COMMAND: plugins --attrib=<attrib> [--top=<toppkg>] [package]
00567   else if(rp.getName() == ROSPACK_NAME && command == "plugins")
00568   {
00569     if(!package.size() || !attrib.size())
00570     {
00571       rp.logError( "no package / attrib given");
00572       return false;
00573     }
00574     if(target.size() || length_str.size() || zombie_only)
00575     {
00576       rp.logError( "invalid option(s) given");
00577       return false;
00578     }
00579     std::vector<std::string> flags;
00580     if(!rp.plugins(package, attrib, top, flags))
00581       return false;
00582     for(std::vector<std::string>::const_iterator it = flags.begin();
00583         it != flags.end();
00584         ++it)
00585       output.append(*it + "\n");
00586     return true;
00587   }
00588   // COMMAND: cflags-only-I [--deps-only] [package]
00589   else if(rp.getName() == ROSPACK_NAME && command == "cflags-only-I")
00590   {
00591     if(!package.size())
00592     {
00593       rp.logError( "no package given");
00594       return false;
00595     }
00596     if(target.size() || top.size() || length_str.size() || zombie_only)
00597     {
00598       rp.logError( "invalid option(s) given");
00599       return false;
00600     }
00601     std::vector<std::string> flags;
00602     if(!rp.exports(package, "cpp", "cflags", deps_only, flags))
00603       return false;
00604     std::string combined;
00605     for(std::vector<std::string>::const_iterator it = flags.begin();
00606         it != flags.end();
00607         ++it)
00608     {
00609       if(it != flags.begin())
00610         combined.append(" ");
00611       combined.append(*it);
00612     }
00613     std::string result;
00614     parse_compiler_flags(combined, "-I", true, false, result);
00615     output.append(result + "\n");
00616     return true;
00617   }
00618   // COMMAND: cflags-only-other [--deps-only] [package]
00619   else if(rp.getName() == ROSPACK_NAME && command == "cflags-only-other")
00620   {
00621     if(!package.size())
00622     {
00623       rp.logError( "no package given");
00624       return false;
00625     }
00626     if(target.size() || top.size() || length_str.size() || zombie_only)
00627     {
00628       rp.logError( "invalid option(s) given");
00629       return false;
00630     }
00631     std::vector<std::string> flags;
00632     if(!rp.exports(package, "cpp", "cflags", deps_only, flags))
00633       return false;
00634     std::string combined;
00635     for(std::vector<std::string>::const_iterator it = flags.begin();
00636         it != flags.end();
00637         ++it)
00638     {
00639       if(it != flags.begin())
00640         combined.append(" ");
00641       combined.append(*it);
00642     }
00643     std::string result;
00644     parse_compiler_flags(combined, "-I", false, false, result);
00645     output.append(result + "\n");
00646     return true;
00647   }
00648   // COMMAND: libs-only-L [--deps-only] [package]
00649   else if(rp.getName() == ROSPACK_NAME && command == "libs-only-L")
00650   {
00651     if(!package.size())
00652     {
00653       rp.logError( "no package given");
00654       return false;
00655     }
00656     if(target.size() || top.size() || length_str.size() || zombie_only)
00657     {
00658       rp.logError( "invalid option(s) given");
00659       return false;
00660     }
00661     std::vector<std::string> flags;
00662     if(!rp.exports(package, "cpp", "lflags", deps_only, flags))
00663       return false;
00664     std::string combined;
00665     for(std::vector<std::string>::const_iterator it = flags.begin();
00666         it != flags.end();
00667         ++it)
00668     {
00669       if(it != flags.begin())
00670         combined.append(" ");
00671       combined.append(*it);
00672     }
00673     std::string result;
00674     parse_compiler_flags(combined, "-L", true, false, result);
00675     output.append(result + "\n");
00676     return true;
00677   }
00678   // COMMAND: libs-only-l [--deps-only] [package]
00679   else if(rp.getName() == ROSPACK_NAME && command == "libs-only-l")
00680   {
00681     if(!package.size())
00682     {
00683       rp.logError( "no package given");
00684       return false;
00685     }
00686     if(target.size() || top.size() || length_str.size() || zombie_only)
00687     {
00688       rp.logError( "invalid option(s) given");
00689       return false;
00690     }
00691     std::vector<std::string> flags;
00692     if(!rp.exports(package, "cpp", "lflags", deps_only, flags))
00693       return false;
00694     std::string combined;
00695     for(std::vector<std::string>::const_iterator it = flags.begin();
00696         it != flags.end();
00697         ++it)
00698     {
00699       if(it != flags.begin())
00700         combined.append(" ");
00701       combined.append(*it);
00702     }
00703     std::string result;
00704     parse_compiler_flags(combined, "-l", true, true, result);
00705     output.append(result + "\n");
00706     return true;
00707   }
00708   // COMMAND: libs-only-other [--deps-only] [package]
00709   else if(rp.getName() == ROSPACK_NAME && command == "libs-only-other")
00710   {
00711     if(!package.size())
00712     {
00713       rp.logError( "no package given");
00714       return false;
00715     }
00716     if(target.size() || top.size() || length_str.size() || zombie_only)
00717     {
00718       rp.logError( "invalid option(s) given");
00719       return false;
00720     }
00721     std::vector<std::string> flags;
00722     if(!rp.exports(package, "cpp", "lflags", deps_only, flags))
00723       return false;
00724     std::string combined;
00725     for(std::vector<std::string>::const_iterator it = flags.begin();
00726         it != flags.end();
00727         ++it)
00728     {
00729       if(it != flags.begin())
00730         combined.append(" ");
00731       combined.append(*it);
00732     }
00733     std::string intermediate;
00734     parse_compiler_flags(combined, "-L", false, false, intermediate);
00735     std::string result;
00736     parse_compiler_flags(intermediate, "-l", false, false, result);
00737     output.append(result + "\n");
00738     return true;
00739   }
00740   // COMMAND: contents [stack]
00741   else if(rp.getName() == ROSSTACK_NAME && command == "contents")
00742   {
00743     if(!package.size())
00744     {
00745       rp.logError( "no stack given");
00746       return false;
00747     }
00748     if(target.size() || top.size() || length_str.size() || 
00749        zombie_only || deps_only || lang.size() || attrib.size())
00750     {
00751       rp.logError( "invalid option(s) given");
00752       return false;
00753     }
00754 
00755     std::set<std::string> packages;
00756     rp.contents(package, packages);
00757     for(std::set<std::string>::const_iterator it = packages.begin();
00758         it != packages.end();
00759         ++it)
00760       output.append(*it + "\n");
00761     return true;
00762   }
00763   // COMMAND: contains [package]
00764   else if(rp.getName() == ROSSTACK_NAME && 
00765           ((command == "contains") || (command == "contains-path")))
00766   {
00767     if(!package.size())
00768     {
00769       rp.logError( "no package given");
00770       return false;
00771     }
00772     if(target.size() || top.size() || length_str.size() || 
00773        zombie_only || deps_only || lang.size() || attrib.size())
00774     {
00775       rp.logError( "invalid option(s) given");
00776       return false;
00777     }
00778     std::string name, path;
00779     if(!rp.contains(package, name, path))
00780       return false;
00781     if(command == "contains")
00782       output.append(name + "\n");
00783     else // command == "contains-path"
00784       output.append(path + "\n");
00785     return true;
00786   }
00787   else
00788   {
00789     rp.logError(std::string("command ") + command + " not implemented");
00790     return false;
00791   }
00792 }
00793 
00794 bool
00795 parse_args(int argc, char** argv, 
00796            rospack::Rosstackage& rp, po::variables_map& vm)
00797 {
00798   po::options_description desc("Allowed options");
00799   desc.add_options()
00800           ("command", po::value<std::string>(), "command")
00801           ("package", po::value<std::string>(), "package")
00802           ("target", po::value<std::string>(), "target")
00803           ("deps-only", "deps-only")
00804           ("lang", po::value<std::string>(), "lang")
00805           ("attrib", po::value<std::string>(), "attrib")
00806           ("top", po::value<std::string>(), "top")
00807           ("length", po::value<std::string>(), "length")
00808           ("zombie-only", "zombie-only")
00809           ("help", "help")
00810           ("quiet,q", "quiet");
00811 
00812   po::positional_options_description pd;
00813   pd.add("command", 1).add("package", 1);
00814   try
00815   {
00816     po::store(po::command_line_parser(argc, argv).options(desc).positional(pd).run(), vm);
00817   }
00818   catch(boost::program_options::error e)
00819   {
00820     rp.logError( std::string("failed to parse command-line options: ") + e.what());
00821     return false;
00822   }
00823   po::notify(vm);
00824 
00825   return true;
00826 }
00827 
00828 }


rospack
Author(s): Brian Gerkey/gerkey@willowgarage.com, Morgan Quigley/mquigley@cs.stanford.edu
autogenerated on Fri Jan 3 2014 11:51:40