1/*
2 * Copyright 2011, Oliver Tappe <zooey@hirschkaefer.de>
3 * Distributed under the terms of the MIT License.
4 */
5
6
7#include "pkgman.h"
8
9#include <errno.h>
10#include <stdio.h>
11#include <stdlib.h>
12#include <string.h>
13
14
15extern const char* __progname;
16const char* kProgramName = __progname;
17
18
19static const char* kUsage =
20	"Usage: %s <command> <command args>\n"
21	"Creates, inspects, or extracts a Haiku package.\n"
22	"\n"
23	"Commands:\n"
24	"  add-repo <repo-base-url>\n"
25	"    Adds the repository with the given <repo-base-URL>.\n"
26	"\n"
27	"  drop-repo <repo-name>\n"
28	"    Drops the repository with the given <repo-name>.\n"
29	"\n"
30	"  list-repos\n"
31	"    Lists all repositories.\n"
32	"\n"
33	"  refresh [<repo-name> ...]\n"
34	"    Refreshes all or just the given repositories.\n"
35	"\n"
36	"Common Options:\n"
37	"  -h, --help   - Print this usage info.\n"
38;
39
40
41void
42print_usage_and_exit(bool error)
43{
44    fprintf(error ? stderr : stdout, kUsage, kProgramName);
45    exit(error ? 1 : 0);
46}
47
48
49int
50main(int argc, const char* const* argv)
51{
52	if (argc < 2)
53		print_usage_and_exit(true);
54
55	const char* command = argv[1];
56	if (strncmp(command, "add-r", 5) == 0)
57		return command_add_repo(argc - 1, argv + 1);
58
59	if (strncmp(command, "drop-r", 6) == 0)
60		return command_drop_repo(argc - 1, argv + 1);
61
62	if (strncmp(command, "list-r", 6) == 0)
63		return command_list_repos(argc - 1, argv + 1);
64
65	if (strncmp(command, "refr", 4) == 0)
66		return command_refresh(argc - 1, argv + 1);
67
68//	if (strcmp(command, "search") == 0)
69//		return command_search(argc - 1, argv + 1);
70
71	if (strcmp(command, "help") == 0)
72		print_usage_and_exit(false);
73	else
74		print_usage_and_exit(true);
75
76	// never gets here
77	return 0;
78}
79