|
| 1 | +// @ts-nocheck |
| 2 | +/* eslint-disable no-console */ |
| 3 | + |
| 4 | +// import chalk from 'chalk' |
| 5 | +import meow from 'meow' |
| 6 | +import ora from 'ora' |
| 7 | + |
| 8 | +import { outputFlags } from '../../flags/index.js' |
| 9 | +// import { handleApiCall, handleUnsuccessfulApiResponse } from '../../utils/api-helpers.js' |
| 10 | +import { InputError } from '../../utils/errors.js' |
| 11 | +import { prepareFlags } from '../../utils/flags.js' |
| 12 | +import { printFlagList } from '../../utils/formatting.js' |
| 13 | +// import { getDefaultKey, setupSdk } from '../../utils/sdk.js' |
| 14 | + |
| 15 | +/** @type {import('../../utils/meow-with-subcommands').CliSubcommand} */ |
| 16 | +export const create = { |
| 17 | + description: 'Create a repository in an organization', |
| 18 | + async run (argv, importMeta, { parentName }) { |
| 19 | + const name = parentName + ' create' |
| 20 | + |
| 21 | + const input = setupCommand(name, create.description, argv, importMeta) |
| 22 | + if (input) { |
| 23 | + const spinnerText = 'Creating repository... \n' |
| 24 | + const spinner = ora(spinnerText).start() |
| 25 | + await createRepo(input.orgSlug, input, spinner) |
| 26 | + } |
| 27 | + } |
| 28 | +} |
| 29 | + |
| 30 | +const listFullScanFlags = prepareFlags({ |
| 31 | + sort: { |
| 32 | + type: 'string', |
| 33 | + shortFlag: 's', |
| 34 | + default: 'created_at', |
| 35 | + description: 'Sorting option (`name` or `created_at`) - default is `created_at`', |
| 36 | + }, |
| 37 | + direction: { |
| 38 | + type: 'string', |
| 39 | + shortFlag: 'd', |
| 40 | + default: 'desc', |
| 41 | + description: 'Direction option (`desc` or `asc`) - Default is `desc`', |
| 42 | + }, |
| 43 | + perPage: { |
| 44 | + type: 'number', |
| 45 | + shortFlag: 'pp', |
| 46 | + default: 30, |
| 47 | + description: 'Results per page - Default is 30', |
| 48 | + }, |
| 49 | + page: { |
| 50 | + type: 'number', |
| 51 | + shortFlag: 'p', |
| 52 | + default: 1, |
| 53 | + description: 'Page number - Default is 1', |
| 54 | + }, |
| 55 | + fromTime: { |
| 56 | + type: 'string', |
| 57 | + shortFlag: 'f', |
| 58 | + default: '', |
| 59 | + description: 'From time - as a unix timestamp', |
| 60 | + }, |
| 61 | + untilTime: { |
| 62 | + type: 'string', |
| 63 | + shortFlag: 'u', |
| 64 | + default: '', |
| 65 | + description: 'Until time - as a unix timestamp', |
| 66 | + } |
| 67 | +}) |
| 68 | + |
| 69 | +// Internal functions |
| 70 | + |
| 71 | +/** |
| 72 | + * @typedef CommandContext |
| 73 | + * @property {boolean} outputJson |
| 74 | + * @property {boolean} outputMarkdown |
| 75 | + * @property {string} orgSlug |
| 76 | + * @property {string} sort |
| 77 | + * @property {string} direction |
| 78 | + * @property {number} perPage |
| 79 | + * @property {number} page |
| 80 | + * @property {string} fromTime |
| 81 | + * @property {string} untilTime |
| 82 | + */ |
| 83 | + |
| 84 | +/** |
| 85 | + * @param {string} name |
| 86 | + * @param {string} description |
| 87 | + * @param {readonly string[]} argv |
| 88 | + * @param {ImportMeta} importMeta |
| 89 | + * @returns {void|CommandContext} |
| 90 | + */ |
| 91 | +function setupCommand (name, description, argv, importMeta) { |
| 92 | + const flags = { |
| 93 | + ...outputFlags, |
| 94 | + ...listFullScanFlags |
| 95 | + } |
| 96 | + |
| 97 | + const cli = meow(` |
| 98 | + Usage |
| 99 | + $ ${name} <org slug> |
| 100 | +
|
| 101 | + Options |
| 102 | + ${printFlagList(flags, 6)} |
| 103 | +
|
| 104 | + Examples |
| 105 | + $ ${name} FakeOrg |
| 106 | + `, { |
| 107 | + argv, |
| 108 | + description, |
| 109 | + importMeta, |
| 110 | + flags |
| 111 | + }) |
| 112 | + |
| 113 | + const { |
| 114 | + json: outputJson, |
| 115 | + markdown: outputMarkdown, |
| 116 | + sort, |
| 117 | + direction, |
| 118 | + perPage, |
| 119 | + page, |
| 120 | + fromTime, |
| 121 | + untilTime |
| 122 | + } = cli.flags |
| 123 | + |
| 124 | + if (!cli.input[0]) { |
| 125 | + throw new InputError(`Please specify an organization slug. \n |
| 126 | +Example: |
| 127 | +socket scan list FakeOrg |
| 128 | +`) |
| 129 | + } |
| 130 | + |
| 131 | + const orgSlug = cli.input[0] || '' |
| 132 | + |
| 133 | + return { |
| 134 | + outputJson, |
| 135 | + outputMarkdown, |
| 136 | + orgSlug, |
| 137 | + sort, |
| 138 | + direction, |
| 139 | + perPage, |
| 140 | + page, |
| 141 | + fromTime, |
| 142 | + untilTime |
| 143 | + } |
| 144 | +} |
| 145 | + |
| 146 | +/** |
| 147 | + * @typedef FullScansData |
| 148 | + * @property {import('@socketsecurity/sdk').SocketSdkReturnType<'getOrgFullScanList'>["data"]} data |
| 149 | + */ |
| 150 | + |
| 151 | +/** |
| 152 | + * @param {string} orgSlug |
| 153 | + * @param {CommandContext} input |
| 154 | + * @param {import('ora').Ora} spinner |
| 155 | + * @returns {Promise<void|FullScansData>} |
| 156 | + */ |
| 157 | +async function createRepo (orgSlug, input, spinner) { |
| 158 | + // const socketSdk = await setupSdk(getDefaultKey()) |
| 159 | + console.log(input) |
| 160 | + |
| 161 | +// return { |
| 162 | +// // data: result.data |
| 163 | +// } |
| 164 | +} |
0 commit comments