From f1220c6377475247a210233c23a9971552672483 Mon Sep 17 00:00:00 2001 From: Pagan Gazzard Date: Mon, 10 Feb 2020 18:25:15 +0000 Subject: [PATCH] Convert lib/actions/notes to typescript Change-type: patch --- lib/actions/notes.coffee | 55 ----------------------------------- lib/actions/notes.ts | 57 +++++++++++++++++++++++++++++++++++++ typings/capitano/index.d.ts | 1 + 3 files changed, 58 insertions(+), 55 deletions(-) delete mode 100644 lib/actions/notes.coffee create mode 100644 lib/actions/notes.ts diff --git a/lib/actions/notes.coffee b/lib/actions/notes.coffee deleted file mode 100644 index 0451e150..00000000 --- a/lib/actions/notes.coffee +++ /dev/null @@ -1,55 +0,0 @@ -### -Copyright 2016-2017 Balena - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -### - -{ normalizeUuidProp } = require('../utils/normalization') - -exports.set = - signature: 'note <|note>' - description: 'set a device note' - help: ''' - Use this command to set or update a device note. - - If note command isn't passed, the tool attempts to read from `stdin`. - - To view the notes, use $ balena device . - - Examples: - - $ balena note "My useful note" --device 7cf02a6 - $ cat note.txt | balena note --device 7cf02a6 - ''' - options: [ - signature: 'device' - parameter: 'device' - description: 'device uuid' - alias: [ 'd', 'dev' ] - required: 'You have to specify a device' - ] - permission: 'user' - action: (params, options, done) -> - normalizeUuidProp(options, 'device') - Promise = require('bluebird') - _ = require('lodash') - balena = require('balena-sdk').fromSharedOptions() - - { exitWithExpectedError } = require('../utils/patterns') - - Promise.try -> - if _.isEmpty(params.note) - exitWithExpectedError('Missing note content') - - balena.models.device.note(options.device, params.note) - .nodeify(done) diff --git a/lib/actions/notes.ts b/lib/actions/notes.ts new file mode 100644 index 00000000..2e62d57d --- /dev/null +++ b/lib/actions/notes.ts @@ -0,0 +1,57 @@ +/* +Copyright 2016-2017 Balena + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +import { CommandDefinition } from 'capitano'; + +export const set: CommandDefinition<{ note: string }, { device: string }> = { + signature: 'note <|note>', + description: 'set a device note', + help: `\ +Use this command to set or update a device note. + +If note command isn't passed, the tool attempts to read from \`stdin\`. + +To view the notes, use $ balena device . + +Examples: + + $ balena note "My useful note" --device 7cf02a6 + $ cat note.txt | balena note --device 7cf02a6\ +`, + options: [ + { + signature: 'device', + parameter: 'device', + description: 'device uuid', + alias: ['d', 'dev'], + required: 'You have to specify a device', + }, + ], + permission: 'user', + async action(params, options) { + const { normalizeUuidProp } = await import('../utils/normalization'); + normalizeUuidProp(options, 'device'); + const _ = await import('lodash'); + const balena = (await import('balena-sdk')).fromSharedOptions(); + + if (_.isEmpty(params.note)) { + const { exitWithExpectedError } = await import('../utils/patterns'); + exitWithExpectedError('Missing note content'); + } + + return balena.models.device.note(options.device!, params.note); + }, +}; diff --git a/typings/capitano/index.d.ts b/typings/capitano/index.d.ts index 2ce5efef..393f5af4 100644 --- a/typings/capitano/index.d.ts +++ b/typings/capitano/index.d.ts @@ -29,6 +29,7 @@ declare module 'capitano' { description: string; parameter?: string; boolean?: boolean; + required?: string; alias?: string | string[]; }