2 #include "parse-options.h"
5 static const char * const diagnose_usage
[] = {
6 N_("git diagnose [-o|--output-directory <path>] [-s|--suffix <format>] [--mode=<mode>]"),
10 int cmd_diagnose(int argc
, const char **argv
, const char *prefix
)
12 struct strbuf zip_path
= STRBUF_INIT
;
13 time_t now
= time(NULL
);
15 enum diagnose_mode mode
= DIAGNOSE_STATS
;
16 char *option_output
= NULL
;
17 char *option_suffix
= "%Y-%m-%d-%H%M";
18 char *prefixed_filename
;
20 const struct option diagnose_options
[] = {
21 OPT_STRING('o', "output-directory", &option_output
, N_("path"),
22 N_("specify a destination for the diagnostics archive")),
23 OPT_STRING('s', "suffix", &option_suffix
, N_("format"),
24 N_("specify a strftime format suffix for the filename")),
25 OPT_CALLBACK_F(0, "mode", &mode
, "(stats|all)",
26 N_("specify the content of the diagnostic archive"),
27 PARSE_OPT_NONEG
, option_parse_diagnose
),
31 argc
= parse_options(argc
, argv
, prefix
, diagnose_options
,
34 /* Prepare the path to put the result */
35 prefixed_filename
= prefix_filename(prefix
,
36 option_output
? option_output
: "");
37 strbuf_addstr(&zip_path
, prefixed_filename
);
38 strbuf_complete(&zip_path
, '/');
40 strbuf_addstr(&zip_path
, "git-diagnostics-");
41 strbuf_addftime(&zip_path
, option_suffix
, localtime_r(&now
, &tm
), 0, 0);
42 strbuf_addstr(&zip_path
, ".zip");
44 switch (safe_create_leading_directories(zip_path
.buf
)) {
49 die_errno(_("could not create leading directories for '%s'"),
53 /* Prepare diagnostics */
54 if (create_diagnostics_archive(&zip_path
, mode
))
55 die_errno(_("unable to create diagnostics archive %s"),
58 free(prefixed_filename
);
59 strbuf_release(&zip_path
);