|
15 | 15 | * Gets the list of builds and information about each build based on command line input
|
16 | 16 | */
|
17 | 17 |
|
18 |
| -int main(int argc, char **argv) |
19 |
| -{ |
20 |
| - if (argc != 2) |
21 |
| - { |
22 |
| - std::cout << "Usage: list_builds <sort_order_type>"; |
23 |
| - return 1; |
24 |
| - } |
25 |
| - Aws::SDKOptions options; |
26 |
| - Aws::InitAPI(options); |
27 |
| - { |
28 |
| - Aws::CodeBuild::CodeBuildClient codebuild; |
29 |
| - |
30 |
| - Aws::CodeBuild::Model::ListBuildsRequest lb_req; |
31 |
| - Aws::CodeBuild::Model::BatchGetBuildsRequest bgb_req; |
32 |
| - |
33 |
| - if (Aws::Utils::StringUtils::CaselessCompare(argv[1], "ASCENDING")) |
34 |
| - { |
35 |
| - lb_req.SetSortOrder(Aws::CodeBuild::Model::SortOrderType::ASCENDING); |
36 |
| - } |
37 |
| - else if(Aws::Utils::StringUtils::CaselessCompare(argv[1], "DESCENDING")) |
38 |
| - { |
39 |
| - lb_req.SetSortOrder(Aws::CodeBuild::Model::SortOrderType::DESCENDING); |
| 18 | +int main(int argc, char **argv) { |
| 19 | + if (argc != 2) { |
| 20 | + std::cout << "Usage: list_builds <sort_order_type>"; |
| 21 | + return 1; |
40 | 22 | }
|
41 |
| - else |
| 23 | + Aws::SDKOptions options; |
| 24 | + Aws::InitAPI(options); |
42 | 25 | {
|
43 |
| - lb_req.SetSortOrder(Aws::CodeBuild::Model::SortOrderType::NOT_SET); |
44 |
| - } |
| 26 | + Aws::CodeBuild::CodeBuildClient codebuild; |
45 | 27 |
|
46 |
| - auto lb_out = codebuild.ListBuilds(lb_req); |
| 28 | + Aws::CodeBuild::Model::ListBuildsRequest lb_req; |
| 29 | + Aws::CodeBuild::Model::BatchGetBuildsRequest bgb_req; |
47 | 30 |
|
48 |
| - if (lb_out.IsSuccess()) |
49 |
| - { |
50 |
| - std::cout << "Information about each build:" << std::endl; |
51 |
| - bgb_req.SetIds(lb_out.GetResult().GetIds()); |
52 |
| - auto bgb_out = codebuild.BatchGetBuilds(bgb_req); |
53 |
| - |
54 |
| - if (bgb_out.IsSuccess()) |
55 |
| - { |
56 |
| - for (auto val: bgb_out.GetResult().GetBuilds()) |
57 |
| - { |
58 |
| - std::cout << val.GetId() << std::endl; |
| 31 | + if (Aws::Utils::StringUtils::CaselessCompare(argv[1], "ASCENDING")) { |
| 32 | + lb_req.SetSortOrder(Aws::CodeBuild::Model::SortOrderType::ASCENDING); |
| 33 | + } |
| 34 | + else if (Aws::Utils::StringUtils::CaselessCompare(argv[1], "DESCENDING")) { |
| 35 | + lb_req.SetSortOrder(Aws::CodeBuild::Model::SortOrderType::DESCENDING); |
| 36 | + } |
| 37 | + else { |
| 38 | + lb_req.SetSortOrder(Aws::CodeBuild::Model::SortOrderType::NOT_SET); |
59 | 39 | }
|
60 |
| - } |
61 |
| - } |
62 | 40 |
|
63 |
| - else |
64 |
| - { |
65 |
| - std::cout << "Error listing builds" << lb_out.GetError().GetMessage() |
66 |
| - << std::endl; |
| 41 | + Aws::String next_token; // Used for pagination. |
| 42 | + |
| 43 | + do { |
| 44 | + if (!next_token.empty()) { |
| 45 | + lb_req.SetNextToken(next_token); |
| 46 | + } |
| 47 | + |
| 48 | + auto lb_out = codebuild.ListBuilds(lb_req); |
| 49 | + |
| 50 | + if (lb_out.IsSuccess()) { |
| 51 | + std::cout << "Information about each build:" << std::endl; |
| 52 | + bgb_req.SetIds(lb_out.GetResult().GetIds()); |
| 53 | + auto bgb_out = codebuild.BatchGetBuilds(bgb_req); |
| 54 | + |
| 55 | + if (bgb_out.IsSuccess()) { |
| 56 | + const auto &builds = bgb_out.GetResult().GetBuilds(); |
| 57 | + std::cout << builds.size() << " build(s) found." << std::endl; |
| 58 | + for (auto val: builds) { |
| 59 | + std::cout << val.GetId() << std::endl; |
| 60 | + } |
| 61 | + } |
| 62 | + |
| 63 | + next_token = lb_out.GetResult().GetNextToken(); |
| 64 | + } |
| 65 | + |
| 66 | + else { |
| 67 | + std::cout << "Error listing builds" << lb_out.GetError().GetMessage() |
| 68 | + << std::endl; |
| 69 | + break; |
| 70 | + } |
| 71 | + |
| 72 | + } while (!next_token.empty()); |
| 73 | + |
67 | 74 | }
|
68 |
| - } |
69 | 75 |
|
70 |
| - Aws::ShutdownAPI(options); |
71 |
| - return 0; |
| 76 | + |
| 77 | + Aws::ShutdownAPI(options); |
| 78 | + return 0; |
72 | 79 | }
|
0 commit comments