]> pd.if.org Git - zpackage/blobdiff - zpm-note.c
add option to echo note after creating
[zpackage] / zpm-note.c
index 05ecda22c95901b3d4f46afd8068ddc2c58a1630..ced0d3fd525a19fbdc45ca6037f5b58462702bfb 100644 (file)
@@ -12,11 +12,15 @@ void usage(void) {
        fprintf(stderr, "zpm-note [-I] [-s <status> ...] [-S <status>] [package]\n");
 }
 
+void print_note(struct zpm_note *n) {
+       printf("%" PRId64 " %s %s\n", n->id, n->pkgid ? n->pkgid : "-", n->note);
+}
+
 int main(int ac, char **av){
        int opt;
        struct zpm pkg;
        char *dbfile;
-       int fail;
+       int fail, echo = 0;
 
        int select = 1;
 
@@ -38,6 +42,7 @@ int main(int ac, char **av){
         * -H hash
         * -a all
         * -m note message, otherwise EDITOR/vi to edit a text file
+        * -e echo note after creating
         * zpm note -p pkgid -P path -H hash -m 'foo'
         * zpm note -l
         * zpm note -D <n>
@@ -53,6 +58,7 @@ int main(int ac, char **av){
                        case 'm': n.note = optarg; break;
                        case 'n': n.id = strtoll(optarg, NULL, 10); break;
                        case 'l': list = 1; break;
+                       case 'e': echo = 1; break;
                        case 'D': delete = 1; break;
                        case 'A': ack = 1; break;
                        case 'a': select = 3; break;
@@ -75,15 +81,17 @@ int main(int ac, char **av){
        if (zpm_open(&pkg, dbfile)) {
                if (list) {
                        while (zpm_note(&pkg, &n, select)) {
-                               printf("%" PRId64 " %s %s\n", n.id,
-                                               n.pkgid ? n.pkgid : "-",
-                                               n.note);
+                               print_note(&n);
                                zpm_note_free(&n);
                        }
                } else if (n.note) {
                        n.id = zpm_note_add(&pkg, n.pkgid, n.path, n.hash, "%s", n.note);
                        if (n.id) {
-                               printf("%" PRId64 "\n", n.id);
+                               if (echo) {
+                                       print_note(&n);
+                               } else {
+                                       printf("%" PRId64 "\n", n.id);
+                               }
                        } else {
                                fprintf(stderr, "unable to create note\n");
                                pkg.error = 1;