1 /* 2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * Copyright 2011, Oliver Tappe <zooey@hirschkaefer.de> 4 * Distributed under the terms of the MIT License. 5 */ 6 7 8 #include "package.h" 9 10 #include <errno.h> 11 #include <getopt.h> 12 #include <stdio.h> 13 #include <stdlib.h> 14 #include <string.h> 15 16 17 extern const char* __progname; 18 const char* kCommandName = __progname; 19 20 21 static const char* kUsage = 22 "Usage: %s <command> <command args>\n" 23 "Creates, inspects, or extracts a Haiku package.\n" 24 "\n" 25 "Commands:\n" 26 " add [ <options> ] <package> <entries>...\n" 27 " Adds the specified entries <entries> to package file <package>.\n" 28 "\n" 29 " -C <dir> - Change to directory <dir> before adding entries.\n" 30 " -f - Force adding, replacing already existing entries. " 31 "Without\n" 32 " this option adding will fail when encountering a " 33 "pre-exiting\n" 34 " entry (directories will be merged, though).\n" 35 " -i <info> - Use the package info file <info>. It will be added as\n" 36 " \".PackageInfo\", overriding a \".PackageInfo\" file,\n" 37 " existing.\n" 38 " -q - Be quiet (don't show any output except for errors).\n" 39 " -v - Be verbose (show more info about created package).\n" 40 "\n" 41 " create [ <options> ] <package>\n" 42 " Creates package file <package> from contents of current directory.\n" 43 "\n" 44 " -b - Create an empty build package. Only the .PackageInfo " 45 "will\n" 46 " be added.\n" 47 " -C <dir> - Change to directory <dir> before adding entries.\n" 48 " -i <info> - Use the package info file <info>. It will be added as\n" 49 " \".PackageInfo\", overriding a \".PackageInfo\" file,\n" 50 " existing.\n" 51 " -I <path> - Set the package's installation path to <path>. This is\n" 52 " an option only for use in package building. It will " 53 "cause\n" 54 " the package .self link to point to <path>, which is " 55 "useful\n" 56 " to redirect a \"make install\". Only allowed with -b.\n" 57 " -q - Be quiet (don't show any output except for errors).\n" 58 " -v - Be verbose (show more info about created package).\n" 59 "\n" 60 " dump [ <options> ] <package>\n" 61 " Dumps the TOC section of package file <package>. For debugging only.\n" 62 "\n" 63 " extract [ <options> ] <package> [ <entries>... ]\n" 64 " Extracts the contents of package file <package>. If <entries> are\n" 65 " specified, only those entries are extracted (directories " 66 "recursively).\n" 67 "\n" 68 " -C <dir> - Change to directory <dir> before extracting the " 69 "contents\n" 70 " of the archive.\n" 71 " -i <info> - Extract the .PackageInfo file to <info> instead.\n" 72 "\n" 73 " list [ <options> ] <package>\n" 74 " Lists the contents of package file <package>.\n" 75 "\n" 76 " -a - Also list the file attributes.\n" 77 " -p - Only print a list of file paths.\n" 78 "\n" 79 "Common Options:\n" 80 " -h, --help - Print this usage info.\n" 81 ; 82 83 84 void 85 print_usage_and_exit(bool error) 86 { 87 fprintf(error ? stderr : stdout, kUsage, kCommandName); 88 exit(error ? 1 : 0); 89 } 90 91 92 int 93 main(int argc, const char* const* argv) 94 { 95 if (argc < 2) 96 print_usage_and_exit(true); 97 98 const char* command = argv[1]; 99 if (strcmp(command, "add") == 0) 100 return command_add(argc - 1, argv + 1); 101 102 if (strcmp(command, "create") == 0) 103 return command_create(argc - 1, argv + 1); 104 105 if (strcmp(command, "dump") == 0) 106 return command_dump(argc - 1, argv + 1); 107 108 if (strcmp(command, "extract") == 0) 109 return command_extract(argc - 1, argv + 1); 110 111 if (strcmp(command, "list") == 0) 112 return command_list(argc - 1, argv + 1); 113 114 if (strcmp(command, "help") == 0) 115 print_usage_and_exit(false); 116 else 117 print_usage_and_exit(true); 118 119 // never gets here 120 return 0; 121 } 122