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> ] <repo-info> <package-file ...> \n" 25 " Creates a package repository from the information found in \n" 26 " <repo-info>, adding the given 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 " -f - print canonical filenames of packages.\n" 36 " -v - be verbose (list attributes of all packages found).\n" 37 "\n" 38 " update [ <options> ] <source-repo> <new-repo> <package-list-file> \n" 39 " Creates package repository file <new-repo> with all the packages\n" 40 " contained in <package-list-file>. If possible, package-infos are\n" 41 " taken from <source-repo> to avoid the need for recomputing the\n" 42 " checksum of all packages.\n" 43 " <old-repo> and <new-repo> can be the same file.\n" 44 " When -t is specified, filenames in the package-list-file are assumed\n" 45 " to be equal to their canonical name that can be reconstructed from\n" 46 " the repository file. This removes the need for accessing the files\n" 47 " and they are allowed to be completely missing.\n" 48 "\n" 49 " -C <dir> - Change to directory <dir> before starting.\n" 50 " -q - be quiet (don't show any output except for errors).\n" 51 " -v - be verbose (list package attributes as encountered).\n" 52 " -t - Trust filenames in package-list-file to be canonical.\n" 53 "\n" 54 "Common Options:\n" 55 " -h, --help - Print this usage info.\n" 56 ; 57 58 59 void 60 print_usage_and_exit(bool error) 61 { 62 fprintf(error ? stderr : stdout, kUsage, kCommandName); 63 exit(error ? 1 : 0); 64 } 65 66 67 int 68 main(int argc, const char* const* argv) 69 { 70 if (argc < 2) 71 print_usage_and_exit(true); 72 73 const char* command = argv[1]; 74 if (strcmp(command, "create") == 0) 75 return command_create(argc - 1, argv + 1); 76 77 if (strcmp(command, "list") == 0) 78 return command_list(argc - 1, argv + 1); 79 80 if (strcmp(command, "update") == 0) 81 return command_update(argc - 1, argv + 1); 82 83 if (strcmp(command, "help") == 0) 84 print_usage_and_exit(false); 85 else 86 print_usage_and_exit(true); 87 88 // never gets here 89 return 0; 90 } 91