diff --git a/src/Zypper.cc b/src/Zypper.cc index 8e53bf7ee5..a3acdb69e7 100644 --- a/src/Zypper.cc +++ b/src/Zypper.cc @@ -2307,6 +2307,7 @@ void Zypper::processCommandOptions() { static struct option service_modify_options[] = { {"help", no_argument, 0, 'h'}, + {"baseurl", required_argument, 0, 'u'}, ARG_REPO_PROP, /* LEGACY(ARG_REPO_PROP) prefers -f */ {"refresh", no_argument, 0, 'r'}, /* LEGACY(ARG_REPO_PROP) prefers -F */ {"no-refresh", no_argument, 0, 'R'}, @@ -2352,6 +2353,7 @@ void Zypper::processCommandOptions() _("Modify properties of repositories specified by alias, number, or URI, or by the '%1%' aggregate options.") ) % "--all, --remote, --local, --medium-type" ) .optionSectionCommandOptions() + .option( "-u, --baseurl ", _("Set a base URL for the repository.") ) .option_REPO_PROP .gap() .option( "-a, --all", _("Apply changes to all repositories.") ) @@ -4107,6 +4109,16 @@ void Zypper::doCommand() return; } + if ( aggregate && copts.count("baseurl") ) + { + // translators: aggregate option is e.g. "--all". This message will be + // followed by mr command help text which will explain it + out().error(_("It is not possible to use --baseurl with aggregate options.")); + out().info( _command_help ); + setExitCode( ZYPPER_EXIT_ERR_INVALID_ARGS ); + return; + } + // too many arguments if ( _arguments.size() && aggregate ) { diff --git a/src/repos.cc b/src/repos.cc index 9a79412c85..1d0ac3e1be 100644 --- a/src/repos.cc +++ b/src/repos.cc @@ -2148,8 +2148,24 @@ void modify_repo( Zypper & zypper, const std::string & alias ) repo.setName( name ); } + std::string baseurl; + if ( (tmp1 = zypper.cOpts().find("baseurl")) != zypper.cOpts().end() ) + { + baseurl = *tmp1->second.begin(); + if ( !baseurl.empty() ) + { + Url url = make_url( baseurl ); + if ( !url.isValid() ) + { + zypper.setExitCode(ZYPPER_EXIT_ERR_INVALID_ARGS); + return; + } + repo.setBaseUrl( url ); + } + } + if ( changed_enabled || changed_autoref || changed_prio - || changed_keeppackages || changed_gpgcheck || !name.empty() ) + || changed_keeppackages || changed_gpgcheck || !name.empty() || !baseurl.empty() ) { std::string volatileNote; // service repos changes may be volatile std::string volatileNoteIfPlugin; // plugin service repos changes may be volatile @@ -2213,6 +2229,12 @@ void modify_repo( Zypper & zypper, const std::string & alias ) zypper.out().info( str::Format(_("Name of repository '%s' has been set to '%s'.")) % alias % name, volatileNote ); } + if ( !baseurl.empty() ) + { + if ( !volatileNote.empty() ) didVolatileChanges = true; + zypper.out().info( str::Format(_("Baseurl of repository '%s' has been set to '%s'.")) % alias % baseurl, volatileNote ); + } + if ( didVolatileChanges ) { zypper.out().warning( volatileServiceRepoChange( repo ) );