-
Notifications
You must be signed in to change notification settings - Fork 9
/
index.js
executable file
·45 lines (39 loc) · 1.25 KB
/
index.js
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
#!/usr/bin/env node
const program = require('commander');
const path = require('path');
const { handleUpload, handleSubmarine, getSubmarineAuth, getAuth, logIn, logInSubmarine } = require('./lib');
program
.version('1.0.3')
.name('pinata-cli')
.description('A command line tool to upload files and folders to Pinata')
.option('-a, --auth [jwt]', 'API jwt from Pinata')
.option('-as --authSubmarine [api key]', 'V2 API Key from Pinata')
.option('-u, --upload [file or folder]', 'Source folder or file to upload to IPFS')
.option('-s, --submarine [file or folder]', 'Source folder or file to submarine on Pinata')
.parse(process.argv)
const main = async () => {
try {
const { upload, submarine, auth, authSubmarine } = program.opts();
if(upload) {
await getAuth();
const result = await handleUpload(upload);
console.log(result);
}
if(submarine) {
await getSubmarineAuth();
const result = await handleSubmarine(submarine);
console.log(result);
}
if(auth) {
await logIn(auth);
console.log("Authenticated");
}
if(authSubmarine) {
await logInSubmarine(authSubmarine);
console.log("Authenticated");
}
} catch (error) {
console.log(error)
}
}
main()