Remove funny messages, add colours

This commit is contained in:
Jake 2019-04-12 16:42:21 +01:00
parent b3dfcdb507
commit 6a579633ba
No known key found for this signature in database
GPG Key ID: 1E172AEEACF8AE3D
4 changed files with 15 additions and 106 deletions

25
cli.js
View File

@ -6,11 +6,9 @@ const pkg = require("./package.json");
const fs = require("fs");
const validUrl = require("valid-url");
const ora = require("ora");
const Funnies = require("funnies").Funnies;
const ttmsh = require("./index.js");
const fileBytes = require("file-bytes");
let funnies = new Funnies();
const chalk = require("chalk");
// configure program with version, description and commands
program.version(pkg.version)
@ -27,7 +25,7 @@ program
// if any command isn't handled, this is run
program.on("command:*", () => {
console.error("Invalid command: %s\nSee --help for a list of available commands.", program.args.join(" "));
console.error(chalk.red.bold("Invalid command: %s\nSee --help for a list of available commands.", program.args.join(" ")));
process.exit(1);
});
@ -38,7 +36,7 @@ program.parse(process.argv);
// 'path' is passed in from the program and *should* be a valid filename
async function upload(path, cmd) {
if (cmd.force) {
console.warn("Forcing upload. Expect problems!");
console.warn(chalk.yellow("Forcing upload. Expect problems!"));
}
// if we don't have a path set or the path doesn't exist
@ -63,17 +61,17 @@ async function upload(path, cmd) {
var ret = ttmsh.retention(sizeMib);
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!`);
console.error(chalk.red.bold(`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...");
console.warn(chalk.yellow.bold(`This file is ~${sizeMib.toFixed(2)} MiB, which is over the limit of ${ttmsh.config.max_size} MiB!`));
console.warn(chalk.yellow("Attempting upload anyway..."));
} else {
console.log(`This file is ~${sizeMib.toFixed(2)} MiB and last ~${ret} days.`);
console.log(chalk.cyan(`This file is ~${sizeMib.toFixed(2)} MiB and last ~${ret} days.`));
}
// run the action, i.e upload the file
doAction("file", path);
doAction("upload", path);
});
}
@ -104,15 +102,14 @@ async function shorten(url) {
// this is run when we need to contact ttm.sh (via the module index.js)
function doAction(action, data) {
// create an spinner to show that we are trying to upload
// the spinner will have a funny message from 'funnies'
const spinner = ora(funnies.message()).start();
const spinner = ora(chalk.blue(`${action}ing...`)).start();
// use the ttmsh module to run the action with the data
ttmsh.do(action, data).then((result) => {
// if we were successful, display our result (i.e the url)
spinner.succeed(result);
spinner.succeed(chalk.greenBright.bold(result));
}).catch((e) => {
// if something went wrong, display an message with the error
spinner.fail(`Whoops! There was a problem while completing your request - ${e.message}`);
spinner.fail(`${chalk.red.bold("Whoops! There was a problem while completing your request -")} ${chalk.red(e.message)}`);
});
}

View File

@ -37,7 +37,7 @@ module.exports.do = function(action, data) {
const formData = {}
switch (action) {
case "file":
case "upload":
// in the form data, set file to be a file stream
// data is our file path if the action is 'file'
formData["file"] = fs.createReadStream(data);

View File

@ -1,16 +1,16 @@
{
"name": "ttmsh",
"version": "1.0.1",
"version": "1.1.1",
"main": "index.js",
"repository": "https://tildegit.org/jakew/ttmsh-cli.git",
"author": "Jake Walker <hi@jakew.me>",
"license": "GPL-3.0",
"description": "A CLI application for interacting with https://ttm.sh/.",
"dependencies": {
"chalk": "^2.4.2",
"commander": "^2.19.0",
"enquirer": "^2.3.0",
"file-bytes": "^2.0.3",
"funnies": "^2.0.0",
"ora": "^3.2.0",
"request": "^2.88.0",
"request-promise": "^4.2.4",

View File

@ -2,13 +2,6 @@
# yarn lockfile v1
"@babel/runtime@^7.1.2":
version "7.4.2"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.4.2.tgz#f5ab6897320f16decd855eed70b705908a313fe8"
integrity sha512-7Bl2rALb7HpvXFL7TETNzKSAeBVCPHELzc0C//9FCxN8nsiueWSJBqaF+2oIJScyILStASR/Cx5WMkXGYTiJFA==
dependencies:
regenerator-runtime "^0.13.2"
ajv@^6.5.5:
version "6.10.0"
resolved "https://registry.yarnpkg.com/ajv/-/ajv-6.10.0.tgz#90d0d54439da587cd7e843bfb7045f50bd22bdf1"
@ -80,11 +73,6 @@ caseless@~0.12.0:
resolved "https://registry.yarnpkg.com/caseless/-/caseless-0.12.0.tgz#1b681c21ff84033c826543090689420d187151dc"
integrity sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=
chain-function@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/chain-function/-/chain-function-1.0.1.tgz#c63045e5b4b663fb86f1c6e186adaf1de402a1cc"
integrity sha512-SxltgMwL9uCko5/ZCLiyG2B7R9fY4pDZUw7hJ4MhirdjBLosoDqkWABi3XMucddHdLiFJMb7PD2MZifZriuMTg==
chalk@^2.0.1, chalk@^2.4.2:
version "2.4.2"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.2.tgz#cd42541677a54333cf541a49108c1432b44c9424"
@ -159,13 +147,6 @@ delayed-stream@~1.0.0:
resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619"
integrity sha1-3zrhmayt+31ECqrgsp4icrJOxhk=
dom-helpers@^3.2.0:
version "3.4.0"
resolved "https://registry.yarnpkg.com/dom-helpers/-/dom-helpers-3.4.0.tgz#e9b369700f959f62ecde5a6babde4bccd9169af8"
integrity sha512-LnuPJ+dwqKDIyotW1VzmOZ5TONUN7CwkCR5hrgawTUbkBGYdeoNLZo6nNfGkCrjtE1nXXaj7iMMpDa8/d9WoIA==
dependencies:
"@babel/runtime" "^7.1.2"
ecc-jsbn@~0.1.1:
version "0.1.2"
resolved "https://registry.yarnpkg.com/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz#3a83a904e54353287874c564b7549386849a98c9"
@ -232,14 +213,6 @@ form-data@~2.3.2:
combined-stream "^1.0.6"
mime-types "^2.1.12"
funnies@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/funnies/-/funnies-2.0.0.tgz#b73de6751b8f8cb15725ef0228e3eec17baa2141"
integrity sha1-tz3mdRuPjLFXJe8CKOPuwXuqIUE=
dependencies:
lodash "^4.13.1"
react-addons-css-transition-group "^15.1.0"
getpass@^0.1.1:
version "0.1.7"
resolved "https://registry.yarnpkg.com/getpass/-/getpass-0.1.7.tgz#5eff8e3e684d569ae4cb2b1282604e8ba62149fa"
@ -284,11 +257,6 @@ isstream@~0.1.2:
resolved "https://registry.yarnpkg.com/isstream/-/isstream-0.1.2.tgz#47e63f7af55afa6f92e1500e690eb8b8529c099a"
integrity sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo=
"js-tokens@^3.0.0 || ^4.0.0":
version "4.0.0"
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"
integrity sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==
jsbn@~0.1.0:
version "0.1.1"
resolved "https://registry.yarnpkg.com/jsbn/-/jsbn-0.1.1.tgz#a5e654c2e5a2deb5f201d96cefbca80c0ef2f513"
@ -319,7 +287,7 @@ jsprim@^1.2.2:
json-schema "0.2.3"
verror "1.10.0"
lodash@^4.13.1, lodash@^4.17.11:
lodash@^4.17.11:
version "4.17.11"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.11.tgz#b39ea6229ef607ecd89e2c8df12536891cac9b8d"
integrity sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==
@ -331,13 +299,6 @@ log-symbols@^2.2.0:
dependencies:
chalk "^2.0.1"
loose-envify@^1.0.0, loose-envify@^1.3.1, loose-envify@^1.4.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.4.0.tgz#71ee51fa7be4caec1a63839f7e682d8132d30caf"
integrity sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==
dependencies:
js-tokens "^3.0.0 || ^4.0.0"
mime-db@~1.38.0:
version "1.38.0"
resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.38.0.tgz#1a2aab16da9eb167b49c6e4df2d9c68d63d8e2ad"
@ -360,11 +321,6 @@ oauth-sign@~0.9.0:
resolved "https://registry.yarnpkg.com/oauth-sign/-/oauth-sign-0.9.0.tgz#47a7b016baa68b5fa0ecf3dee08a85c679ac6455"
integrity sha512-fexhUFFPTGV8ybAtSIGbV6gOkSv8UtRbDBnAyLQw4QPKkgNlsH2ByPGtMUqdWkos6YCRmAqViwgZrJc/mRDzZQ==
object-assign@^4.1.1:
version "4.1.1"
resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863"
integrity sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=
onetime@^2.0.0:
version "2.0.1"
resolved "https://registry.yarnpkg.com/onetime/-/onetime-2.0.1.tgz#067428230fd67443b2794b22bba528b6867962d4"
@ -394,15 +350,6 @@ pify@^2.3.0:
resolved "https://registry.yarnpkg.com/pify/-/pify-2.3.0.tgz#ed141a6ac043a849ea588498e7dca8b15330e90c"
integrity sha1-7RQaasBDqEnqWISY59yosVMw6Qw=
prop-types@^15.5.6:
version "15.7.2"
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.7.2.tgz#52c41e75b8c87e72b9d9360e0206b99dcbffa6c5"
integrity sha512-8QQikdH7//R2vurIJSutZ1smHYTcLpRWEOlHnzcWHmBYrOGUysKwSsrC89BCiFj3CbrfJ/nXFdJepOVrY1GCHQ==
dependencies:
loose-envify "^1.4.0"
object-assign "^4.1.1"
react-is "^16.8.1"
psl@^1.1.24, psl@^1.1.28:
version "1.1.31"
resolved "https://registry.yarnpkg.com/psl/-/psl-1.1.31.tgz#e9aa86d0101b5b105cbe93ac6b784cd547276184"
@ -423,34 +370,6 @@ qs@~6.5.2:
resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.2.tgz#cb3ae806e8740444584ef154ce8ee98d403f3e36"
integrity sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA==
react-addons-css-transition-group@^15.1.0:
version "15.6.2"
resolved "https://registry.yarnpkg.com/react-addons-css-transition-group/-/react-addons-css-transition-group-15.6.2.tgz#9e4376bcf40b5217d14ec68553081cee4b08a6d6"
integrity sha1-nkN2vPQLUhfRTsaFUwgc7ksIptY=
dependencies:
react-transition-group "^1.2.0"
react-is@^16.8.1:
version "16.8.5"
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.8.5.tgz#c54ac229dd66b5afe0de5acbe47647c3da692ff8"
integrity sha512-sudt2uq5P/2TznPV4Wtdi+Lnq3yaYW8LfvPKLM9BKD8jJNBkxMVyB0C9/GmVhLw7Jbdmndk/73n7XQGeN9A3QQ==
react-transition-group@^1.2.0:
version "1.2.1"
resolved "https://registry.yarnpkg.com/react-transition-group/-/react-transition-group-1.2.1.tgz#e11f72b257f921b213229a774df46612346c7ca6"
integrity sha512-CWaL3laCmgAFdxdKbhhps+c0HRGF4c+hdM4H23+FI1QBNUyx/AMeIJGWorehPNSaKnQNOAxL7PQmqMu78CDj3Q==
dependencies:
chain-function "^1.0.0"
dom-helpers "^3.2.0"
loose-envify "^1.3.1"
prop-types "^15.5.6"
warning "^3.0.0"
regenerator-runtime@^0.13.2:
version "0.13.2"
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.13.2.tgz#32e59c9a6fb9b1a4aff09b4930ca2d4477343447"
integrity sha512-S/TQAZJO+D3m9xeN1WTI8dLKBBiRgXBlTJvbWjCThHWZj9EvHK70Ff50/tYj2J/fvBY6JtFVwRuazHN2E7M9BA==
request-promise-core@1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/request-promise-core/-/request-promise-core-1.1.2.tgz#339f6aababcafdb31c799ff158700336301d3346"
@ -605,13 +524,6 @@ verror@1.10.0:
core-util-is "1.0.2"
extsprintf "^1.2.0"
warning@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/warning/-/warning-3.0.0.tgz#32e5377cb572de4ab04753bdf8821c01ed605b7c"
integrity sha1-MuU3fLVy3kqwR1O9+IIcAe1gW3w=
dependencies:
loose-envify "^1.0.0"
wcwidth@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/wcwidth/-/wcwidth-1.0.1.tgz#f0b0dcf915bc5ff1528afadb2c0e17b532da2fe8"