add warning if as only one parameter is not specified repo file. (bnc #380322)
authorJosef Reidinger <jreidinger@suse.cz>
Fri, 18 Apr 2008 10:29:39 +0000 (10:29 +0000)
committerJosef Reidinger <jreidinger@suse.cz>
Fri, 18 Apr 2008 10:29:39 +0000 (10:29 +0000)
doc/zypper.8
src/zypper-utils.h
src/zypper.cc

index 04a00eb..020d2bc 100644 (file)
@@ -366,7 +366,9 @@ repositories, ZENworks 7 Linux Management, ZENworks 6.6.x Linux
 Management servers, as well as local files.
 
 .TP
-.B addrepo (ar) [options] <URI> [<alias>]
+.B addrepo (ar) [options] <URI> <alias> 
+.B addrepo (ar) [options] <FILE.repo>
+
 Add a new repository specified by URI and assign specified alias to it or specify URI to repo file.
 
 Newly added repositories have auto-refresh disabled by default (except for repositories
index 76986e4..ef5f986 100644 (file)
@@ -76,10 +76,20 @@ zypp::Capability safe_parse_cap (Zypper & zypper,
 
 
 //comparator for RepoInfo set
-class RepoInfoAliasComparator{
-  public: bool operator()(const zypp::RepoInfo &a, const zypp::RepoInfo& b){
+class RepoInfoAliasComparator
+{
+  public: bool operator()(const zypp::RepoInfo &a, const zypp::RepoInfo& b)
+  {
     return a.alias()<b.alias();
   }
 };
 
+/**
+ * checks name for .repo string
+ */
+inline bool isRepoFile(const std::string& name)
+{
+  return name.find(".repo") != name.npos ;
+}
+
 #endif /*ZYPPER_UTILS_H*/
index e5fb560..fbdf695 100644 (file)
@@ -1829,6 +1829,15 @@ void Zypper::doCommand()
         setExitCode(ZYPPER_EXIT_ERR_INVALID_ARGS);
         return;
       case 1:
+        if( !isRepoFile(_arguments[0] ))
+        {
+          out().error(
+            _("If only one argument is used, it must be a URI pointing to a .repo file."));
+          ERR << "Not repo file." << endl;
+          out().info(_command_help);
+          setExitCode(ZYPPER_EXIT_ERR_INVALID_ARGS);
+          return;
+        }
         add_repo_from_file(*this,_arguments[0], enabled);
        break;
       case 2: