Add querying use cases
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
qvalentin 2022-05-25 19:13:52 +02:00
parent fd4a2c0e83
commit 71b28222a7
8 changed files with 220 additions and 152 deletions

View file

@ -7,33 +7,52 @@ import java.util.stream.Collectors;
public class LinkCommands extends Subcommand {
private final LinkCliAdapter linkCliAdapter;
private final LinkCliAdapter linkCliAdapter;
public LinkCommands(LinkCliAdapter linkCliAdapter) {
this.linkCliAdapter = linkCliAdapter;
commands.put("add", this::addLink);
commands.put("get", this::getAll);
}
public LinkCommands(LinkCliAdapter linkCliAdapter) {
this.linkCliAdapter = linkCliAdapter;
commands.put("add", this::addLink);
commands.put("get", this::getAll);
commands.put("category", this::getByCategory);
commands.put("user", this::getByUser);
commands.put("tag", this::getByTag);
}
@Override
public String getSubcommand() {
return "link";
}
@Override
public String getSubcommand() {
return "link";
}
@Override
public String getUsage() {
return "Usage: " + System.lineSeparator() +
getSubcommand() + "add http://example.org yourUsername [category1 category2 .. categoryN]";
}
@Override
public String getUsage() {
return "Usage: " + System.lineSeparator() +
getSubcommand() + "add http://example.org yourUsername [category1 category2 .. categoryN]" + System.lineSeparator() +
getSubcommand() + "get " + System.lineSeparator() +
getSubcommand() + "category aCategoryName " + System.lineSeparator() +
getSubcommand() + "tag aTagName " + System.lineSeparator() +
getSubcommand() + "user aUserName ";
}
private String addLink(String[] args) {
linkCliAdapter.addLink(args[1],
Arrays.stream(Arrays.copyOfRange(args, 3, args.length)).collect(Collectors.toSet()),
args[2]);
return "Added the new Link";
}
private String addLink(String[] args) {
linkCliAdapter.addLink(args[1],
Arrays.stream(Arrays.copyOfRange(args, 3, args.length)).collect(Collectors.toSet()),
args[2]);
return "Added the new Link";
}
private String getAll(String[] args) {
return String.join(System.lineSeparator(), linkCliAdapter.getLinks());
}
private String getAll(String[] args) {
return String.join(System.lineSeparator(), linkCliAdapter.getLinks());
}
private String getByCategory(String[] args) {
return String.join(System.lineSeparator(), linkCliAdapter.getLinksForCategory(args[1]));
}
private String getByUser(String[] args) {
return String.join(System.lineSeparator(), linkCliAdapter.getLinksForUser(args[1]));
}
private String getByTag(String[] args) {
return String.join(System.lineSeparator(), linkCliAdapter.getLinksForTag(args[1]));
}
}

View file

@ -2,32 +2,34 @@ package cli.tag;
import cli.Subcommand;
import java.util.HashMap;
import java.util.function.Function;
public class TagCommands extends Subcommand {
final private CustomTagsCliAdapter customTagsCliAdapter;
final private CustomTagsCliAdapter customTagsCliAdapter;
public TagCommands(CustomTagsCliAdapter customTagsCliAdapter) {
this.customTagsCliAdapter = customTagsCliAdapter;
commands.put("add", this::addCustomTag);
}
public TagCommands(CustomTagsCliAdapter customTagsCliAdapter) {
this.customTagsCliAdapter = customTagsCliAdapter;
commands.put("add", this::addCustomTag);
commands.put("get", this::getTags);
}
@Override
public String getSubcommand() {
return "tag";
}
@Override
public String getSubcommand() {
return "tag";
}
@Override
public String getUsage() {
return "Usage: " + System.lineSeparator()+
getSubcommand() + " add tagName tagRegexExpression";
}
@Override
public String getUsage() {
return "Usage: " + System.lineSeparator() +
getSubcommand() + " add tagName tagRegexExpression";
}
private String addCustomTag(String[] args) {
customTagsCliAdapter.addCustomTagMatcher(args[1], args[2]);
return "Added the new Tag matcher";
}
private String addCustomTag(String[] args) {
customTagsCliAdapter.addCustomTagMatcher(args[1], args[2]);
return "Added the new Tag matcher";
}
private String getTags(String[] args) {
return String.join(System.lineSeparator(), customTagsCliAdapter.getAllTagNames());
}
}