plugins.c
1 /*- 2 * Copyright (c) 2012 Marin Atanasov Nikolov <dnaeon@gmail.com> 3 * Copyright (c) 2014 Matthew Seaman <matthew@FreeBSD.org> 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer 11 * in this position and unchanged. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 */ 27 28 #include <getopt.h> 29 #include <stdio.h> 30 #include <stdbool.h> 31 #include <unistd.h> 32 33 #include <pkg.h> 34 35 #include "pkgcli.h" 36 37 void 38 usage_plugins(void) 39 { 40 fprintf(stderr, "Usage: pkg plugins [-l] <plugin>\n\n"); 41 //fprintf(stderr, "For more information see 'pkg help plugins'.\n"); 42 } 43 44 int 45 exec_plugins(int argc, char **argv) 46 { 47 struct pkg_plugin *p = NULL; 48 int ch; 49 bool __unused list_only = true; 50 51 struct option longopts[] = { 52 { "list-only", no_argument, NULL, 'l' }, 53 { NULL, 0, NULL, 0 }, 54 }; 55 56 while ((ch = getopt_long(argc, argv, "+l", longopts, NULL)) != -1) { 57 switch (ch) { 58 case 'l': 59 list_only = true; 60 break; 61 default: 62 usage_plugins(); 63 return (EXIT_FAILURE); 64 } 65 } 66 67 /** 68 * For now only display the available plugins 69 * @todo: implement enabling, disabling and configuring of plugins 70 */ 71 72 printf("%-10s %-45s %-10s\n", "NAME", "DESC", "VERSION"); 73 while (pkg_plugins(&p) != EPKG_END) 74 printf("%-10s %-45s %-10s\n", 75 pkg_plugin_get(p, PKG_PLUGIN_NAME), 76 pkg_plugin_get(p, PKG_PLUGIN_DESC), 77 pkg_plugin_get(p, PKG_PLUGIN_VERSION)); 78 79 return (EXIT_SUCCESS); 80 }