2 #include "parse-options.h"
3 #include "bundle-uri.h"
5 #include "string-list.h"
7 #include "ref-filter.h"
16 static int cmd__bundle_uri_parse(int argc
, const char **argv
, enum input_mode mode
)
18 const char *key_value_usage
[] = {
19 "test-tool bundle-uri parse-key-values <input>",
22 const char *config_usage
[] = {
23 "test-tool bundle-uri parse-config <input>",
26 const char **usage
= key_value_usage
;
27 struct option options
[] = {
30 struct strbuf sb
= STRBUF_INIT
;
31 struct bundle_list list
;
35 if (mode
== CONFIG_FILE
)
38 argc
= parse_options(argc
, argv
, NULL
, options
, usage
,
39 PARSE_OPT_STOP_AT_NON_OPTION
);
41 init_bundle_list(&list
);
43 list
.baseURI
= xstrdup("<uri>");
49 fp
= fopen(argv
[0], "r");
51 die("failed to open '%s'", argv
[0]);
52 while (strbuf_getline(&sb
, fp
) != EOF
) {
53 if (bundle_uri_parse_line(&list
, sb
.buf
))
54 err
= error("bad line: '%s'", sb
.buf
);
62 err
= bundle_uri_parse_config_format("<uri>", argv
[0], &list
);
67 print_bundle_list(stdout
, &list
);
69 clear_bundle_list(&list
);
74 usage_with_options(usage
, options
);
77 static int cmd_ls_remote(int argc
, const char **argv
)
80 struct remote
*remote
;
81 struct transport
*transport
;
84 dest
= argc
> 1 ? argv
[1] : NULL
;
86 remote
= remote_get(dest
);
89 die(_("bad repository '%s'"), dest
);
90 die(_("no remote configured to get bundle URIs from"));
93 die(_("remote '%s' has no configured URL"), dest
);
95 transport
= transport_get(remote
, NULL
);
96 if (transport_get_remote_bundle_uri(transport
) < 0) {
97 error(_("could not get the bundle-uri list"));
102 print_bundle_list(stdout
, transport
->bundles
);
105 if (transport_disconnect(transport
))
110 int cmd__bundle_uri(int argc
, const char **argv
)
112 const char *usage
[] = {
113 "test-tool bundle-uri <subcommand> [<options>]",
116 struct option options
[] = {
120 argc
= parse_options(argc
, argv
, NULL
, options
, usage
,
121 PARSE_OPT_STOP_AT_NON_OPTION
|
122 PARSE_OPT_KEEP_ARGV0
);
126 if (!strcmp(argv
[1], "parse-key-values"))
127 return cmd__bundle_uri_parse(argc
- 1, argv
+ 1, KEY_VALUE_PAIRS
);
128 if (!strcmp(argv
[1], "parse-config"))
129 return cmd__bundle_uri_parse(argc
- 1, argv
+ 1, CONFIG_FILE
);
130 if (!strcmp(argv
[1], "ls-remote"))
131 return cmd_ls_remote(argc
- 1, argv
+ 1);
132 error("there is no test-tool bundle-uri tool '%s'", argv
[1]);
135 usage_with_options(usage
, options
);