| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
#include <aws/common/command_line_parser.h> |
| 7 |
|
| 8 |
#include "app_ctx.h" |
| 9 |
|
| 10 |
struct s3_compute_platform_ctx { |
| 11 |
struct app_ctx *app_ctx; |
| 12 |
struct aws_byte_cursor instance_type; |
| 13 |
}; |
| 14 |
|
| 15 |
static void s_usage(int exit_code) { |
| 16 |
FILE *output = exit_code == 0 ? stdout : stderr; |
| 17 |
fprintf(output, "usage: s3 platform-info [options]\n"); |
| 18 |
fprintf( |
| 19 |
output, |
| 20 |
" -instance-type, (optional) Instance type to look up configuration for, if not set it will be the current " |
| 21 |
"executing environment. \n"); |
| 22 |
fprintf(output, " -h, --help\n"); |
| 23 |
fprintf(output, " Display this message and quit.\n"); |
| 24 |
exit(exit_code); |
| 25 |
} |
| 26 |
|
| 27 |
static struct aws_cli_option s_long_options[] = { |
| 28 |
{"instance-type", AWS_CLI_OPTIONS_REQUIRED_ARGUMENT, NULL, 'i'}, |
| 29 |
|
| 30 |
{NULL, AWS_CLI_OPTIONS_NO_ARGUMENT, NULL, 0}, |
| 31 |
}; |
| 32 |
|
| 33 |
static void s_parse_options(int argc, char **argv, struct s3_compute_platform_ctx *ctx) { |
| 34 |
int option_index = 0; |
| 35 |
|
| 36 |
int opt_val = 0; |
| 37 |
do { |
| 38 |
opt_val = aws_cli_getopt_long(argc, argv, "i:", s_long_options, &option_index); |
| 39 |
|
| 40 |
if (opt_val == 'i') { |
| 41 |
ctx->instance_type = aws_byte_cursor_from_c_str(aws_cli_optarg); |
| 42 |
} |
| 43 |
} while (opt_val != -1); |
| 44 |
} |
| 45 |
|
| 46 |
int s3_compute_platform_info_main(int argc, char *argv[], const char *command_name, void *user_data) { |
| 47 |
(void)command_name; |
| 48 |
|
| 49 |
struct app_ctx *app_ctx = user_data; |
| 50 |
|
| 51 |
if (app_ctx->help_requested) { |
| 52 |
s_usage(0); |
| 53 |
} |
| 54 |
|
| 55 |
struct s3_compute_platform_ctx compute_platform_app_ctx = { |
| 56 |
.app_ctx = app_ctx, |
| 57 |
}; |
| 58 |
app_ctx->sub_command_data = &compute_platform_app_ctx; |
| 59 |
|
| 60 |
s_parse_options(argc, argv, &compute_platform_app_ctx); |
| 61 |
|
| 62 |
const struct aws_s3_platform_info *platform_info = aws_s3_get_current_platform_info(); |
| 63 |
|
| 64 |
printf("{\n"); |
| 65 |
printf("\t'instance_type': '" PRInSTR "',\n", AWS_BYTE_CURSOR_PRI(platform_info->instance_type)); |
| 66 |
printf("\t'max_throughput_gbps': %d,\n", (int)platform_info->max_throughput_gbps); |
| 67 |
printf("\t'has_recommended_configuration': %s,\n", platform_info->has_recommended_configuration ? "true" : "false"); |
| 68 |
return 0; |
| 69 |
} |