|
| 1 | +import {Command, Flags, CliUx} from '@oclif/core' |
| 2 | + |
| 3 | +import {APIClient} from '../../api' |
| 4 | + |
| 5 | +export default class Create extends Command { |
| 6 | + static description = 'Create a team note' |
| 7 | + |
| 8 | + static examples = [ |
| 9 | + `team-notes:create --teamPath=CLI-test --content='# A new note created' --readPermission=owner --writePermission=owner --commentPermission=disabled |
| 10 | +ID Title User Path Team Path |
| 11 | +────────────────────── ──────────────────────────────── ────────────────────── ──────── |
| 12 | +raUuSTetT5uQbqQfLnz9lA CLI test note gvfz2UB5THiKABQJQnLs6Q null ` |
| 13 | + ] |
| 14 | + |
| 15 | + static flags = { |
| 16 | + help: Flags.help({char: 'h'}), |
| 17 | + teamPath: Flags.string(), |
| 18 | + title: Flags.string(), |
| 19 | + content: Flags.string(), |
| 20 | + readPermission: Flags.string(), |
| 21 | + writePermission: Flags.string(), |
| 22 | + commentPermission: Flags.string(), |
| 23 | + ...CliUx.ux.table.flags(), |
| 24 | + } |
| 25 | + |
| 26 | + async run() { |
| 27 | + const {flags} = await this.parse(Create) |
| 28 | + const {teamPath, title, content, readPermission, writePermission, commentPermission} = flags |
| 29 | + const options = {title, content, readPermission, writePermission, commentPermission} |
| 30 | + |
| 31 | + if(!teamPath) { |
| 32 | + this.error('Flag teamPath could not be empty') |
| 33 | + } |
| 34 | + |
| 35 | + try { |
| 36 | + // TODO: create note options typing |
| 37 | + const note = await APIClient.createTeamNote(teamPath, options as any) |
| 38 | + |
| 39 | + CliUx.ux.table([note], { |
| 40 | + id: { |
| 41 | + header: 'ID', |
| 42 | + }, |
| 43 | + title: {}, |
| 44 | + userPath: { |
| 45 | + header: 'User path' |
| 46 | + }, |
| 47 | + teamPath:{ |
| 48 | + header: 'Team path' |
| 49 | + } |
| 50 | + }, { |
| 51 | + printLine: this.log.bind(this), |
| 52 | + ...flags |
| 53 | + }) |
| 54 | + } catch (e) { |
| 55 | + this.log('Update team note content failed') |
| 56 | + this.error(e) |
| 57 | + } |
| 58 | + } |
| 59 | +} |
| 60 | + |
0 commit comments