mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 18:40:39 +00:00
Added JSON output to listGroups and allowed json to be activated with -j (#401)
* Added json output to listGroups and allowed json to be activated with -j * Renamed classes * Added AsamK's suggestions * Removed isRegisted check since that is causing a conflict with upstream * Fixed an issue in the help message for listGroupsCommand * Re-enabled --json for receive and getUserStatuses commands as deprecated * Added better depricated warning message and clarified some java doc stuff
This commit is contained in:
parent
c9fa28d844
commit
90f5cd79c9
6 changed files with 134 additions and 41 deletions
|
@ -8,6 +8,8 @@ import net.sourceforge.argparse4j.inf.Namespace;
|
|||
import net.sourceforge.argparse4j.inf.Subparser;
|
||||
|
||||
import org.asamk.signal.manager.Manager;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
|
@ -17,12 +19,15 @@ import java.util.stream.Collectors;
|
|||
|
||||
public class GetUserStatusCommand implements LocalCommand {
|
||||
|
||||
// TODO delete later when "json" variable is removed
|
||||
final static Logger logger = LoggerFactory.getLogger(GetUserStatusCommand.class);
|
||||
|
||||
@Override
|
||||
public void attachToSubparser(final Subparser subparser) {
|
||||
subparser.addArgument("number").help("Phone number").nargs("+");
|
||||
subparser.help("Check if the specified phone number/s have been registered");
|
||||
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 \"output\" option instead.\n\nOutput received messages in json format, one json object per line.")
|
||||
.action(Arguments.storeTrue());
|
||||
}
|
||||
|
||||
|
@ -32,6 +37,13 @@ public class GetUserStatusCommand implements LocalCommand {
|
|||
ObjectMapper jsonProcessor = new ObjectMapper();
|
||||
jsonProcessor.disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET);
|
||||
|
||||
boolean inJson = ns.getString("output").equals("json");
|
||||
|
||||
// TODO delete later when "json" variable is removed
|
||||
if (ns.getBoolean("json")) {
|
||||
logger.warn("\"--json\" option has been deprecated, please use \"output\" instead.");
|
||||
}
|
||||
|
||||
// Get a map of registration statuses
|
||||
Map<String, Boolean> registered;
|
||||
try {
|
||||
|
@ -42,7 +54,7 @@ public class GetUserStatusCommand implements LocalCommand {
|
|||
}
|
||||
|
||||
// Output
|
||||
if (ns.getBoolean("json")) {
|
||||
if (inJson) {
|
||||
List<JsonIsRegistered> objects = registered.entrySet()
|
||||
.stream()
|
||||
.map(entry -> new JsonIsRegistered(entry.getKey(), entry.getValue()))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue