Use global output flag for daemon command

This commit is contained in:
AsamK 2021-01-15 12:09:37 +01:00
parent 5938d54784
commit cc40c437d1

View file

@ -10,6 +10,8 @@ import org.asamk.signal.dbus.DbusSignalImpl;
import org.asamk.signal.manager.Manager; import org.asamk.signal.manager.Manager;
import org.freedesktop.dbus.connections.impl.DBusConnection; import org.freedesktop.dbus.connections.impl.DBusConnection;
import org.freedesktop.dbus.exceptions.DBusException; import org.freedesktop.dbus.exceptions.DBusException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException; import java.io.IOException;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -20,6 +22,8 @@ import static org.asamk.signal.util.ErrorUtils.handleAssertionError;
public class DaemonCommand implements LocalCommand { public class DaemonCommand implements LocalCommand {
private final static Logger logger = LoggerFactory.getLogger(ReceiveCommand.class);
@Override @Override
public void attachToSubparser(final Subparser subparser) { public void attachToSubparser(final Subparser subparser) {
subparser.addArgument("--system") subparser.addArgument("--system")
@ -29,12 +33,19 @@ public class DaemonCommand implements LocalCommand {
.help("Dont download attachments of received messages.") .help("Dont download attachments of received messages.")
.action(Arguments.storeTrue()); .action(Arguments.storeTrue());
subparser.addArgument("--json") subparser.addArgument("--json")
.help("Output received messages in json format, one json object per line.") .help("WARNING: This parameter is now deprecated! Please use the global \"--output=json\" option instead.\n\nOutput received messages in json format, one json object per line.")
.action(Arguments.storeTrue()); .action(Arguments.storeTrue());
} }
@Override @Override
public int handleCommand(final Namespace ns, final Manager m) { public int handleCommand(final Namespace ns, final Manager m) {
boolean inJson = ns.getString("output").equals("json") || ns.getBoolean("json");
// TODO delete later when "json" variable is removed
if (ns.getBoolean("json")) {
logger.warn("\"--json\" option has been deprecated, please use the global \"--output=json\" instead.");
}
DBusConnection conn = null; DBusConnection conn = null;
try { try {
try { try {
@ -60,7 +71,7 @@ public class DaemonCommand implements LocalCommand {
TimeUnit.HOURS, TimeUnit.HOURS,
false, false,
ignoreAttachments, ignoreAttachments,
ns.getBoolean("json") inJson
? new JsonDbusReceiveMessageHandler(m, conn, SIGNAL_OBJECTPATH) ? new JsonDbusReceiveMessageHandler(m, conn, SIGNAL_OBJECTPATH)
: new DbusReceiveMessageHandler(m, conn, SIGNAL_OBJECTPATH)); : new DbusReceiveMessageHandler(m, conn, SIGNAL_OBJECTPATH));
return 0; return 0;