mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 10:30:38 +00:00
Add an enum for output types
This commit is contained in:
parent
14c8f07b8d
commit
d4b4bd8603
6 changed files with 28 additions and 8 deletions
|
@ -65,8 +65,8 @@ public class Cli {
|
|||
|
||||
parser.addArgument("-o", "--output")
|
||||
.help("Choose to output in plain text or JSON")
|
||||
.choices("plain-text", "json")
|
||||
.setDefault("plain-text");
|
||||
.type(Arguments.enumStringType(OutputType.class))
|
||||
.setDefault(OutputType.PLAIN_TEXT);
|
||||
|
||||
Subparsers subparsers = parser.addSubparsers().title("subcommands").dest("command");
|
||||
|
||||
|
|
16
src/main/java/org/asamk/signal/OutputType.java
Normal file
16
src/main/java/org/asamk/signal/OutputType.java
Normal file
|
@ -0,0 +1,16 @@
|
|||
package org.asamk.signal;
|
||||
|
||||
public enum OutputType {
|
||||
PLAIN_TEXT {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "plain-text";
|
||||
}
|
||||
},
|
||||
JSON {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "json";
|
||||
}
|
||||
},
|
||||
}
|
|
@ -7,6 +7,7 @@ import net.sourceforge.argparse4j.inf.Subparser;
|
|||
import org.asamk.signal.DbusConfig;
|
||||
import org.asamk.signal.DbusReceiveMessageHandler;
|
||||
import org.asamk.signal.JsonDbusReceiveMessageHandler;
|
||||
import org.asamk.signal.OutputType;
|
||||
import org.asamk.signal.dbus.DbusSignalImpl;
|
||||
import org.asamk.signal.manager.Manager;
|
||||
import org.freedesktop.dbus.connections.impl.DBusConnection;
|
||||
|
@ -38,7 +39,7 @@ public class DaemonCommand implements MultiLocalCommand {
|
|||
|
||||
@Override
|
||||
public int handleCommand(final Namespace ns, final Manager m) {
|
||||
boolean inJson = ns.getString("output").equals("json") || ns.getBoolean("json");
|
||||
boolean inJson = ns.get("output") == OutputType.JSON || ns.getBoolean("json");
|
||||
|
||||
// TODO delete later when "json" variable is removed
|
||||
if (ns.getBoolean("json")) {
|
||||
|
@ -73,7 +74,7 @@ public class DaemonCommand implements MultiLocalCommand {
|
|||
|
||||
@Override
|
||||
public int handleCommand(final Namespace ns, final List<Manager> managers) {
|
||||
boolean inJson = ns.getString("output").equals("json") || ns.getBoolean("json");
|
||||
boolean inJson = ns.get("output") == OutputType.JSON || ns.getBoolean("json");
|
||||
|
||||
// TODO delete later when "json" variable is removed
|
||||
if (ns.getBoolean("json")) {
|
||||
|
|
|
@ -7,6 +7,7 @@ import net.sourceforge.argparse4j.impl.Arguments;
|
|||
import net.sourceforge.argparse4j.inf.Namespace;
|
||||
import net.sourceforge.argparse4j.inf.Subparser;
|
||||
|
||||
import org.asamk.signal.OutputType;
|
||||
import org.asamk.signal.manager.Manager;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -37,7 +38,7 @@ public class GetUserStatusCommand implements LocalCommand {
|
|||
ObjectMapper jsonProcessor = new ObjectMapper();
|
||||
jsonProcessor.disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET);
|
||||
|
||||
boolean inJson = ns.getString("output").equals("json") || ns.getBoolean("json");
|
||||
boolean inJson = ns.get("output") == OutputType.JSON || ns.getBoolean("json");
|
||||
|
||||
// TODO delete later when "json" variable is removed
|
||||
if (ns.getBoolean("json")) {
|
||||
|
|
|
@ -9,6 +9,7 @@ import net.sourceforge.argparse4j.impl.Arguments;
|
|||
import net.sourceforge.argparse4j.inf.Namespace;
|
||||
import net.sourceforge.argparse4j.inf.Subparser;
|
||||
|
||||
import org.asamk.signal.OutputType;
|
||||
import org.asamk.signal.manager.Manager;
|
||||
import org.asamk.signal.manager.groups.GroupInviteLinkUrl;
|
||||
import org.asamk.signal.manager.storage.groups.GroupInfo;
|
||||
|
@ -75,7 +76,7 @@ public class ListGroupsCommand implements LocalCommand {
|
|||
|
||||
@Override
|
||||
public int handleCommand(final Namespace ns, final Manager m) {
|
||||
if (ns.getString("output").equals("json")) {
|
||||
if (ns.get("output") == OutputType.JSON) {
|
||||
final ObjectMapper jsonProcessor = new ObjectMapper();
|
||||
jsonProcessor.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
|
||||
jsonProcessor.disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET);
|
||||
|
|
|
@ -12,6 +12,7 @@ import net.sourceforge.argparse4j.inf.Subparser;
|
|||
|
||||
import org.asamk.Signal;
|
||||
import org.asamk.signal.JsonReceiveMessageHandler;
|
||||
import org.asamk.signal.OutputType;
|
||||
import org.asamk.signal.ReceiveMessageHandler;
|
||||
import org.asamk.signal.json.JsonMessageEnvelope;
|
||||
import org.asamk.signal.manager.Manager;
|
||||
|
@ -48,7 +49,7 @@ public class ReceiveCommand implements ExtendedDbusCommand, LocalCommand {
|
|||
public int handleCommand(final Namespace ns, final Signal signal, DBusConnection dbusconnection) {
|
||||
final ObjectMapper jsonProcessor;
|
||||
|
||||
boolean inJson = ns.getString("output").equals("json") || ns.getBoolean("json");
|
||||
boolean inJson = ns.get("output") == OutputType.JSON || ns.getBoolean("json");
|
||||
|
||||
// TODO delete later when "json" variable is removed
|
||||
if (ns.getBoolean("json")) {
|
||||
|
@ -156,7 +157,7 @@ public class ReceiveCommand implements ExtendedDbusCommand, LocalCommand {
|
|||
|
||||
@Override
|
||||
public int handleCommand(final Namespace ns, final Manager m) {
|
||||
boolean inJson = ns.getString("output").equals("json") || ns.getBoolean("json");
|
||||
boolean inJson = ns.get("output") == OutputType.JSON || ns.getBoolean("json");
|
||||
|
||||
// TODO delete later when "json" variable is removed
|
||||
if (ns.getBoolean("json")) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue