2020-03-25 17:07:17 +00:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright 2016-2020 Balena Ltd.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2023-09-06 14:39:31 +00:00
|
|
|
import { Flags, Args } from '@oclif/core';
|
2023-11-07 22:32:25 +00:00
|
|
|
import Command from '../../command';
|
|
|
|
import { ExpectedError } from '../../errors';
|
|
|
|
import * as cf from '../../utils/common-flags';
|
|
|
|
import { getBalenaSdk, stripIndent } from '../../utils/lazy';
|
2020-03-25 17:07:17 +00:00
|
|
|
|
|
|
|
export default class NoteCmd extends Command {
|
|
|
|
public static description = stripIndent`
|
|
|
|
Set a device note.
|
|
|
|
|
|
|
|
Set or update a device note. If the note argument is not provided,
|
|
|
|
it will be read from stdin.
|
|
|
|
|
|
|
|
To view device notes, use the \`balena device <uuid>\` command.
|
2020-07-24 12:25:46 +00:00
|
|
|
`;
|
|
|
|
|
2020-03-25 17:07:17 +00:00
|
|
|
public static examples = [
|
|
|
|
'$ balena note "My useful note" --device 7cf02a6',
|
|
|
|
'$ cat note.txt | balena note --device 7cf02a6',
|
|
|
|
];
|
|
|
|
|
2023-09-06 14:39:31 +00:00
|
|
|
public static args = {
|
|
|
|
note: Args.string({
|
2020-03-25 17:07:17 +00:00
|
|
|
description: 'note content',
|
2023-09-06 14:39:31 +00:00
|
|
|
}),
|
|
|
|
};
|
2020-03-25 17:07:17 +00:00
|
|
|
|
|
|
|
public static usage = 'note <|note>';
|
|
|
|
|
2023-09-06 14:39:31 +00:00
|
|
|
public static flags = {
|
2020-03-25 17:07:17 +00:00
|
|
|
device: { exclusive: ['dev'], ...cf.device },
|
2023-09-06 14:39:31 +00:00
|
|
|
dev: Flags.string({
|
2020-03-25 17:07:17 +00:00
|
|
|
exclusive: ['device'],
|
|
|
|
hidden: true,
|
|
|
|
}),
|
|
|
|
help: cf.help,
|
|
|
|
};
|
|
|
|
|
|
|
|
public static authenticated = true;
|
|
|
|
|
|
|
|
public static readStdin = true;
|
|
|
|
|
|
|
|
public async run() {
|
2023-09-06 14:39:31 +00:00
|
|
|
const { args: params, flags: options } = await this.parse(NoteCmd);
|
2020-03-25 17:07:17 +00:00
|
|
|
|
|
|
|
params.note = params.note || this.stdin;
|
|
|
|
|
2020-07-08 16:34:53 +00:00
|
|
|
if (params.note.length === 0) {
|
2020-03-25 17:07:17 +00:00
|
|
|
throw new ExpectedError('Missing note content');
|
|
|
|
}
|
|
|
|
|
|
|
|
options.device = options.device || options.dev;
|
|
|
|
delete options.dev;
|
|
|
|
|
2020-07-08 16:34:53 +00:00
|
|
|
if (options.device == null || options.device.length === 0) {
|
2020-03-25 17:07:17 +00:00
|
|
|
throw new ExpectedError('Missing device UUID (--device)');
|
|
|
|
}
|
|
|
|
|
|
|
|
const balena = getBalenaSdk();
|
|
|
|
|
2023-05-23 10:21:51 +00:00
|
|
|
return balena.models.device.setNote(options.device, params.note);
|
2020-03-25 17:07:17 +00:00
|
|
|
}
|
|
|
|
}
|