From abfbdb317a86dfcf75a07b0b987b47e6ca9c2578 Mon Sep 17 00:00:00 2001 From: pooneh-m <46979170+pooneh-m@users.noreply.github.com> Date: Thu, 16 Jul 2020 09:23:07 -0700 Subject: [PATCH] docs(samples): fix sample formatting issues (#94) --- game-servers/snippets/create_cluster.js | 31 +++++++++++++--------- game-servers/snippets/create_realm.js | 25 +++++++++++------- game-servers/snippets/delete_cluster.js | 34 +++++++++++++++++-------- game-servers/snippets/delete_realm.js | 28 ++++++++++++-------- game-servers/snippets/get_cluster.js | 34 +++++++++++++++++-------- game-servers/snippets/get_realm.js | 27 ++++++++++++-------- game-servers/snippets/list_clusters.js | 27 ++++++++++++-------- game-servers/snippets/list_realms.js | 23 +++++++++++------ 8 files changed, 147 insertions(+), 82 deletions(-) diff --git a/game-servers/snippets/create_cluster.js b/game-servers/snippets/create_cluster.js index 57f19fc1ff..120e5f83b7 100644 --- a/game-servers/snippets/create_cluster.js +++ b/game-servers/snippets/create_cluster.js @@ -22,7 +22,7 @@ * @param {string} gkeClusterId the GKE cluster to connect to * @param {string} gkeLocation the location of the GKE cluster */ -function main( +async function main( projectId = 'YOUR_PROJECT_ID', location = 'LOCATION_ID', realmId = 'REALM_ID', @@ -30,14 +30,6 @@ function main( gkeClusterName = 'GKE_CLUSTER_NAME' ) { // [START cloud_game_servers_create_cluster] - /** - * TODO(developer): Uncomment these variables before running the sample. - */ - // const projectId = 'Your Google Cloud Project ID'; - // const location = 'A Compute Engine region, e.g. "us-central1"'; - // const realmId = 'The ID of the realm to locate this cluster in'; - // const gameClusterId = 'A unique ID for this Game Server Cluster'; - // const gkeClusterName= 'The full resource name of the GKE cluster to use'; const { GameServerClustersServiceClient, } = require('@google-cloud/game-servers'); @@ -45,9 +37,17 @@ function main( const client = new GameServerClustersServiceClient(); async function createGameServerCluster() { + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + // const projectId = 'Your Google Cloud Project ID'; + // const location = 'A Compute Engine region, e.g. "us-central1"'; + // const realmId = 'The ID of the realm to locate this cluster in'; + // const gameClusterId = 'A unique ID for this Game Server Cluster'; + // const gkeClusterName= 'The full resource name of the GKE cluster to use'; const request = { // Provide full resource name of a Game Server Realm - parent: `projects/${projectId}/locations/${location}/realms/${realmId}`, + parent: client.realmPath(projectId, location, realmId), gameServerClusterId: gameClusterId, gameServerCluster: { description: 'My Game Server Cluster', @@ -70,10 +70,17 @@ function main( console.log( `\tGKE cluster: ${result.connectionInfo.gkeClusterReference.cluster}` ); - // [END cloud_game_servers_create_cluster] } createGameServerCluster(); + // [END cloud_game_servers_create_cluster] } -main(...process.argv.slice(2)); +main(...process.argv.slice(2)).catch(err => { + console.error(err.message); + process.exitCode = 1; +}); +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); diff --git a/game-servers/snippets/create_realm.js b/game-servers/snippets/create_realm.js index 8ce712035f..517b440313 100644 --- a/game-servers/snippets/create_realm.js +++ b/game-servers/snippets/create_realm.js @@ -19,23 +19,23 @@ * @param {string} location Compute Engine region. * @param {string} realmId a unique identifier for the new realm */ -function main( +async function main( projectId = 'YOUR_PROJECT_ID', location = 'LOCATION_ID', realmId = 'REALM_ID' ) { // [START cloud_game_servers_create_realm] - /** - * TODO(developer): Uncomment these variables before running the sample. - */ - // const projectId = 'Your Google Cloud Project ID'; - // const location = 'A Compute Engine region, e.g. "us-central1"'; - // const realmId = 'A unique identifier for the realm'; const {RealmsServiceClient} = require('@google-cloud/game-servers'); const client = new RealmsServiceClient(); async function createRealm() { + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + // const projectId = 'Your Google Cloud Project ID'; + // const location = 'A Compute Engine region, e.g. "us-central1"'; + // const realmId = 'A unique identifier for the realm'; const request = { parent: `projects/${projectId}/locations/${location}`, realmId: realmId, @@ -56,10 +56,17 @@ function main( console.log(`\tRealm name: ${realm.name}`); console.log(`\tRealm description: ${realm.description}`); console.log(`\tRealm time zone: ${realm.timeZone}`); - // [END cloud_game_servers_create_realm] } createRealm(); + // [END cloud_game_servers_create_realm] } -main(...process.argv.slice(2)); +main(...process.argv.slice(2)).catch(err => { + console.error(err.message); + process.exitCode = 1; +}); +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); diff --git a/game-servers/snippets/delete_cluster.js b/game-servers/snippets/delete_cluster.js index 8ef0e09fea..4b4c4d4778 100644 --- a/game-servers/snippets/delete_cluster.js +++ b/game-servers/snippets/delete_cluster.js @@ -20,20 +20,13 @@ * @param {string} realmId the realm to use * @param {string} gameClusterId the game cluster to delete */ -function main( +async function main( projectId = 'YOUR_PROJECT_ID', location = 'LOCATION_ID', realmId = 'REALM_ID', gameClusterId = 'GAME_CLUSTER_ID' ) { // [START cloud_game_servers_delete_cluster] - /** - * TODO(developer): Uncomment these variables before running the sample. - */ - // const projectId = 'Your Google Cloud Project ID'; - // const location = 'A Compute Engine region, e.g. "us-central1"'; - // const realmId = 'The ID of the realm to locate this cluster in'; - // const gameClusterId = 'The unique ID for this Game Server Cluster'; const { GameServerClustersServiceClient, } = require('@google-cloud/game-servers'); @@ -41,18 +34,37 @@ function main( const client = new GameServerClustersServiceClient(); async function deleteGameServerCluster() { + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + // const projectId = 'Your Google Cloud Project ID'; + // const location = 'A Compute Engine region, e.g. "us-central1"'; + // const realmId = 'The ID of the realm to locate this cluster in'; + // const gameClusterId = 'The unique ID for this Game Server Cluster'; const request = { // Provide full resource name of a Game Server Realm - name: `projects/${projectId}/locations/${location}/realms/${realmId}/gameServerClusters/${gameClusterId}`, + name: client.gameServerClusterPath( + projectId, + location, + realmId, + gameClusterId + ), }; await client.deleteGameServerCluster(request); console.log('Game Server cluster deleted'); - // [END cloud_game_servers_delete_cluster] } deleteGameServerCluster(); + // [END cloud_game_servers_delete_cluster] } -main(...process.argv.slice(2)); +main(...process.argv.slice(2)).catch(err => { + console.error(err.message); + process.exitCode = 1; +}); +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); diff --git a/game-servers/snippets/delete_realm.js b/game-servers/snippets/delete_realm.js index f5224437c3..d5ba2ed6fc 100644 --- a/game-servers/snippets/delete_realm.js +++ b/game-servers/snippets/delete_realm.js @@ -19,37 +19,43 @@ * @param {string} location Compute Engine region. * @param {string} realmId the unique ID of the realm */ -function main( +async function main( projectId = 'YOUR_PROJECT_ID', location = 'LOCATION_ID', realmId = 'REALM_ID' ) { // [START cloud_game_servers_delete_realm] - /** - * TODO(developer): Uncomment these variables before running the sample. - */ - // const projectId = 'Your Google Cloud Project ID'; - // const location = 'A Compute Engine region, e.g. "us-central1"'; - // const realmId = 'Unique identifier of the realm'; const {RealmsServiceClient} = require('@google-cloud/game-servers'); const client = new RealmsServiceClient(); async function deleteRealm() { + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + // const projectId = 'Your Google Cloud Project ID'; + // const location = 'A Compute Engine region, e.g. "us-central1"'; + // const realmId = 'Unique identifier of the realm'; const request = { // Realm name is the full resource name including project ID,location, // and the realm ID. - name: `projects/${projectId}/locations/${location}/realms/${realmId}`, + name: client.realmPath(projectId, location, realmId), }; const [operation] = await client.deleteRealm(request); await operation.promise(); console.log(`Realm with ID ${realmId} deleted.`); - - // [END cloud_game_servers_delete_realm] } deleteRealm(); + // [END cloud_game_servers_delete_realm] } -main(...process.argv.slice(2)); +main(...process.argv.slice(2)).catch(err => { + console.error(err.message); + process.exitCode = 1; +}); +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); diff --git a/game-servers/snippets/get_cluster.js b/game-servers/snippets/get_cluster.js index 8cebc8ff75..5fb715e544 100644 --- a/game-servers/snippets/get_cluster.js +++ b/game-servers/snippets/get_cluster.js @@ -20,20 +20,13 @@ * @param {string} realmId the realm to use * @param {string} gameClusterId the game cluster to get */ -function main( +async function main( projectId = 'YOUR_PROJECT_ID', location = 'LOCATION_ID', realmId = 'REALM_ID', gameClusterId = 'GAME_CLUSTER_ID' ) { // [START cloud_game_servers_get_cluster] - /** - * TODO(developer): Uncomment these variables before running the sample. - */ - // const projectId = 'Your Google Cloud Project ID'; - // const location = 'A Compute Engine region, e.g. "us-central1"'; - // const realmId = 'The ID of the realm to locate this cluster in'; - // const gameClusterId = 'The unique ID for this Game Server Cluster'; const { GameServerClustersServiceClient, } = require('@google-cloud/game-servers'); @@ -41,9 +34,21 @@ function main( const client = new GameServerClustersServiceClient(); async function getGameServerCluster() { + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + // const projectId = 'Your Google Cloud Project ID'; + // const location = 'A Compute Engine region, e.g. "us-central1"'; + // const realmId = 'The ID of the realm to locate this cluster in'; + // const gameClusterId = 'The unique ID for this Game Server Cluster'; const request = { // Provide full resource name of a Game Server Realm - name: `projects/${projectId}/locations/${location}/realms/${realmId}/gameServerClusters/${gameClusterId}`, + name: client.gameServerClusterPath( + projectId, + location, + realmId, + gameClusterId + ), }; const [cluster] = await client.getGameServerCluster(request); @@ -54,10 +59,17 @@ function main( console.log( `\tGKE cluster: ${cluster.connectionInfo.gkeClusterReference.cluster}` ); - // [END cloud_game_servers_get_cluster] } getGameServerCluster(); + // [END cloud_game_servers_get_cluster] } -main(...process.argv.slice(2)); +main(...process.argv.slice(2)).catch(err => { + console.error(err.message); + process.exitCode = 1; +}); +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); diff --git a/game-servers/snippets/get_realm.js b/game-servers/snippets/get_realm.js index 620deadc14..b87e2f02d7 100644 --- a/game-servers/snippets/get_realm.js +++ b/game-servers/snippets/get_realm.js @@ -19,26 +19,26 @@ * @param {string} location Compute Engine region. * @param {string} realmId the unique ID of the realm */ -function main( +async function main( projectId = 'YOUR_PROJECT_ID', location = 'LOCATION_ID', realmId = 'REALM_ID' ) { // [START cloud_game_servers_get_realm] - /** - * TODO(developer): Uncomment these variables before running the sample. - */ - // const projectId = 'Your Google Cloud Project ID'; - // const location = 'A Compute Engine region, e.g. "us-central1"'; - // const realmId = 'Unique identifier of the realm'; const {RealmsServiceClient} = require('@google-cloud/game-servers'); const client = new RealmsServiceClient(); async function getRealm() { + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + // const projectId = 'Your Google Cloud Project ID'; + // const location = 'A Compute Engine region, e.g. "us-central1"'; + // const realmId = 'Unique identifier of the realm'; const request = { // Realm name is the full resource name including project ID and location - name: `projects/${projectId}/locations/${location}/realms/${realmId}`, + name: client.realmPath(projectId, location, realmId), }; const [realm] = await client.getRealm(request); @@ -50,10 +50,17 @@ function main( const createDate = new Date(createTime.seconds * 1000); console.log(`Realm created on: ${createDate.toLocaleDateString()}`); - // [END cloud_game_servers_get_realm] } getRealm(); + // [END cloud_game_servers_get_realm] } -main(...process.argv.slice(2)); +main(...process.argv.slice(2)).catch(err => { + console.error(err.message); + process.exitCode = 1; +}); +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); diff --git a/game-servers/snippets/list_clusters.js b/game-servers/snippets/list_clusters.js index d2faa73f53..88c1b8e101 100644 --- a/game-servers/snippets/list_clusters.js +++ b/game-servers/snippets/list_clusters.js @@ -19,18 +19,12 @@ * @param {string} location Compute Engine region * @param {string} realmId the realm to use */ -function main( +async function main( projectId = 'YOUR_PROJECT_ID', location = 'LOCATION_ID', realmId = 'REALM_ID' ) { // [START cloud_game_servers_list_clusters] - /** - * TODO(developer): Uncomment these variables before running the sample. - */ - // const projectId = 'Your Google Cloud Project ID'; - // const location = 'A Compute Engine region, e.g. "us-central1"'; - // const realmId = 'The ID of the realm to locate this cluster in'; const { GameServerClustersServiceClient, } = require('@google-cloud/game-servers'); @@ -38,9 +32,15 @@ function main( const client = new GameServerClustersServiceClient(); async function listGameServerClusters() { + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + // const projectId = 'Your Google Cloud Project ID'; + // const location = 'A Compute Engine region, e.g. "us-central1"'; + // const realmId = 'The ID of the realm to locate this cluster in'; const request = { // Provide full resource name of a Game Server Realm - parent: `projects/${projectId}/locations/${location}/realms/${realmId}`, + parent: client.realmPath(projectId, location, realmId), }; const results = await client.listGameServerClusters(request); @@ -54,10 +54,17 @@ function main( `\tGKE cluster: ${cluster.connectionInfo.gkeClusterReference.cluster}` ); } - // [END cloud_game_servers_list_clusters] } listGameServerClusters(); + // [END cloud_game_servers_list_clusters] } -main(...process.argv.slice(2)); +main(...process.argv.slice(2)).catch(err => { + console.error(err.message); + process.exitCode = 1; +}); +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); diff --git a/game-servers/snippets/list_realms.js b/game-servers/snippets/list_realms.js index fbeb7256f8..b3c2253c4c 100644 --- a/game-servers/snippets/list_realms.js +++ b/game-servers/snippets/list_realms.js @@ -18,18 +18,18 @@ * @param {string} projectId string project identifier. * @param {string} location Compute Engine region. */ -function main(projectId = 'YOUR_PROJECT_ID', location = 'LOCATION_ID') { +async function main(projectId = 'YOUR_PROJECT_ID', location = 'LOCATION_ID') { // [START cloud_game_servers_list_realms] - /** - * TODO(developer): Uncomment these variables before running the sample. - */ - // const projectId = 'Your Google Cloud Project ID'; - // const location = 'A Compute Engine region, e.g. "us-central1"'; const {RealmsServiceClient} = require('@google-cloud/game-servers'); const client = new RealmsServiceClient(); async function listRealms() { + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + // const projectId = 'Your Google Cloud Project ID'; + // const location = 'A Compute Engine region, e.g. "us-central1"'; const request = { parent: `projects/${projectId}/locations/${location}`, }; @@ -44,10 +44,17 @@ function main(projectId = 'YOUR_PROJECT_ID', location = 'LOCATION_ID') { const createDate = new Date(createTime.seconds * 1000); console.log(`Realm created on: ${createDate.toLocaleDateString()}\n`); } - // [END cloud_game_servers_list_realms] } listRealms(); + // [END cloud_game_servers_list_realms] } -main(...process.argv.slice(2)); +main(...process.argv.slice(2)).catch(err => { + console.error(err.message); + process.exitCode = 1; +}); +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +});