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.
17 extern const char* __progname
;
18 const char* kCommandName
= __progname
;
21 static const char* kUsage
=
22 "Usage: %s <command> <command args>\n"
23 "Creates, inspects, or extracts a Haiku package.\n"
26 " add [ <options> ] <package> <entries>...\n"
27 " Adds the specified entries <entries> to package file <package>.\n"
29 " -0 ... -9 - Use compression level 0 ... 9. 0 means no, 9 best "
32 " -C <dir> - Change to directory <dir> before adding entries.\n"
33 " -f - Force adding, replacing already existing entries. "
35 " this option adding will fail when encountering a "
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"
41 " -q - Be quiet (don't show any output except for errors).\n"
42 " -v - Be verbose (show more info about created package).\n"
44 " checksum [ <options> ] [ <package> ]\n"
45 " Computes the checksum of package file <package>. If <package> is "
47 " or \"-\", the file is read from stdin. This is only supported, if the "
51 " -q - Be quiet (don't show any output except for errors).\n"
52 " -v - Be verbose (show more info about created package).\n"
54 " create [ <options> ] <package>\n"
55 " Creates package file <package> from contents of current directory.\n"
57 " -0 ... -9 - Use compression level 0 ... 9. 0 means no, 9 best "
60 " -b - Create an empty build package. Only the .PackageInfo "
63 " -C <dir> - Change to directory <dir> before adding entries.\n"
64 " -i <info> - Use the package info file <info>. It will be added as\n"
65 " \".PackageInfo\", overriding a \".PackageInfo\" file,\n"
67 " -I <path> - Set the package's installation path to <path>. This is\n"
68 " an option only for use in package building. It will "
70 " the package .self link to point to <path>, which is "
72 " to redirect a \"make install\". Only allowed with -b.\n"
73 " -q - Be quiet (don't show any output except for errors).\n"
74 " -v - Be verbose (show more info about created package).\n"
76 " dump [ <options> ] <package>\n"
77 " Dumps the TOC section of package file <package>. For debugging only.\n"
79 " extract [ <options> ] <package> [ <entries>... ]\n"
80 " Extracts the contents of package file <package>. If <entries> are\n"
81 " specified, only those entries are extracted (directories "
84 " -C <dir> - Change to directory <dir> before extracting the "
87 " -i <info> - Extract the .PackageInfo file to <info> instead.\n"
89 " info [ <options> ] <package>\n"
90 " Prints individual meta information of package file <package>.\n"
92 " -f <format>, --format <format>\n"
93 " - Print the given format string, performing the following\n"
95 " %%fileName%% - the package's canonical file name\n"
96 " %%name%% - the package name\n"
97 " %%version%% - the package version\n"
102 " list [ <options> ] <package>\n"
103 " Lists the contents of package file <package>.\n"
105 " -a - Also list the file attributes.\n"
106 " -i - Only print the meta information, not the files.\n"
107 " -p - Only print a list of file paths.\n"
109 " recompress [ <options> ] <input package> <output package>\n"
110 " Reads the package file <input package> and writes it to new package\n"
111 " <output package> using the specified compression options. If the\n"
112 " compression level 0 is specified (i.e. no compression), "
114 " can be \"-\", in which case the data are written to stdout.\n"
115 " If the input files doesn't use compression <input package>\n"
116 " can be \"-\", in which case the data are read from stdin.\n"
118 " -0 ... -9 - Use compression level 0 ... 9. 0 means no, 9 best "
121 " -q - Be quiet (don't show any output except for errors).\n"
122 " -v - Be verbose (show more info about created package).\n"
125 " -h, --help - Print this usage info.\n"
130 print_usage_and_exit(bool error
)
132 fprintf(error
? stderr
: stdout
, kUsage
, kCommandName
);
138 main(int argc
, const char* const* argv
)
141 print_usage_and_exit(true);
143 const char* command
= argv
[1];
144 if (strcmp(command
, "add") == 0)
145 return command_add(argc
- 1, argv
+ 1);
147 if (strcmp(command
, "checksum") == 0)
148 return command_checksum(argc
- 1, argv
+ 1);
150 if (strcmp(command
, "create") == 0)
151 return command_create(argc
- 1, argv
+ 1);
153 if (strcmp(command
, "dump") == 0)
154 return command_dump(argc
- 1, argv
+ 1);
156 if (strcmp(command
, "extract") == 0)
157 return command_extract(argc
- 1, argv
+ 1);
159 if (strcmp(command
, "list") == 0)
160 return command_list(argc
- 1, argv
+ 1);
162 if (strcmp(command
, "info") == 0)
163 return command_info(argc
- 1, argv
+ 1);
165 if (strcmp(command
, "recompress") == 0)
166 return command_recompress(argc
- 1, argv
+ 1);
168 if (strcmp(command
, "help") == 0)
169 print_usage_and_exit(false);
171 print_usage_and_exit(true);