]> nmode's Git Repositories - signal-cli/blobdiff - src/main/java/cli/Main.java
Fix formatting
[signal-cli] / src / main / java / cli / Main.java
index 31979d8cd590fd9dce1f6bd17ceae35457c9f1a7..d314ff0b2fb765b17116e660a3625935e01e0386 100644 (file)
@@ -105,10 +105,10 @@ public class Main {
                     }
                 }
 
                     }
                 }
 
-                final List<String> attachments = ns.<String>getList("attachment");
+                final List<String> attachments = ns.getList("attachment");
                 List<TextSecureAttachment> textSecureAttachments = null;
                 if (attachments != null) {
                 List<TextSecureAttachment> textSecureAttachments = null;
                 if (attachments != null) {
-                    textSecureAttachments = new ArrayList<TextSecureAttachment>(attachments.size());
+                    textSecureAttachments = new ArrayList<>(attachments.size());
                     for (String attachment : attachments) {
                         try {
                             File attachmentFile = new File(attachment);
                     for (String attachment : attachments) {
                         try {
                             File attachmentFile = new File(attachment);
@@ -161,7 +161,15 @@ public class Main {
     private static Namespace parseArgs(String[] args) {
         ArgumentParser parser = ArgumentParsers.newArgumentParser("textsecure-cli")
                 .defaultHelp(true)
     private static Namespace parseArgs(String[] args) {
         ArgumentParser parser = ArgumentParsers.newArgumentParser("textsecure-cli")
                 .defaultHelp(true)
-                .description("Commandline interface for TextSecure.");
+                .description("Commandline interface for TextSecure.")
+                .version(Manager.PROJECT_NAME + " " + Manager.PROJECT_VERSION);
+
+        parser.addArgument("-u", "--username")
+                .help("Specify your phone number, that will be used for verification.");
+        parser.addArgument("-v", "--version")
+                .help("Show package version.")
+                .action(Arguments.version());
+
         Subparsers subparsers = parser.addSubparsers()
                 .title("subcommands")
                 .dest("command")
         Subparsers subparsers = parser.addSubparsers()
                 .title("subcommands")
                 .dest("command")
@@ -188,12 +196,15 @@ public class Main {
                 .help("Add file as attachment");
 
         Subparser parserReceive = subparsers.addParser("receive");
                 .help("Add file as attachment");
 
         Subparser parserReceive = subparsers.addParser("receive");
-        parser.addArgument("-u", "--username")
-                .required(true)
-                .help("Specify your phone number, that will be used for verification.");
 
         try {
 
         try {
-            return parser.parseArgs(args);
+            Namespace ns = parser.parseArgs(args);
+            if (ns.getString("username") == null) {
+                parser.printUsage();
+                System.err.println("You need to specify a username (phone number)");
+                System.exit(2);
+            }
+            return ns;
         } catch (ArgumentParserException e) {
             parser.handleError(e);
             return null;
         } catch (ArgumentParserException e) {
             parser.handleError(e);
             return null;
@@ -262,9 +273,11 @@ public class Main {
                             for (TextSecureAttachment attachment : message.getAttachments().get()) {
                                 System.out.println("- " + attachment.getContentType() + " (" + (attachment.isPointer() ? "Pointer" : "") + (attachment.isStream() ? "Stream" : "") + ")");
                                 if (attachment.isPointer()) {
                             for (TextSecureAttachment attachment : message.getAttachments().get()) {
                                 System.out.println("- " + attachment.getContentType() + " (" + (attachment.isPointer() ? "Pointer" : "") + (attachment.isStream() ? "Stream" : "") + ")");
                                 if (attachment.isPointer()) {
-                                    System.out.println("  Id: " + attachment.asPointer().getId() + " Key length: " + attachment.asPointer().getKey().length + (attachment.asPointer().getRelay().isPresent() ? " Relay: " + attachment.asPointer().getRelay().get() : ""));
+                                    final TextSecureAttachmentPointer pointer = attachment.asPointer();
+                                    System.out.println("  Id: " + pointer.getId() + " Key length: " + pointer.getKey().length + (pointer.getRelay().isPresent() ? " Relay: " + pointer.getRelay().get() : ""));
+                                    System.out.println("  Size: " + (pointer.getSize().isPresent() ? pointer.getSize().get() + " bytes" : "<unavailable>") + (pointer.getPreview().isPresent() ? " (Preview is available: " + pointer.getPreview().get().length + " bytes)" : ""));
                                     try {
                                     try {
-                                        File file = m.retrieveAttachment(attachment.asPointer());
+                                        File file = m.retrieveAttachment(pointer);
                                         System.out.println("  Stored plaintext in: " + file);
                                     } catch (IOException | InvalidMessageException e) {
                                         System.out.println("Failed to retrieve attachment: " + e.getMessage());
                                         System.out.println("  Stored plaintext in: " + file);
                                     } catch (IOException | InvalidMessageException e) {
                                         System.out.println("Failed to retrieve attachment: " + e.getMessage());