/// <summary> /// Resolves or removes existing aliases. /// </summary> /// <param name="aliasName">The name of the existing alias.</param> /// <returns>The exit status code to end the process with.</returns> private ExitCode ResolveOrRemove(string aliasName) { using (var integrationManager = new IntegrationManager(Handler, MachineWide)) { AppEntry appEntry; var appAlias = GetAppAlias(integrationManager.AppList, aliasName, out appEntry); if (appAlias == null) { Handler.Output(Resources.AppAlias, string.Format(Resources.AliasNotFound, aliasName)); return(ExitCode.InvalidArguments); } if (_resolve) { string result = appEntry.InterfaceUri.ToStringRfc(); if (!string.IsNullOrEmpty(appAlias.Command)) { result += Environment.NewLine + "Command: " + appAlias.Command; } Handler.OutputLow(Resources.AppAlias, result); } if (_remove) { integrationManager.RemoveAccessPoints(appEntry, new AccessPoint[] { appAlias }); Handler.OutputLow(Resources.AppAlias, string.Format(Resources.AliasRemoved, aliasName, appEntry.Name)); } return(ExitCode.OK); } }
public void RemoveAccessPoints() { var capabilityList = CapabilityListTest.CreateTestCapabilityList(); var testApp = new Feed { Name = "Test", CapabilityLists = { capabilityList } }; using var unapplyFlag = new TemporaryFlagFile("0install-test-flag"); var accessPoint = new MockAccessPoint { ID = "id1", Capability = "my_ext1", UnapplyFlagPath = unapplyFlag }; // Inject access point into AppEntry (without running integration) var appEntry = _integrationManager.AddApp(new FeedTarget(FeedTest.Test1Uri, testApp)); appEntry.AccessPoints = new AccessPointList { Entries = { accessPoint } }; _integrationManager.RemoveAccessPoints(appEntry, new[] { accessPoint }); _integrationManager.AppList.Entries[0].AccessPoints !.Entries.Should().BeEmpty(); unapplyFlag.Set.Should().BeTrue(because: "Unapply() should be called"); _integrationManager.Invoking(x => x.RemoveAccessPoints(appEntry, new[] { accessPoint })) .Should().NotThrow(because: "Allow multiple removals of access points."); }
/// <inheritdoc /> protected override ExitCode ExecuteHelper() { string aliasName = AdditionalArgs[0]; if (_resolve || _remove) { if (AdditionalArgs.Count > 1) { throw new OptionException(Resources.TooManyArguments + Environment.NewLine + AdditionalArgs[1].EscapeArgument(), null); } var match = IntegrationManager.AppList.FindAppAlias(aliasName); if (!match.HasValue) { Handler.Output(Resources.AppAlias, string.Format(Resources.AliasNotFound, aliasName)); return(ExitCode.NoChanges); } var(alias, appEntry) = match.Value; if (_resolve) { string result = appEntry.InterfaceUri.ToStringRfc(); if (!string.IsNullOrEmpty(alias.Command)) { result += Environment.NewLine + "Command: " + alias.Command; } Handler.OutputLow(Resources.AppAlias, result); } if (_remove) { IntegrationManager.RemoveAccessPoints(appEntry, new AccessPoint[] { alias }); Handler.OutputLow(Resources.AppAlias, string.Format(Resources.AliasRemoved, aliasName, appEntry.Name)); } return(ExitCode.OK); } else { if (AdditionalArgs.Count < 2 || string.IsNullOrEmpty(AdditionalArgs[1])) { throw new OptionException(Resources.MissingArguments, null); } string?command = (AdditionalArgs.Count >= 3) ? AdditionalArgs[2] : null; var appEntry = GetAppEntry(IntegrationManager, ref InterfaceUri); CreateAlias(appEntry, aliasName, command); return(ExitCode.OK); } }