2 #include "parse-options.h"
3 #include "bundle-uri.h"
6 #include "string-list.h"
8 #include "ref-filter.h"
17 static int cmd__bundle_uri_parse(int argc
, const char **argv
, enum input_mode mode
)
19 const char *key_value_usage
[] = {
20 "test-tool bundle-uri parse-key-values <input>",
23 const char *config_usage
[] = {
24 "test-tool bundle-uri parse-config <input>",
27 const char **usage
= key_value_usage
;
28 struct option options
[] = {
31 struct strbuf sb
= STRBUF_INIT
;
32 struct bundle_list list
;
36 if (mode
== CONFIG_FILE
)
39 argc
= parse_options(argc
, argv
, NULL
, options
, usage
,
40 PARSE_OPT_STOP_AT_NON_OPTION
);
42 init_bundle_list(&list
);
44 list
.baseURI
= xstrdup("<uri>");
50 fp
= fopen(argv
[0], "r");
52 die("failed to open '%s'", argv
[0]);
53 while (strbuf_getline(&sb
, fp
) != EOF
) {
54 if (bundle_uri_parse_line(&list
, sb
.buf
))
55 err
= error("bad line: '%s'", sb
.buf
);
63 err
= bundle_uri_parse_config_format("<uri>", argv
[0], &list
);
68 print_bundle_list(stdout
, &list
);
70 clear_bundle_list(&list
);
75 usage_with_options(usage
, options
);
78 static int cmd_ls_remote(int argc
, const char **argv
)
81 struct remote
*remote
;
82 struct transport
*transport
;
85 dest
= argc
> 1 ? argv
[1] : NULL
;
87 remote
= remote_get(dest
);
90 die(_("bad repository '%s'"), dest
);
91 die(_("no remote configured to get bundle URIs from"));
94 die(_("remote '%s' has no configured URL"), dest
);
96 transport
= transport_get(remote
, NULL
);
97 if (transport_get_remote_bundle_uri(transport
) < 0) {
98 error(_("could not get the bundle-uri list"));
103 print_bundle_list(stdout
, transport
->bundles
);
106 if (transport_disconnect(transport
))
111 int cmd__bundle_uri(int argc
, const char **argv
)
113 const char *usage
[] = {
114 "test-tool bundle-uri <subcommand> [<options>]",
117 struct option options
[] = {
121 argc
= parse_options(argc
, argv
, NULL
, options
, usage
,
122 PARSE_OPT_STOP_AT_NON_OPTION
|
123 PARSE_OPT_KEEP_ARGV0
);
127 if (!strcmp(argv
[1], "parse-key-values"))
128 return cmd__bundle_uri_parse(argc
- 1, argv
+ 1, KEY_VALUE_PAIRS
);
129 if (!strcmp(argv
[1], "parse-config"))
130 return cmd__bundle_uri_parse(argc
- 1, argv
+ 1, CONFIG_FILE
);
131 if (!strcmp(argv
[1], "ls-remote"))
132 return cmd_ls_remote(argc
- 1, argv
+ 1);
133 error("there is no test-tool bundle-uri tool '%s'", argv
[1]);
136 usage_with_options(usage
, options
);