7
7
#include "utf8.h"
8
8
#include "strbuf.h"
9
9
#include "mailinfo.h"
10
+ #include "parse-options.h"
10
11
11
- static const char mailinfo_usage [] =
12
- "git mailinfo [-k | -b] [-m | --message-id] [-u | --encoding=<encoding> | -n] [--scissors | --no-scissors] <msg> <patch> < mail >info" ;
12
+ static const char * const mailinfo_usage [] = {
13
+ /* TRANSLATORS: keep <> in "<" mail ">" info. */
14
+ N_ ("git mailinfo [<options>] <msg> <patch> < mail >info" ),
15
+ NULL ,
16
+ };
13
17
14
18
struct metainfo_charset
15
19
{
@@ -21,43 +25,54 @@ struct metainfo_charset
21
25
const char * charset ;
22
26
};
23
27
28
+ static int parse_opt_explicit_encoding (const struct option * opt ,
29
+ const char * arg , int unset )
30
+ {
31
+ struct metainfo_charset * meta_charset = opt -> value ;
32
+
33
+ BUG_ON_OPT_NEG (unset );
34
+
35
+ meta_charset -> policy = CHARSET_EXPLICIT ;
36
+ meta_charset -> charset = arg ;
37
+
38
+ return 0 ;
39
+ }
40
+
24
41
int cmd_mailinfo (int argc , const char * * argv , const char * prefix )
25
42
{
26
43
struct metainfo_charset meta_charset ;
27
44
struct mailinfo mi ;
28
45
int status ;
29
46
char * msgfile , * patchfile ;
30
47
48
+ struct option options [] = {
49
+ OPT_BOOL ('k' , NULL , & mi .keep_subject , N_ ("keep subject" )),
50
+ OPT_BOOL ('b' , NULL , & mi .keep_non_patch_brackets_in_subject ,
51
+ N_ ("keep non patch brackets in subject" )),
52
+ OPT_BOOL ('m' , "message-id" , & mi .add_message_id ,
53
+ N_ ("copy Message-ID to the end of commit message" )),
54
+ OPT_SET_INT_F ('u' , NULL , & meta_charset .policy ,
55
+ N_ ("re-code metadata to i18n.commitEncoding" ),
56
+ CHARSET_DEFAULT , PARSE_OPT_NONEG ),
57
+ OPT_SET_INT_F ('n' , NULL , & meta_charset .policy ,
58
+ N_ ("disable charset re-coding of metadata" ),
59
+ CHARSET_NO_REENCODE , PARSE_OPT_NONEG ),
60
+ OPT_CALLBACK_F (0 , "encoding" , & meta_charset , N_ ("encoding" ),
61
+ N_ ("re-code metadata to this encoding" ),
62
+ PARSE_OPT_NONEG , parse_opt_explicit_encoding ),
63
+ OPT_BOOL (0 , "scissors" , & mi .use_scissors , N_ ("use scissors" )),
64
+ OPT_HIDDEN_BOOL (0 , "inbody-headers" , & mi .use_inbody_headers ,
65
+ N_ ("use headers in message's body" )),
66
+ OPT_END ()
67
+ };
68
+
31
69
setup_mailinfo (& mi );
32
70
meta_charset .policy = CHARSET_DEFAULT ;
33
71
34
- while (1 < argc && argv [1 ][0 ] == '-' ) {
35
- if (!strcmp (argv [1 ], "-k" ))
36
- mi .keep_subject = 1 ;
37
- else if (!strcmp (argv [1 ], "-b" ))
38
- mi .keep_non_patch_brackets_in_subject = 1 ;
39
- else if (!strcmp (argv [1 ], "-m" ) || !strcmp (argv [1 ], "--message-id" ))
40
- mi .add_message_id = 1 ;
41
- else if (!strcmp (argv [1 ], "-u" ))
42
- meta_charset .policy = CHARSET_DEFAULT ;
43
- else if (!strcmp (argv [1 ], "-n" ))
44
- meta_charset .policy = CHARSET_NO_REENCODE ;
45
- else if (starts_with (argv [1 ], "--encoding=" )) {
46
- meta_charset .policy = CHARSET_EXPLICIT ;
47
- meta_charset .charset = argv [1 ] + 11 ;
48
- } else if (!strcmp (argv [1 ], "--scissors" ))
49
- mi .use_scissors = 1 ;
50
- else if (!strcmp (argv [1 ], "--no-scissors" ))
51
- mi .use_scissors = 0 ;
52
- else if (!strcmp (argv [1 ], "--no-inbody-headers" ))
53
- mi .use_inbody_headers = 0 ;
54
- else
55
- usage (mailinfo_usage );
56
- argc -- ; argv ++ ;
57
- }
72
+ argc = parse_options (argc , argv , prefix , options , mailinfo_usage , 0 );
58
73
59
- if (argc != 3 )
60
- usage (mailinfo_usage );
74
+ if (argc != 2 )
75
+ usage_with_options (mailinfo_usage , options );
61
76
62
77
switch (meta_charset .policy ) {
63
78
case CHARSET_DEFAULT :
@@ -75,8 +90,8 @@ int cmd_mailinfo(int argc, const char **argv, const char *prefix)
75
90
mi .input = stdin ;
76
91
mi .output = stdout ;
77
92
78
- msgfile = prefix_filename (prefix , argv [1 ]);
79
- patchfile = prefix_filename (prefix , argv [2 ]);
93
+ msgfile = prefix_filename (prefix , argv [0 ]);
94
+ patchfile = prefix_filename (prefix , argv [1 ]);
80
95
81
96
status = !!mailinfo (& mi , msgfile , patchfile );
82
97
clear_mailinfo (& mi );
0 commit comments