Skip to content

Commit 0d9d155

Browse files
committed
wip
1 parent d6f7dd9 commit 0d9d155

File tree

6 files changed

+614
-0
lines changed

6 files changed

+614
-0
lines changed

lib/commands/repos/create.js

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
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+
}

lib/commands/repos/delete.js

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
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 { printFlagList } from '../../utils/formatting.js'
12+
// import { getDefaultKey, setupSdk } from '../../utils/sdk.js'
13+
14+
/** @type {import('../../utils/meow-with-subcommands').CliSubcommand} */
15+
export const del = {
16+
description: 'Delete a repository in an organization',
17+
async run (argv, importMeta, { parentName }) {
18+
const name = parentName + ' del'
19+
20+
const input = setupCommand(name, del.description, argv, importMeta)
21+
if (input) {
22+
const spinnerText = 'Deleting repository... \n'
23+
const spinner = ora(spinnerText).start()
24+
await deleteRepository(input.orgSlug, input, spinner)
25+
}
26+
}
27+
}
28+
29+
// Internal functions
30+
31+
/**
32+
* @typedef CommandContext
33+
* @property {boolean} outputJson
34+
* @property {boolean} outputMarkdown
35+
* @property {string} orgSlug
36+
*/
37+
38+
/**
39+
* @param {string} name
40+
* @param {string} description
41+
* @param {readonly string[]} argv
42+
* @param {ImportMeta} importMeta
43+
* @returns {void|CommandContext}
44+
*/
45+
function setupCommand (name, description, argv, importMeta) {
46+
const flags = {
47+
...outputFlags
48+
}
49+
50+
const cli = meow(`
51+
Usage
52+
$ ${name} <org slug>
53+
54+
Options
55+
${printFlagList(flags, 6)}
56+
57+
Examples
58+
$ ${name} FakeOrg
59+
`, {
60+
argv,
61+
description,
62+
importMeta,
63+
flags
64+
})
65+
66+
const {
67+
json: outputJson,
68+
markdown: outputMarkdown
69+
} = cli.flags
70+
71+
if (!cli.input[0]) {
72+
throw new InputError(`Please specify an organization slug. \n
73+
Example:
74+
socket scan list FakeOrg
75+
`)
76+
}
77+
78+
const orgSlug = cli.input[0] || ''
79+
80+
return {
81+
outputJson,
82+
outputMarkdown,
83+
orgSlug
84+
}
85+
}
86+
87+
/**
88+
* @typedef RepositoryData
89+
* @property {import('@socketsecurity/sdk').SocketSdkReturnType<'getOrgFullScanList'>["data"]} data
90+
*/
91+
92+
/**
93+
* @param {string} orgSlug
94+
* @param {CommandContext} input
95+
* @param {import('ora').Ora} spinner
96+
* @returns {Promise<void|RepositoryData>}
97+
*/
98+
async function deleteRepository (orgSlug, input, spinner) {
99+
// const socketSdk = await setupSdk(getDefaultKey())
100+
console.log(input)
101+
102+
// return {
103+
// // data: result.data
104+
// }
105+
}

lib/commands/repos/index.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// @ts-nocheck
2+
import { create } from './create.js'
3+
import { del } from './delete.js'
4+
import { list } from './list.js'
5+
import { update } from './update.js'
6+
import { view } from './view.js'
7+
import { meowWithSubcommands } from '../../utils/meow-with-subcommands.js'
8+
9+
const description = 'Repositories related commands'
10+
11+
/** @type {import('../../utils/meow-with-subcommands').CliSubcommand} */
12+
export const repo = {
13+
description,
14+
run: async (argv, importMeta, { parentName }) => {
15+
await meowWithSubcommands(
16+
{
17+
create,
18+
view,
19+
list,
20+
del,
21+
update
22+
},
23+
{
24+
argv,
25+
description,
26+
importMeta,
27+
name: parentName + ' repo',
28+
}
29+
)
30+
}
31+
}

0 commit comments

Comments
 (0)