From 1221b67d078802dc6af28b2559d61a8e4aeb4211 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Sun, 19 Jan 2014 00:37:44 +0100 Subject: [PATCH] create_repository_config: Make URL argument optional If not specified, the URL from the repository info is used. --- .../create_repository_config.cpp | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/tools/create_repository_config/create_repository_config.cpp b/src/tools/create_repository_config/create_repository_config.cpp index 86e78dcd7a..9837945b31 100644 --- a/src/tools/create_repository_config/create_repository_config.cpp +++ b/src/tools/create_repository_config/create_repository_config.cpp @@ -37,10 +37,11 @@ void print_usage_and_exit(bool error) { fprintf(error ? stderr : stdout, - "Usage: %s \n" - "Creates a repository config file from a given base URL (the\n" - "directory in which the \"repo\", \"repo.info\', and \"repo.sha256\n" - "files can be found.\n", + "Usage: %s [ ] \n" + "Creates a repository config file from a given repository info and\n" + "the base URL (the directory in which the \"repo\", \"repo.info\',\n" + "and \"repo.sha256 files can be found). If the URL is not specified,\n" + "the one from the repository info is used.", sProgramName); exit(error ? 1 : 0); } @@ -49,7 +50,7 @@ print_usage_and_exit(bool error) int main(int argc, const char* const* argv) { - if (argc != 4) { + if (argc < 3 || argc > 4) { if (argc == 2 && (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0)) { print_usage_and_exit(false); @@ -57,15 +58,19 @@ main(int argc, const char* const* argv) print_usage_and_exit(true); } - const char* url = argv[1]; - const char* infoPath = argv[2]; - const char* configPath = argv[3]; + int argi = 1; + const char* url = argc == 4 ? argv[argi++] : NULL; + const char* infoPath = argv[argi++]; + const char* configPath = argv[argi++]; // read the info BPackageKit::BRepositoryInfo repoInfo; DIE_ON_ERROR(repoInfo.SetTo(infoPath), "failed to read repository info file \"%s\"", infoPath); + if (url == NULL) + url = repoInfo.OriginalBaseURL(); + // init and write the config BPackageKit::BRepositoryConfig repoConfig; repoConfig.SetName(repoInfo.Name());