geary-args.vala 5.02 KB
Newer Older
1
/* Copyright 2016 Software Freedom Conservancy Inc.
2 3
 *
 * This software is licensed under the GNU Lesser General Public License
4
 * (version 2.1 or later).  See the COPYING file in this distribution.
5 6 7 8 9
 */

namespace Args {

private const OptionEntry[] options = {
10
    { "hidden", 0, 0, OptionArg.NONE, ref hidden_startup, N_("Start Geary with hidden main window"), null },
11 12
    { "debug", 'd', 0, OptionArg.NONE, ref log_debug, N_("Output debugging information"), null },
    { "log-conversations", 0, 0, OptionArg.NONE, ref log_conversations, N_("Log conversation monitoring"), null },
Jim Nelson's avatar
Jim Nelson committed
13
    { "log-deserializer", 0, 0, OptionArg.NONE, ref log_deserializer, N_("Log network deserialization"), null },
14 15 16 17 18 19 20 21 22 23 24
    { "log-network", 0, 0, OptionArg.NONE, ref log_network, N_("Log network activity"), null },
    /// The IMAP replay queue is how changes on the server are replicated on the client.
    /// It could also be called the IMAP events queue.
    { "log-replay-queue", 0, 0, OptionArg.NONE, ref log_replay_queue, N_("Log IMAP replay queue"), null },
    /// Serialization is how commands and responses are converted into a stream of bytes for
    /// network transmission
    { "log-serializer", 0, 0, OptionArg.NONE, ref log_serializer, N_("Log network serialization"), null },
    { "log-periodic", 0, 0, OptionArg.NONE, ref log_periodic, N_("Log periodic activity"), null },
    { "log-sql", 0, 0, OptionArg.NONE, ref log_sql, N_("Log database queries (generates lots of messages)"), null },
    /// "Normalization" can also be called "synchronization"
    { "log-folder-normalization", 0, 0, OptionArg.NONE, ref log_folder_normalization, N_("Log folder normalization"), null },
25
    { "inspector", 'i', 0, OptionArg.NONE, ref inspector, N_("Allow inspection of WebView"), null },
26
    { "revoke-certs", 0, 0, OptionArg.NONE, ref revoke_certs, N_("Revoke all server certificates with TLS warnings"), null },
27
    { "quit", 'q', 0, OptionArg.NONE, ref quit, N_("Perform a graceful quit"), null },
28 29 30 31
    { "version", 'V', 0, OptionArg.NONE, ref version, N_("Display program version"), null },
    { null }
};

32
public bool hidden_startup = false;
33 34 35
public bool log_debug = false;
public bool log_network = false;
public bool log_serializer = false;
Jim Nelson's avatar
Jim Nelson committed
36
public bool log_deserializer = false;
37 38 39 40 41
public bool log_replay_queue = false;
public bool log_conversations = false;
public bool log_periodic = false;
public bool log_sql = false;
public bool log_folder_normalization = false;
42
public bool inspector = false;
43
public bool quit = false;
44
public bool revoke_certs = false;
45 46
public bool version = false;

47 48
public bool parse(string[] args) {
    var context = new OptionContext("[%s...]".printf(Geary.ComposedEmail.MAILTO_SCHEME));
49 50
    context.set_help_enabled(true);
    context.add_main_entries(options, null);
51
    context.set_description("%s\n\n%s\n%s\n\n%s\n\t%s\n".printf(
52 53
        // This gives a command-line hint on how to open new composer windows with mailto:
        _("Use %s to open a new composer window").printf(Geary.ComposedEmail.MAILTO_SCHEME),
54 55 56
        GearyApplication.COPYRIGHT_1,
        GearyApplication.COPYRIGHT_2,
        _("Please report comments, suggestions and bugs to:"),
57 58 59 60 61 62 63
        GearyApplication.BUGREPORT));
    
    try {
        context.parse(ref args);
    } catch (OptionError error) {
        // i18n: Command line arguments are invalid
        stdout.printf (_("Failed to parse command line options: %s\n"), error.message);
64 65
        stdout.printf("\n%s", context.get_help(true, null));
        return false;
66 67 68 69 70 71 72 73
    }
    
    // other than the OptionEntry command-line arguments, the only acceptable arguments are
    // mailto:'s
    for (int ctr = 1; ctr < args.length; ctr++) {
        string arg = args[ctr];
        
        if (!arg.has_prefix(Geary.ComposedEmail.MAILTO_SCHEME)) {
74
            stdout.printf(_("Unrecognized command line option “%s”\n").printf(arg));
75
            stdout.printf("\n%s", context.get_help(true, null));
76
            
77
            return false;
78 79 80 81 82
        }
    }
    
    if (version) {
        stdout.printf("%s %s\n", GearyApplication.PRGNAME, GearyApplication.VERSION);
83
        Process.exit(0);
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
    }
    
    if (log_network)
        Geary.Logging.enable_flags(Geary.Logging.Flag.NETWORK);
    
    if (log_serializer)
        Geary.Logging.enable_flags(Geary.Logging.Flag.SERIALIZER);
    
    if (log_replay_queue)
        Geary.Logging.enable_flags(Geary.Logging.Flag.REPLAY);
    
    if (log_conversations)
        Geary.Logging.enable_flags(Geary.Logging.Flag.CONVERSATIONS);
    
    if (log_periodic)
        Geary.Logging.enable_flags(Geary.Logging.Flag.PERIODIC);
    
    if (log_sql)
        Geary.Logging.enable_flags(Geary.Logging.Flag.SQL);
    
    if (log_folder_normalization)
        Geary.Logging.enable_flags(Geary.Logging.Flag.FOLDER_NORMALIZATION);
    
Jim Nelson's avatar
Jim Nelson committed
107 108
    if (log_deserializer)
        Geary.Logging.enable_flags(Geary.Logging.Flag.DESERIALIZER);
109 110

    if (log_debug) {
111
        Geary.Logging.log_to(stdout);
112 113 114 115 116 117
    } else {
        // We'll be logging to stderror until this point, so stop
        // that.
        Geary.Logging.log_to(null);
    }

118
    return true;
119 120 121 122
}

}