stuff
This commit is contained in:
parent
7fbc3f722c
commit
22a9368697
12 changed files with 228 additions and 144 deletions
|
@ -21,7 +21,7 @@ abstract public class Subcommand {
|
|||
commandExists(args[0]);
|
||||
return commands.get(args[0]).apply(args);
|
||||
}
|
||||
catch (IndexOutOfBoundsException e) {
|
||||
catch (IndexOutOfBoundsException | IllegalArgumentException e) {
|
||||
throw new CliError("Missing a value! " + getUsage());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ public class CategoryCommands extends Subcommand {
|
|||
|
||||
@Override
|
||||
public String getUsage() {
|
||||
return "Usage:" + System.lineSeparator() + getSubcommand() + "add categoryName" + System.lineSeparator() + getSubcommand() + "get";
|
||||
return "Usage:" + System.lineSeparator() + getSubcommand() + " add categoryName" + System.lineSeparator() + getSubcommand() + " get";
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -7,52 +7,64 @@ 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);
|
||||
commands.put("category", this::getByCategory);
|
||||
commands.put("user", this::getByUser);
|
||||
commands.put("tag", this::getByTag);
|
||||
}
|
||||
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);
|
||||
commands.put("hosts", this::groupByHosts);
|
||||
}
|
||||
|
||||
@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]" + System.lineSeparator() +
|
||||
getSubcommand() + "get " + System.lineSeparator() +
|
||||
getSubcommand() + "category aCategoryName " + System.lineSeparator() +
|
||||
getSubcommand() + "tag aTagName " + System.lineSeparator() +
|
||||
getSubcommand() + "user aUserName ";
|
||||
}
|
||||
@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 " + System.lineSeparator() +
|
||||
getSubcommand() + " hosts";
|
||||
|
||||
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 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 getByCategory(String[] args) {
|
||||
return String.join(System.lineSeparator(), linkCliAdapter.getLinksForCategory(args[1]));
|
||||
}
|
||||
private String getAll(String[] args) {
|
||||
var firstLine = "All available Links:" + System.lineSeparator();
|
||||
return firstLine + String.join(System.lineSeparator(), linkCliAdapter.getLinks());
|
||||
}
|
||||
|
||||
private String getByUser(String[] args) {
|
||||
return String.join(System.lineSeparator(), linkCliAdapter.getLinksForUser(args[1]));
|
||||
}
|
||||
private String getByCategory(String[] args) {
|
||||
var firstLine = "All available Links for the category:" + System.lineSeparator();
|
||||
return firstLine + String.join(System.lineSeparator(), linkCliAdapter.getLinksForCategory(args[1]));
|
||||
}
|
||||
|
||||
private String getByTag(String[] args) {
|
||||
return String.join(System.lineSeparator(), linkCliAdapter.getLinksForTag(args[1]));
|
||||
}
|
||||
private String getByUser(String[] args) {
|
||||
var firstLine = "All available Links for the user:" + System.lineSeparator();
|
||||
return firstLine + String.join(System.lineSeparator(), linkCliAdapter.getLinksForUser(args[1]));
|
||||
}
|
||||
|
||||
private String getByTag(String[] args) {
|
||||
var firstLine = "All available Links for the tag:" + System.lineSeparator();
|
||||
return firstLine + String.join(System.lineSeparator(), linkCliAdapter.getLinksForTag(args[1]));
|
||||
}
|
||||
|
||||
private String groupByHosts(String[] strings) {
|
||||
var firstLine = "All available Links grouped by the host names:" + System.lineSeparator();
|
||||
return firstLine + String.join(System.lineSeparator(), linkCliAdapter.groupByHosts());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ public class TagCommands extends Subcommand {
|
|||
}
|
||||
|
||||
private String getTags(String[] args) {
|
||||
return String.join(System.lineSeparator(), customTagsCliAdapter.getAllTagNames());
|
||||
var firstLine = "All available Tags:" + System.lineSeparator();
|
||||
return firstLine + String.join(System.lineSeparator(), customTagsCliAdapter.getAllTagNames());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,5 @@ public class Main {
|
|||
catch (RuntimeException runtimeException) {
|
||||
System.out.println(runtimeException.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue