2 #include "parse-options.h"
3 #include "bundle-uri.h"
6 #include "string-list.h"
15 static int cmd__bundle_uri_parse(int argc
, const char **argv
, enum input_mode mode
)
17 const char *key_value_usage
[] = {
18 "test-tool bundle-uri parse-key-values <input>",
21 const char *config_usage
[] = {
22 "test-tool bundle-uri parse-config <input>",
25 const char **usage
= key_value_usage
;
26 struct option options
[] = {
29 struct strbuf sb
= STRBUF_INIT
;
30 struct bundle_list list
;
34 if (mode
== CONFIG_FILE
)
37 argc
= parse_options(argc
, argv
, NULL
, options
, usage
,
38 PARSE_OPT_STOP_AT_NON_OPTION
);
40 init_bundle_list(&list
);
42 list
.baseURI
= xstrdup("<uri>");
48 fp
= fopen(argv
[0], "r");
50 die("failed to open '%s'", argv
[0]);
51 while (strbuf_getline(&sb
, fp
) != EOF
) {
52 if (bundle_uri_parse_line(&list
, sb
.buf
))
53 err
= error("bad line: '%s'", sb
.buf
);
61 err
= bundle_uri_parse_config_format("<uri>", argv
[0], &list
);
66 print_bundle_list(stdout
, &list
);
68 clear_bundle_list(&list
);
73 usage_with_options(usage
, options
);
76 static int cmd_ls_remote(int argc
, const char **argv
)
79 struct remote
*remote
;
80 struct transport
*transport
;
83 dest
= argc
> 1 ? argv
[1] : NULL
;
85 remote
= remote_get(dest
);
88 die(_("bad repository '%s'"), dest
);
89 die(_("no remote configured to get bundle URIs from"));
92 transport
= transport_get(remote
, NULL
);
93 if (transport_get_remote_bundle_uri(transport
) < 0) {
94 error(_("could not get the bundle-uri list"));
99 print_bundle_list(stdout
, transport
->bundles
);
102 if (transport_disconnect(transport
))
107 int cmd__bundle_uri(int argc
, const char **argv
)
109 const char *usage
[] = {
110 "test-tool bundle-uri <subcommand> [<options>]",
113 struct option options
[] = {
117 argc
= parse_options(argc
, argv
, NULL
, options
, usage
,
118 PARSE_OPT_STOP_AT_NON_OPTION
|
119 PARSE_OPT_KEEP_ARGV0
);
123 if (!strcmp(argv
[1], "parse-key-values"))
124 return cmd__bundle_uri_parse(argc
- 1, argv
+ 1, KEY_VALUE_PAIRS
);
125 if (!strcmp(argv
[1], "parse-config"))
126 return cmd__bundle_uri_parse(argc
- 1, argv
+ 1, CONFIG_FILE
);
127 if (!strcmp(argv
[1], "ls-remote"))
128 return cmd_ls_remote(argc
- 1, argv
+ 1);
129 error("there is no test-tool bundle-uri tool '%s'", argv
[1]);
132 usage_with_options(usage
, options
);