create_repository_config: Make URL argument optional

If not specified, the URL from the repository info is used.
This commit is contained in:
Ingo Weinhold
2014-01-19 00:49:11 +01:00
parent 12c19e6362
commit 1221b67d07
@@ -37,10 +37,11 @@ void
print_usage_and_exit(bool error) print_usage_and_exit(bool error)
{ {
fprintf(error ? stderr : stdout, fprintf(error ? stderr : stdout,
"Usage: %s <URL> <repository info> <repository config>\n" "Usage: %s [ <URL> ] <repository info> <repository config>\n"
"Creates a repository config file from a given base URL (the\n" "Creates a repository config file from a given repository info and\n"
"directory in which the \"repo\", \"repo.info\', and \"repo.sha256\n" "the base URL (the directory in which the \"repo\", \"repo.info\',\n"
"files can be found.\n", "and \"repo.sha256 files can be found). If the URL is not specified,\n"
"the one from the repository info is used.",
sProgramName); sProgramName);
exit(error ? 1 : 0); exit(error ? 1 : 0);
} }
@@ -49,7 +50,7 @@ print_usage_and_exit(bool error)
int int
main(int argc, const char* const* argv) main(int argc, const char* const* argv)
{ {
if (argc != 4) { if (argc < 3 || argc > 4) {
if (argc == 2 if (argc == 2
&& (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0)) { && (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0)) {
print_usage_and_exit(false); print_usage_and_exit(false);
@@ -57,15 +58,19 @@ main(int argc, const char* const* argv)
print_usage_and_exit(true); print_usage_and_exit(true);
} }
const char* url = argv[1]; int argi = 1;
const char* infoPath = argv[2]; const char* url = argc == 4 ? argv[argi++] : NULL;
const char* configPath = argv[3]; const char* infoPath = argv[argi++];
const char* configPath = argv[argi++];
// read the info // read the info
BPackageKit::BRepositoryInfo repoInfo; BPackageKit::BRepositoryInfo repoInfo;
DIE_ON_ERROR(repoInfo.SetTo(infoPath), DIE_ON_ERROR(repoInfo.SetTo(infoPath),
"failed to read repository info file \"%s\"", infoPath); "failed to read repository info file \"%s\"", infoPath);
if (url == NULL)
url = repoInfo.OriginalBaseURL();
// init and write the config // init and write the config
BPackageKit::BRepositoryConfig repoConfig; BPackageKit::BRepositoryConfig repoConfig;
repoConfig.SetName(repoInfo.Name()); repoConfig.SetName(repoInfo.Name());