From: Jean-Philippe Orsini Date: Sun, 24 Mar 2013 12:23:05 +0000 (+0000) Subject: added support of --help and --version X-Git-Tag: v0.0.6~123 X-Git-Url: https://git.wpitchoune.net/gitweb/?p=ptask.git;a=commitdiff_plain;h=156559c34ff1d61b2045365b85a9613b854119ba added support of --help and --version --- diff --git a/src/main.c b/src/main.c index 90d5966..f791684 100644 --- a/src/main.c +++ b/src/main.c @@ -19,6 +19,7 @@ #include #include #include +#include #include @@ -28,6 +29,7 @@ #include "note.h" #include "tw.h" +static const char *program_name; static struct task **tasks; static GtkTextView *w_note; static GtkEntry *w_description; @@ -46,6 +48,42 @@ enum { COL_PRIORITY }; +static struct option long_options[] = { + {"version", no_argument, 0, 'v'}, + {"help", no_argument, 0, 'h'}, + {0, 0, 0, 0} +}; + +static void print_version() +{ + printf("ptask %s\n", VERSION); + printf(_("Copyright (C) %s jeanfi@gmail.com\n" + "License GPLv2: GNU GPL version 2 or later " + "\n" + "This is free software: you are free to change and " + " redistribute it.\n" + "There is NO WARRANTY, to the extent permitted by law.\n"), + "2012-2013"); +} + +static void print_help() +{ + printf(_("Usage: %s [OPTION]...\n"), program_name); + + puts(_("Ptask is a task management UI based on taskwarrior.")); + + puts(""); + puts(_("Options:")); + puts(_(" -h, --help display this help and exit\n" + " -v, --version display version information and exit")); + + puts(""); + + printf(_("Report bugs to: %s\n"), PACKAGE_BUGREPORT); + puts(""); + printf(_("%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL); +} + static struct task *get_selected_task(GtkTreeView *treeview) { GtkTreePath *path; @@ -375,6 +413,9 @@ int main(int argc, char **argv) GtkWidget *window, *btn; GtkBuilder *builder; GtkTreeModel *model; + int optc, cmdok, opti; + + program_name = argv[0]; setlocale(LC_ALL, ""); @@ -383,6 +424,28 @@ int main(int argc, char **argv) textdomain(PACKAGE); #endif + cmdok = 1; + while ((optc = getopt_long(argc, argv, "vh", long_options, + &opti)) != -1) { + switch (optc) { + case 'h': + print_help(); + exit(EXIT_SUCCESS); + case 'v': + print_version(); + exit(EXIT_SUCCESS); + default: + cmdok = 0; + break; + } + } + + if (!cmdok || optind != argc) { + fprintf(stderr, _("Try `%s --help' for more information.\n"), + program_name); + exit(EXIT_FAILURE); + } + gtk_init(NULL, NULL); builder = gtk_builder_new(); gtk_builder_add_from_file