Skip to content

Commit f116cf1

Browse files
jmdobryAce Nassri
authored andcommitted
Update the sample template. (#387)
1 parent 3162a05 commit f116cf1

File tree

1 file changed

+53
-44
lines changed

1 file changed

+53
-44
lines changed

CONTRIBUTING.md

Lines changed: 53 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -138,59 +138,68 @@ You can run `npm run lint` to match our JavaScript coding standards.
138138

139139
## Sample template
140140

141-
```
142-
<LICENSE_HEADER>
143-
144-
// [START all]
145-
// [START setup]
146-
// By default, the client will authenticate using the service account file
147-
// specified by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use
148-
// the project specified by the GCLOUD_PROJECT environment variable. See
149-
// https://googlecloudplatform.github.io/gcloud-node/#/docs/google-cloud/latest/guides/authentication
150-
var <API_CLIENT> = require('@google-cloud/<API>');
151-
152-
// Instantiate a <API> client
153-
var <CLIENT> = <API_CLIENT>();
154-
// [END setup]
155-
156-
// [START <REGION_TAG_NAME>]
141+
```js
157142
/**
158-
* <DESCRIPTION>
143+
* Copyright 2017, Google, Inc.
144+
* Licensed under the Apache License, Version 2.0 (the "License");
145+
* you may not use this file except in compliance with the License.
146+
* You may obtain a copy of the License at
159147
*
160-
* @param {<TYPE>} <NAME> <DESCRIPTION>.
161-
* @param {function} cb The callback function.
148+
* http://www.apache.org/licenses/LICENSE-2.0
149+
*
150+
* Unless required by applicable law or agreed to in writing, software
151+
* distributed under the License is distributed on an "AS IS" BASIS,
152+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
153+
* See the License for the specific language governing permissions and
154+
* limitations under the License.
162155
*/
163-
function <METHOD_NAME> (<ARGUMENTS>, callback) {
164-
// <SETUP>
165-
166-
// <RUN SAMPLE CODE>
167156

168-
// Inside callback: console.log(<MESSAGE>)
157+
'use strict';
158+
159+
function someMethod (someVariable) {
160+
// [START some_region_tag]
161+
// Imports the Google Cloud client library
162+
const Library = require('@google-cloud/some-library');
163+
164+
// The something something, e.g. "some-value"
165+
// const someVariable = "some-value";
166+
167+
// Instantiates a client
168+
const library = Library();
169+
170+
// Does something
171+
library
172+
.someMethod(someVariable)
173+
.then((results) => {
174+
const someResults = results[0];
175+
176+
console.log('Results:');
177+
someResults.forEach((result) => {
178+
console.log(result);
179+
});
180+
})
181+
.catch((err) => {
182+
console.error('ERROR:', err);
183+
});
184+
// [END some_region_tag]
169185
}
170-
// [END <REGION_TAG_NAME>]
171-
172-
// The command-line program
173-
var cli = require('yargs');
174-
175-
var program = module.exports = {
176-
<METHOD_NAME>: <METHOD_NAME>,
177-
main: function (args) {
178-
// Run the command-line program
179-
cli.help().strict().parse(args).argv; // eslint-disable-line
180-
}
181-
};
182186

183-
cli
187+
const cli = require('yargs')
184188
.demand(1)
185-
.command('<COMMAND> <ARGS>', '<DESCRIPTION>.', {}, function (options) {
186-
program.<METHOD_NAME>(options, console.log);
187-
})
188-
.example('node $0 <COMMAND> <ARGS>', '<DESCRIPTION>.')
189-
.wrap(100)
189+
.command(
190+
'someCommand <someVariable>',
191+
'Does something.',
192+
{},
193+
(opts) => someMethod(opts.someVariable)
194+
)
195+
.example('node $0 someCommand someValue', 'Does something.')
196+
.wrap(120)
190197
.recommendCommands()
191-
.epilogue('For more information, see <DOCS_LINK>');
198+
.epilogue(`For more information, see https://cloud.google.com/someProduct/docs`)
199+
.help()
200+
.strict();
192201

193202
if (module === require.main) {
194-
program.main(process.argv.slice(2));
203+
cli.parse(process.argv.slice(2));
195204
}
196205
```

0 commit comments

Comments
 (0)