forked from BranchMetrics/xcode-github
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathXGCommandOptions.m
More file actions
131 lines (120 loc) · 4.86 KB
/
XGCommandOptions.m
File metadata and controls
131 lines (120 loc) · 4.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/**
@file XGCommandOptions.m
@package xcode-github
@brief Command options for the xcode-github app.
@author Edward Smith
@date March 7, 2018
@copyright Copyright © 2018 Branch. All rights reserved.
*/
#import "XGCommandOptions.h"
#include <getopt.h>
@implementation XGCommandOptions
- (instancetype _Nonnull) initWithArgc:(int)argc argv:(char*const _Nullable[_Nullable])argv {
self = [super init];
if (!self) return self;
static struct option long_options[] = {
{"dryrun", no_argument, NULL, 'd'},
{"github", required_argument, NULL, 'g'},
{"help", no_argument, NULL, 'h'},
{"password", required_argument, NULL, 'p'},
{"repeat", no_argument, NULL, 'r'},
{"status", no_argument, NULL, 's'},
{"template", required_argument, NULL, 't'},
{"user", required_argument, NULL, 'u'},
{"verbose", no_argument, NULL, 'v'},
{"version", no_argument, NULL, 'V'},
{"xcodeserver", required_argument, NULL, 'x'},
{"successmessage", no_argument, NULL, 'S'},
{"failuremessage", no_argument, NULL, 'F'},
{"perfectmessage", no_argument, NULL, 'P'},
{0, 0, 0, 0}
};
if (argc <= 1) {
self.showHelp = YES;
return self;
}
int c = 0;
do {
int option_index = 0;
c = getopt_long(argc, argv, "dg:hst:vVx:", long_options, &option_index);
switch (c) {
case -1: break;
case 'd': self.dryRun = YES; break;
case 'g': self.githubAuthToken = [self.class stringFromParameter]; break;
case 'h': self.showHelp = YES; break;
case 'p': self.xcodeServerPassword = [self.class stringFromParameter]; break;
case 'r': self.repeatForever = YES; break;
case 's': self.showStatusOnly = YES; break;
case 't': self.templateBotName = [self.class stringFromParameter]; break;
case 'u': self.xcodeServerUser = [self.class stringFromParameter]; break;
case 'v': self.verbosity++; break;
case 'V': self.showVersion = YES; break;
case 'x': self.xcodeServerName = [self.class stringFromParameter]; break;
case 'S': self.successMessage = [self.class stringFromParameter]; break;
case 'F': self.failureMessage = [self.class stringFromParameter]; break;
case 'P': self.perfectMessage = [self.class stringFromParameter]; break;
default: self.badOptionsError = YES; break;
}
} while (c != -1 && !self.badOptionsError);
return self;
}
+ (NSString*) stringFromParameter {
return [NSString stringWithCString:optarg encoding:NSUTF8StringEncoding];
}
+ (NSString*) helpString {
NSString *kHelpString =
@"xcode-github - Creates Xcode test bots for new GitHub PRs.\n"
"\n"
"usage: xcode-github [-dhsVv] -g <github-auth-token>\n"
" -t <bot-template> -x <xcode-server-domain-name>\n"
"\n"
"\n"
" -d, --dryrun\n"
" Dry run. Print what would be done.\n"
"\n"
" -g, --github <github-auth-token>\n"
" A GitHub auth token that allows checking the status of a repo\n"
" and change a PR's status.\n"
"\n"
" -h, --help\n"
" Print this help information.\n"
"\n"
" -p, --password <password>\n"
" Password for the Xcode server.\n"
"\n"
" -r, --repeat\n"
" Repeat updating the status forever, waiting 60 seconds between updates.\n"
"\n"
" -s, --status\n"
" Only print the status of the xcode server bots and quit.\n"
"\n"
" -t --template <bot-template>\n"
" An existing bot on the xcode server that is used as a template\n"
" for the new GitHub PR bots.\n"
"\n"
" -u, --user <user>\n"
" User for the Xcode server.\n"
"\n"
" -V, --version\n"
" Show version and exit.\n"
"\n"
" -v, --verbose\n"
" Verbose. Extra 'v' increases the verbosity.\n"
"\n"
" -x, --xcodeserver <xcode-server-domain-name>\n"
" The network name of the xcode server.\n"
" -S, --successmessage <custom-message>\n"
" Optional custom integration success message.\n"
"\n"
" -F, --failuremessage <custom-message>\n"
" Optional custom integration failure message.\n"
"\n"
" -P, --perfectmessage <custom-message>\n"
" Optional custom perfect integration message.\n"
"\n"
"The tool returns 0 on success, otherwise a non-zero value.\n"
"\n"
;
return kHelpString;
}
@end