Skip to content

Commit 1fdf2e6

Browse files
Added cd scripts, added version option to elasticurl. (#53)
1 parent eabccf6 commit 1fdf2e6

File tree

5 files changed

+173
-12
lines changed

5 files changed

+173
-12
lines changed

bin/elasticurl/main.c

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
# pragma warning(disable : 4221) /* Local var in declared initializer */
3737
#endif
3838

39+
#define ELASTICURL_VERSION "0.2.0"
40+
3941
struct elasticurl_ctx {
4042
struct aws_allocator *allocator;
4143
const char *verb;
@@ -60,7 +62,7 @@ struct elasticurl_ctx {
6062
bool exchange_completed;
6163
};
6264

63-
static void s_usage(void) {
65+
static void s_usage(int exit_code) {
6466

6567
fprintf(stderr, "usage: elasticurl [options] url\n");
6668
fprintf(stderr, " url: url to make a request to. The default is a GET request.\n");
@@ -81,10 +83,11 @@ static void s_usage(void) {
8183
fprintf(stderr, " -k, --insecure: turns off SSL/TLS validation.\n");
8284
fprintf(stderr, " -o, --output FILE: dumps content-body to FILE instead of stdout.\n");
8385
fprintf(stderr, " -t, --trace FILE: dumps logs to FILE instead of stderr.\n");
84-
fprintf(stderr, " -v, --verbose ERROR|INFO|DEBUG|TRACE: log level to configure. Default is none.\n");
86+
fprintf(stderr, " -v, --verbose: ERROR|INFO|DEBUG|TRACE: log level to configure. Default is none.\n");
87+
fprintf(stderr, " --version: print the version of elasticurl.\n");
8588
fprintf(stderr, " -h, --help\n");
8689
fprintf(stderr, " Display this message and quit.\n");
87-
exit(1);
90+
exit(exit_code);
8891
}
8992

9093
static struct aws_cli_option s_long_options[] = {
@@ -105,6 +108,7 @@ static struct aws_cli_option s_long_options[] = {
105108
{"output", AWS_CLI_OPTIONS_REQUIRED_ARGUMENT, NULL, 'o'},
106109
{"trace", AWS_CLI_OPTIONS_REQUIRED_ARGUMENT, NULL, 't'},
107110
{"verbose", AWS_CLI_OPTIONS_REQUIRED_ARGUMENT, NULL, 'v'},
111+
{"version", AWS_CLI_OPTIONS_NO_ARGUMENT, NULL, 'V'},
108112
{"help", AWS_CLI_OPTIONS_NO_ARGUMENT, NULL, 'h'},
109113
/* Per getopt(3) the last element of the array has to be filled with all zeros */
110114
{NULL, AWS_CLI_OPTIONS_NO_ARGUMENT, NULL, 0},
@@ -113,7 +117,7 @@ static struct aws_cli_option s_long_options[] = {
113117
static void s_parse_options(int argc, char **argv, struct elasticurl_ctx *ctx) {
114118
while (true) {
115119
int option_index = 0;
116-
int c = aws_cli_getopt_long(argc, argv, "a:b:c:e:f:H:d:g:M:GPHiko:t:v:h", s_long_options, &option_index);
120+
int c = aws_cli_getopt_long(argc, argv, "a:b:c:e:f:H:d:g:M:GPHiko:t:v:Vh", s_long_options, &option_index);
117121
if (c == -1) {
118122
break;
119123
}
@@ -140,7 +144,7 @@ static void s_parse_options(int argc, char **argv, struct elasticurl_ctx *ctx) {
140144
case 'H':
141145
if (ctx->header_line_count >= sizeof(ctx->header_lines) / sizeof(const char *)) {
142146
fprintf(stderr, "currently only 10 header lines are supported.\n");
143-
s_usage();
147+
s_usage(1);
144148
}
145149
ctx->header_lines[ctx->header_line_count++] = aws_cli_optarg;
146150
break;
@@ -152,7 +156,7 @@ static void s_parse_options(int argc, char **argv, struct elasticurl_ctx *ctx) {
152156
ctx->data_file = fopen(aws_cli_optarg, "rb");
153157
if (!ctx->data_file) {
154158
fprintf(stderr, "unable to open file %s.\n", aws_cli_optarg);
155-
s_usage();
159+
s_usage(1);
156160
}
157161
break;
158162
case 'M':
@@ -178,7 +182,7 @@ static void s_parse_options(int argc, char **argv, struct elasticurl_ctx *ctx) {
178182

179183
if (!ctx->output) {
180184
fprintf(stderr, "unable to open file %s.\n", aws_cli_optarg);
181-
s_usage();
185+
s_usage(1);
182186
}
183187
break;
184188
case 't':
@@ -195,15 +199,18 @@ static void s_parse_options(int argc, char **argv, struct elasticurl_ctx *ctx) {
195199
ctx->log_level = AWS_LL_ERROR;
196200
} else {
197201
fprintf(stderr, "unsupported log level %s.\n", aws_cli_optarg);
198-
s_usage();
202+
s_usage(1);
199203
}
200204
break;
205+
case 'V':
206+
fprintf(stderr, "elasticurl %s\n", ELASTICURL_VERSION);
207+
exit(0);
201208
case 'h':
202-
s_usage();
209+
s_usage(0);
203210
break;
204211
default:
205212
fprintf(stderr, "Unknown option\n");
206-
s_usage();
213+
s_usage(1);
207214
}
208215
}
209216

@@ -216,11 +223,11 @@ static void s_parse_options(int argc, char **argv, struct elasticurl_ctx *ctx) {
216223
"Failed to parse uri %s with error %s\n",
217224
(char *)uri_cursor.ptr,
218225
aws_error_debug_str(aws_last_error()));
219-
s_usage();
226+
s_usage(1);
220227
};
221228
} else {
222229
fprintf(stderr, "A URI for the request must be supplied.\n");
223-
s_usage();
230+
s_usage(1);
224231
}
225232
}
226233

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
version: 0.2
2+
#this build spec assumes the manylinux1 image for pypi
3+
#additional packages we installed: cmake 3.5, libcrypto 1.1.0j, gcc 4.8.4
4+
phases:
5+
install:
6+
commands:
7+
pre_build:
8+
commands:
9+
- export CC=gcc
10+
build:
11+
commands:
12+
- echo Build started on `date`
13+
- mkdir /tmp/install
14+
- mkdir /tmp/aws-c-common-build
15+
- mkdir /tmp/aws-c-compression-build
16+
- mkdir /tmp/aws-c-io-build
17+
- mkdir /tmp/aws-c-http-build
18+
- mkdir /tmp/s2n-build
19+
- cd /tmp/aws-c-common-build
20+
- cmake -DCMAKE_INSTALL_PREFIX=/tmp/install -DBUILD_TESTING=OFF $CODEBUILD_SRC_DIR_aws-c-common
21+
- make -j
22+
- make install
23+
- cd /tmp/aws-c-compression-build
24+
- cmake -DCMAKE_PREFIX_PATH=/tmp/install -DCMAKE_INSTALL_PREFIX=/tmp/install -DBUILD_TESTING=OFF $CODEBUILD_SRC_DIR_aws-c-compression
25+
- make -j
26+
- make install
27+
- cd /tmp/s2n-build
28+
- cmake -DCMAKE_PREFIX_PATH=/opt/openssl;/tmp/install -DCMAKE_INSTALL_PREFIX=/tmp/install -DBUILD_TESTING=OFF $CODEBUILD_SRC_DIR_s2n
29+
- make -j
30+
- make install
31+
- cd /tmp/aws-c-io-build
32+
- cmake -DCMAKE_PREFIX_PATH=/opt/openssl;/tmp/install -DCMAKE_INSTALL_PREFIX=/tmp/install -DBUILD_TESTING=OFF $CODEBUILD_SRC_DIR_aws-c-io
33+
- make -j
34+
- make install
35+
- cd /tmp/aws-c-http-build
36+
- cmake -DCMAKE_PREFIX_PATH=/opt/openssl;/tmp/install -DCMAKE_INSTALL_PREFIX=/tmp/install -DBUILD_TESTING=OFF $CODEBUILD_SRC_DIR_aws-c-http
37+
- make -j
38+
- make install
39+
- /tmp/install/bin/elasticurl --version
40+
- /tmp/install/bin/elasticurl -v TRACE https://example.com
41+
post_build:
42+
commands:
43+
- echo Build completed on `date`
44+
45+
artifacts:
46+
files:
47+
- '/tmp/install/bin/elasticurl'
48+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
#before running this, you'll need cmake3 and a compiler.
3+
set -e
4+
export MACOSX_DEPLOYMENT_TARGET="10.9"
5+
mkdir install
6+
mkdir aws-c-common-build
7+
mkdir aws-c-io-build
8+
mkdir aws-c-compression-build
9+
mkdir aws-c-http-build
10+
cd aws-c-common-build
11+
cmake -DCMAKE_INSTALL_PREFIX=`pwd`/../install -DBUILD_TESTING=OFF ../aws-c-common
12+
make -j
13+
make install
14+
cd ..
15+
cd aws-c-compression-build
16+
cmake -DCMAKE_PREFIX_PATH=`pwd`/../install -DCMAKE_INSTALL_PREFIX=`pwd`/../install -DBUILD_TESTING=OFF ../aws-c-compression
17+
make -j
18+
make install
19+
cd ..
20+
cd aws-c-io-build
21+
cmake -DCMAKE_PREFIX_PATH=`pwd`/../install -DCMAKE_INSTALL_PREFIX=`pwd`/../install -DBUILD_TESTING=OFF ../aws-c-io
22+
make -j
23+
make install
24+
cd ..
25+
cd aws-c-http-build
26+
cmake -DCMAKE_PREFIX_PATH=`pwd`/../install -DCMAKE_INSTALL_PREFIX=`pwd`/../install -DBUILD_TESTING=OFF ../aws-c-http
27+
make -j
28+
make install
29+
cd ..
30+
31+
install/bin/elasticurl --version
32+
install/bin/elasticurl -v TRACE https://example.com
33+
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/bash
2+
#before running this, you'll need cmake3 and a compiler.
3+
set -e
4+
mkdir install
5+
mkdir aws-c-common-build
6+
mkdir aws-c-compression-build
7+
mkdir aws-c-io-build
8+
mkdir aws-c-http-build
9+
mkdir s2n-build
10+
cd aws-c-common-build
11+
cmake -DCMAKE_INSTALL_PREFIX=`pwd`/../install -DBUILD_TESTING=OFF ../aws-c-common
12+
make -j
13+
make install
14+
cd ..
15+
cd aws-c-compression-build
16+
cmake -DCMAKE_PREFIX_PATH=`pwd`/../install -DCMAKE_INSTALL_PREFIX=`pwd`/../install -DBUILD_TESTING=OFF ../aws-c-compression
17+
make -j
18+
make install
19+
cd ..
20+
cd s2n-build
21+
cmake -DCMAKE_PREFIX_PATH=`pwd`/../install -DCMAKE_INSTALL_PREFIX=`pwd`/../install -DBUILD_TESTING=OFF ../s2n
22+
make -j
23+
make install
24+
cd ..
25+
cd aws-c-io-build
26+
cmake -DCMAKE_PREFIX_PATH=`pwd`/../install -DCMAKE_INSTALL_PREFIX=`pwd`/../install -DBUILD_TESTING=OFF ../aws-c-io
27+
make -j
28+
make install
29+
cd ..
30+
cd aws-c-http-build
31+
cmake -DCMAKE_PREFIX_PATH=`pwd`/../install -DCMAKE_INSTALL_PREFIX=`pwd`/../install -DBUILD_TESTING=OFF ../aws-c-http
32+
make -j
33+
make install
34+
cd ..
35+
36+
install/bin/elasticurl --version
37+
install/bin/elasticurl -v TRACE https://example.com
38+
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
mkdir install
3+
cd install
4+
set INSTALL_DIR %cd%
5+
cd ..
6+
mkdir aws-c-common-build
7+
mkdir aws-c-compression-build
8+
mkdir aws-c-io-build
9+
mkdir aws-c-http-build
10+
cd aws-c-common-build
11+
cmake -DCMAKE_INSTALL_PREFIX=%INSTALL_DIR% -DBUILD_TESTING=OFF ..\aws-c-common || goto error
12+
cmake --build .\ --target install --config RelWithDebInfo || goto error
13+
cd ..
14+
cd aws-c-compression-build
15+
cmake -DCMAKE_PREFIX_PATH=%INSTALL_DIR% -DCMAKE_INSTALL_PREFIX=%INSTALL_DIR% -DBUILD_TESTING=OFF ..\aws-c-compression || goto error
16+
cmake --build .\ --target install --config RelWithDebInfo || goto error
17+
cd ..
18+
cd aws-c-io-build
19+
cmake -DCMAKE_PREFIX_PATH=%INSTALL_DIR% -DCMAKE_INSTALL_PREFIX=%INSTALL_DIR% -DBUILD_TESTING=OFF ..\aws-c-io || goto error
20+
cmake --build .\ --target install --config RelWithDebInfo || goto error
21+
cd ..
22+
cd aws-c-http-build
23+
cmake -DCMAKE_PREFIX_PATH=%INSTALL_DIR% -DCMAKE_INSTALL_PREFIX=%INSTALL_DIR% -DBUILD_TESTING=OFF ..\aws-c-http || goto error
24+
cmake --build .\ --target install --config RelWithDebInfo || goto error
25+
cd ..
26+
27+
%INSTALL_DIR%\bin\elasticurl --version || goto error
28+
%INSTALL_DIR%\bin\elasticurl -v TRACE https://example.com || goto error
29+
30+
goto :EOF
31+
32+
:error
33+
echo Failed with error #%errorlevel%.
34+
exit /b %errorlevel%
35+

0 commit comments

Comments
 (0)