Skip to content
This repository has been archived by the owner on Sep 4, 2024. It is now read-only.

Commit

Permalink
feat: ✨ CLI: Add tags option to CLI for upload and upload-dir
Browse files Browse the repository at this point in the history
  • Loading branch information
JesseTheRobot committed Jun 20, 2023
1 parent b813d9e commit b7cb033
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/node/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ program
.option("-c, --currency <string>", "The currency to use")
.option("--timeout <number>", "The timeout (in ms) for API HTTP requests - increase if you get timeouts for upload")
.option("--no-confirmation", "Disable confirmations for certain actions")
.option("-t, --tags [value...]", "Tags to include, format <name> <value>")
.option(
"--multiplier <number>",
"Adjust the multiplier used for tx rewards - the higher the faster the network will process the transaction.",
Expand Down Expand Up @@ -92,7 +93,8 @@ program
.action(async (file: string) => {
try {
const bundlr = await init(options, "upload");
const res = await bundlr.uploadFile(file);
const tags = parseTags(options?.tags);
const res = await bundlr.uploadFile(file, { tags: tags ?? [] });
console.log(`Uploaded to https://arweave.net/${res?.id}`);
} catch (err: any) {
console.error(`Error whilst uploading file: ${options.debug ? err.stack : err.message} `);
Expand Down Expand Up @@ -121,11 +123,13 @@ program
async function uploadDir(folder: string): Promise<void> {
try {
const bundler = await init(options, "upload");
const tags = parseTags(options?.tags);
const res = await bundler.uploadFolder(folder, {
indexFile: options.indexFile,
batchSize: +options.batchSize,
interactivePreflight: options.confirmation,
keepDeleted: !options.removeDeleted,
manifestTags: tags ?? [],
logFunction: async (log): Promise<void> => {
console.log(log);
},
Expand All @@ -137,6 +141,15 @@ async function uploadDir(folder: string): Promise<void> {
}
}

const parseTags = (arr: string[]): { name: string; value: string }[] | undefined => {
if (!arr) return;
if (arr.length % 2 !== 0) throw new Error(`Tags key is missing a value!`);
return arr.reduce<{ name: string; value: string }[]>((a, v, i) => {
(i + 1) % 2 === 0 ? (a.at(-1)!.value = v) : a.push({ name: v, value: "" });
return a;
}, []);
};

program
.command("fund")
.description("Funds your account with the specified amount of atomic units")
Expand Down

0 comments on commit b7cb033

Please sign in to comment.