Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

channel list output is confusing #755 #777

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@
import java.util.Optional;

import org.wildfly.channel.Channel;
import org.wildfly.channel.ChannelManifestCoordinate;
import org.wildfly.channel.ChannelMapper;
import org.wildfly.channel.Repository;
import org.wildfly.prospero.actions.MetadataAction;
import org.wildfly.prospero.cli.ActionFactory;
import org.wildfly.prospero.cli.CliConsole;
import org.wildfly.prospero.cli.CliMessages;
import org.wildfly.prospero.cli.ReturnCodes;
import org.wildfly.prospero.cli.printers.ChannelPrinter;
import org.wildfly.prospero.metadata.ManifestVersionRecord;
import picocli.CommandLine;

Expand All @@ -53,6 +55,9 @@ public static class ChannelListCommand extends AbstractCommand {
@CommandLine.Option(names = CliConstants.DIR)
Optional<Path> directory;

@CommandLine.Option(names = CliConstants.FULL)
spyrkob marked this conversation as resolved.
Show resolved Hide resolved
boolean fullList;

public ChannelListCommand(CliConsole console, ActionFactory actionFactory) {
super(console, actionFactory);
}
Expand All @@ -68,12 +73,33 @@ public Integer call() throws Exception {
channels = metadataAction.getChannels();
}

final ChannelPrinter channelPrinter = new ChannelPrinter(console);
console.println("-------");
for (Channel channel : channels) {
channelPrinter.print(channel);
console.println("-------");
}
if (fullList) {
console.println(ChannelMapper.toYaml(channels));
} else {
ChannelManifestCoordinate coordinate = channel.getManifestCoordinate();
if (coordinate != null) {
// Full Maven GAV
if (coordinate.getVersion() != null && !coordinate.getVersion().isEmpty()) {
console.println(channel.getName() + " " + coordinate.getGroupId() + ":" + coordinate.getArtifactId() + ":" + coordinate.getVersion() + "\n");
}
// GA only (no version)
else if (coordinate.getGroupId() != null && coordinate.getArtifactId() != null) {
console.println(channel.getName() + " " + coordinate.getGroupId() + ":" + coordinate.getArtifactId() + "\n");
}
// Manifest URL
else if (coordinate.getUrl() != null){
console.println(channel.getName() + " " + coordinate.getUrl() + "\n");
}
} else {
// No manifest coordinate, print no-stream-strategy and repository ids
console.println(channel.getName() + " no-stream-strategy: " + channel.getNoStreamStrategy());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just one thing - can you inline this to something like <channel_name> <no_manifest_strategy> @ <repo1_id>,<repo2_id>[...]. All other cases are one line, we should keep this the same

for (Repository repo : channel.getRepositories()) {
console.println("Repository ID: " + repo.getId());
}
}
}
}

return ReturnCodes.SUCCESS;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ private Commands() {
public static final String DIR = "--dir";
public static final String FEATURE_PACK_REFERENCE = "<feature-pack-reference>";
public static final String FPL = "--fpl";
public static final String FULL = "--full";
public static final String H = "-h";
public static final String HELP = "--help";
public static final String LAYERS = "--layers";
Expand Down
1 change: 1 addition & 0 deletions prospero-cli/src/main/resources/UsageMessages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ ${prospero.dist.name}.help = Displays the help information for the command.
verbose = Prints additional information if the command fails.
${prospero.dist.name}.verbose = Prints additional information if the command fails.
debug = Prints debug messages.
full = Display the detailed list of all available channels
${prospero.dist.name}.debug = Prints debug messages.
local-cache = Path to the local Maven repository cache. It overrides the default Maven repository at ~/.m2/repository.
no-resolve-local-cache = Perform the operation without resolving or installing artifacts in the local maven cache.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.wildfly.prospero.cli.commands;

import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Files;
Expand All @@ -34,10 +35,11 @@
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.wildfly.channel.Channel;
import org.wildfly.channel.ChannelManifest;
import org.wildfly.channel.ChannelManifestCoordinate;
import org.wildfly.channel.MavenCoordinate;
import org.wildfly.channel.Repository;
import org.wildfly.channel.ChannelManifest;
import org.wildfly.channel.ChannelMapper;
import org.wildfly.prospero.api.InstallationMetadata;
import org.wildfly.prospero.api.exceptions.MetadataException;
import org.wildfly.prospero.cli.AbstractConsoleTest;
Expand Down Expand Up @@ -191,9 +193,28 @@ public void testList() {
int exitCode = commandLine.execute(CliConstants.Commands.CHANNEL, CliConstants.Commands.LIST,
CliConstants.DIR, dir.toString());
Assert.assertEquals(ReturnCodes.SUCCESS, exitCode);
Assert.assertEquals(3, getStandardOutput().lines().filter(l->l.contains("manifest")).count());
assertThat(getStandardOutput().lines()
.filter(line -> line.matches(".*\\S+ \\S+:\\S+(?::\\S+)?")))
.containsExactlyInAnyOrder(
"test1 g:a",
"test2 g:a:v",
"test3 file:/a:b"
);
}

@Test
public void testFullList() throws MetadataException, IOException {
// Execute the command
int exitCode = commandLine.execute(CliConstants.Commands.CHANNEL, CliConstants.Commands.LIST, CliConstants.FULL,
CliConstants.DIR, dir.toString());
InstallationMetadata installationMetadata = InstallationMetadata.loadInstallation(dir);

Assert.assertEquals(ReturnCodes.SUCCESS, exitCode);
assertThat(getStandardOutput()).contains(ChannelMapper.toYaml(installationMetadata.getProsperoConfig().getChannels()));

}


@Test
public void testAddDuplicate() {
int exitCode = commandLine.execute(CliConstants.Commands.CHANNEL, CliConstants.Commands.ADD,
Expand Down
Loading