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 " -0 ... -9 - Use compression level 0 ... 9. 0 means no, 9 best " 30 "compression.\n" 31 " Defaults to 9.\n" 32 " -C <dir> - Change to directory <dir> before adding entries.\n" 33 " -f - Force adding, replacing already existing entries. " 34 "Without\n" 35 " this option adding will fail when encountering a " 36 "pre-exiting\n" 37 " entry (directories will be merged, though).\n" 38 " -i <info> - Use the package info file <info>. It will be added as\n" 39 " \".PackageInfo\", overriding a \".PackageInfo\" file,\n" 40 " existing.\n" 41 " -q - Be quiet (don't show any output except for errors).\n" 42 " -v - Be verbose (show more info about created package).\n" 43 "\n" 44 " create [ <options> ] <package>\n" 45 " Creates package file <package> from contents of current directory.\n" 46 "\n" 47 " -0 ... -9 - Use compression level 0 ... 9. 0 means no, 9 best " 48 "compression.\n" 49 " Defaults to 9.\n" 50 " -b - Create an empty build package. Only the .PackageInfo " 51 "will\n" 52 " be added.\n" 53 " -C <dir> - Change to directory <dir> before adding entries.\n" 54 " -i <info> - Use the package info file <info>. It will be added as\n" 55 " \".PackageInfo\", overriding a \".PackageInfo\" file,\n" 56 " existing.\n" 57 " -I <path> - Set the package's installation path to <path>. This is\n" 58 " an option only for use in package building. It will " 59 "cause\n" 60 " the package .self link to point to <path>, which is " 61 "useful\n" 62 " to redirect a \"make install\". Only allowed with -b.\n" 63 " -q - Be quiet (don't show any output except for errors).\n" 64 " -v - Be verbose (show more info about created package).\n" 65 "\n" 66 " dump [ <options> ] <package>\n" 67 " Dumps the TOC section of package file <package>. For debugging only.\n" 68 "\n" 69 " extract [ <options> ] <package> [ <entries>... ]\n" 70 " Extracts the contents of package file <package>. If <entries> are\n" 71 " specified, only those entries are extracted (directories " 72 "recursively).\n" 73 "\n" 74 " -C <dir> - Change to directory <dir> before extracting the " 75 "contents\n" 76 " of the archive.\n" 77 " -i <info> - Extract the .PackageInfo file to <info> instead.\n" 78 "\n" 79 " list [ <options> ] <package>\n" 80 " Lists the contents of package file <package>.\n" 81 "\n" 82 " -a - Also list the file attributes.\n" 83 " -i - Only print the meta information, not the files.\n" 84 " -p - Only print a list of file paths.\n" 85 "\n" 86 "Common Options:\n" 87 " -h, --help - Print this usage info.\n" 88 ; 89 90 91 void 92 print_usage_and_exit(bool error) 93 { 94 fprintf(error ? stderr : stdout, kUsage, kCommandName); 95 exit(error ? 1 : 0); 96 } 97 98 99 int 100 main(int argc, const char* const* argv) 101 { 102 if (argc < 2) 103 print_usage_and_exit(true); 104 105 const char* command = argv[1]; 106 if (strcmp(command, "add") == 0) 107 return command_add(argc - 1, argv + 1); 108 109 if (strcmp(command, "create") == 0) 110 return command_create(argc - 1, argv + 1); 111 112 if (strcmp(command, "dump") == 0) 113 return command_dump(argc - 1, argv + 1); 114 115 if (strcmp(command, "extract") == 0) 116 return command_extract(argc - 1, argv + 1); 117 118 if (strcmp(command, "list") == 0) 119 return command_list(argc - 1, argv + 1); 120 121 if (strcmp(command, "help") == 0) 122 print_usage_and_exit(false); 123 else 124 print_usage_and_exit(true); 125 126 // never gets here 127 return 0; 128 } 129