-
Notifications
You must be signed in to change notification settings - Fork 393
/
Copy pathblobs.ts
96 lines (88 loc) · 3.61 KB
/
blobs.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import { OptionValues } from 'commander'
import requiresSiteInfo from '../../utils/hooks/requires-site-info.js'
import BaseCommand from '../base-command.js'
/**
* The blobs command
*/
const blobs = (_options: OptionValues, command: BaseCommand) => {
command.help()
}
/**
* Creates the `netlify blobs` command
*/
export const createBlobsCommand = (program: BaseCommand) => {
program
.command('blobs:delete')
.description(`Deletes an object with a given key, if it exists, from a Netlify Blobs store`)
.argument('<store>', 'Name of the store')
.argument('<key>', 'Object key')
.alias('blob:delete')
.hook('preAction', requiresSiteInfo)
.action(async (storeName: string, key: string, _options: OptionValues, command: BaseCommand) => {
const { blobsDelete } = await import('./blobs-delete.js')
await blobsDelete(storeName, key, _options, command)
})
program
.command('blobs:get')
.description(
`Reads an object with a given key from a Netlify Blobs store and, if it exists, prints the content to the terminal or saves it to a file`,
)
.argument('<store>', 'Name of the store')
.argument('<key>', 'Object key')
.option('-O, --output <path>', 'Defines the filesystem path where the blob data should be persisted')
.alias('blob:get')
.hook('preAction', requiresSiteInfo)
.action(async (storeName: string, key: string, options: OptionValues, command: BaseCommand) => {
const { blobsGet } = await import('./blobs-get.js')
await blobsGet(storeName, key, options, command)
})
program
.command('blobs:list')
.description(`Lists objects in a Netlify Blobs store`)
.argument('<store>', 'Name of the store')
.option(
'-d, --directories',
`Indicates that keys with the '/' character should be treated as directories, returning a list of sub-directories at a given level rather than all the keys inside them`,
)
.option(
'-p, --prefix <prefix>',
`A string for filtering down the entries; when specified, only the entries whose key starts with that prefix are returned`,
)
.option('--json', 'Output list contents as JSON')
.alias('blob:list')
.hook('preAction', requiresSiteInfo)
.action(async (storeName: string, options: OptionValues, command: BaseCommand) => {
const { blobsList } = await import('./blobs-list.js')
await blobsList(storeName, options, command)
})
program
.command('blobs:set')
.description(
`Writes to a Netlify Blobs store an object with the data provided in the command or the contents of a file defined by the 'input' parameter`,
)
.argument('<store>', 'Name of the store')
.argument('<key>', 'Object key')
.argument('[value...]', 'Object value')
.option('-i, --input <path>', 'Defines the filesystem path where the blob data should be read from')
.alias('blob:set')
.hook('preAction', requiresSiteInfo)
.action(
async (storeName: string, key: string, valueParts: string[], options: OptionValues, command: BaseCommand) => {
const { blobsSet } = await import('./blobs-set.js')
await blobsSet(storeName, key, valueParts, options, command)
},
)
return program
.command('blobs')
.alias('blob')
.description(`Manage objects in Netlify Blobs`)
.addExamples([
'netlify blobs:get my-store my-key',
'netlify blobs:set my-store my-key This will go in a blob',
'netlify blobs:set my-store my-key --input ./some-file.txt',
'netlify blobs:delete my-store my-key',
'netlify blobs:list my-store',
'netlify blobs:list my-store --json',
])
.action(blobs)
}