1 /* 2 * Copyright 2011, Oliver Tappe <zooey@hirschkaefer.de> 3 * Distributed under the terms of the MIT License. 4 */ 5 6 7 #include "package_repo.h" 8 9 #include <errno.h> 10 #include <getopt.h> 11 #include <stdio.h> 12 #include <stdlib.h> 13 #include <string.h> 14 15 extern const char* __progname; 16 const char* kCommandName = __progname; 17 18 19 static const char* kUsage = 20 "Usage: %s <command> <command args>\n" 21 "Creates or inspects a Haiku package repository file.\n" 22 "\n" 23 "Commands:\n" 24 " create [ <options> ] <package-repo> <package-file ...> \n" 25 " Creates package repository file <package-repo> from the given\n" 26 " package files.\n" 27 "\n" 28 " -C <dir> - Change to directory <dir> before starting.\n" 29 " -q - be quiet (don't show any output except for errors).\n" 30 " -v - be verbose (list package attributes as encountered).\n" 31 "\n" 32 " list [ <options> ] <package-repo>\n" 33 " Lists the contents of package repository file <package-repo>.\n" 34 "\n" 35 " -v - be verbose (list attributes of all packages found).\n" 36 "\n" 37 "Common Options:\n" 38 " -h, --help - Print this usage info.\n" 39 ; 40 41 42 void 43 print_usage_and_exit(bool error) 44 { 45 fprintf(error ? stderr : stdout, kUsage, kCommandName); 46 exit(error ? 1 : 0); 47 } 48 49 50 int 51 main(int argc, const char* const* argv) 52 { 53 if (argc < 2) 54 print_usage_and_exit(true); 55 56 const char* command = argv[1]; 57 if (strcmp(command, "create") == 0) 58 return command_create(argc - 1, argv + 1); 59 60 if (strcmp(command, "list") == 0) 61 return command_list(argc - 1, argv + 1); 62 63 if (strcmp(command, "help") == 0) 64 print_usage_and_exit(false); 65 else 66 print_usage_and_exit(true); 67 68 // never gets here 69 return 0; 70 } 71