Add force parameter
This commit is contained in:
parent
8f46819ac2
commit
b3dfcdb507
18
cli.js
18
cli.js
|
@ -22,6 +22,7 @@ program.version(pkg.version)
|
|||
|
||||
program
|
||||
.command("upload [path]")
|
||||
.option("-f, --force", "force an upload (disable file size checks)")
|
||||
.action(upload);
|
||||
|
||||
// if any command isn't handled, this is run
|
||||
|
@ -35,7 +36,11 @@ program.parse(process.argv);
|
|||
|
||||
// this function is ran when the upload command is used
|
||||
// 'path' is passed in from the program and *should* be a valid filename
|
||||
async function upload(path) {
|
||||
async function upload(path, cmd) {
|
||||
if (cmd.force) {
|
||||
console.warn("Forcing upload. Expect problems!");
|
||||
}
|
||||
|
||||
// if we don't have a path set or the path doesn't exist
|
||||
if (!path || !fs.existsSync(path)) {
|
||||
// ask the user to (re)type a path
|
||||
|
@ -57,13 +62,16 @@ async function upload(path) {
|
|||
var sizeMib = size / 1048576;
|
||||
var ret = ttmsh.retention(sizeMib);
|
||||
|
||||
if (ret === -1) {
|
||||
if (ret === -1 && !cmd.force) {
|
||||
console.error(`This file is ~${sizeMib.toFixed(2)} MiB, which is over the limit of ${ttmsh.config.max_size} MiB!`);
|
||||
return;
|
||||
} else if (ret === -1 && cmd.force) {
|
||||
console.warn(`This file is ~${sizeMib.toFixed(2)} MiB, which is over the limit of ${ttmsh.config.max_size} MiB!`);
|
||||
console.warn("Attempting upload anyway...");
|
||||
} else {
|
||||
console.log(`This file is ~${sizeMib.toFixed(2)} MiB and last ~${ret} days.`);
|
||||
}
|
||||
|
||||
console.log(`This file is ~${sizeMib.toFixed(2)} MiB and last ~${ret} days.`);
|
||||
|
||||
// run the action, i.e upload the file
|
||||
doAction("file", path);
|
||||
});
|
||||
|
@ -105,6 +113,6 @@ function doAction(action, data) {
|
|||
spinner.succeed(result);
|
||||
}).catch((e) => {
|
||||
// if something went wrong, display an message with the error
|
||||
spinner.fail(`Whoops! There was a problem while completing your request - ${err.message}`);
|
||||
spinner.fail(`Whoops! There was a problem while completing your request - ${e.message}`);
|
||||
});
|
||||
}
|
Reference in New Issue