diff --git a/README.md b/README.md index f87d7b8..531d258 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,56 @@ -# ttmsh-cli +# ttm.sh CLI -A CLI application for interacting with ttm.sh \ No newline at end of file +A CLI application for interacting with ttm.sh. + +## Installation + +### From Source +```sh +git clone https://tildegit.org/jakew/ttmsh-cli.git +cd ttmsh-cli +npm install +npm link +# now you can use the command 'ttmsh' or 'node ./cli.js' or './cli.js' (only on nix) +``` + +## Usage + +### Shorten + +You can either include the URL in your command: + +```console +jakew@tilde:~$ ttmsh shorten https://google.co.uk +√ https://ttm.sh/Ef +``` + +...or not include it and be asked later: + +```console +jakew@tilde:~$ ttmsh shorten +√ Which URL would you like to shorten? · https://google.co.uk +√ https://ttm.sh/Ef +``` + +*Note: You will be asked again if you pass in an invalid URL.* + +### Upload + +Like with [shorten](#shorten), you can either include a file path in your command: + +```console +jakew@tilde:~$ ttmsh upload message.txt +√ https://ttm.sh/j0.txt +``` + +...or don't include it and be asked later: + +```console +jakew@tilde:~$ ttmsh upload +√ Which file would you like to upload? · message.txt +√ https://ttm.sh/j0.txt +``` + +## Contributing + +I'd love for people to add in new features and improve on my current work so feel free to open a pull request! \ No newline at end of file diff --git a/cli.js b/cli.js index 11ac43c..ada5248 100644 --- a/cli.js +++ b/cli.js @@ -1,11 +1,13 @@ +#!/usr/bin/env node + const { prompt } = require('enquirer'); const program = require('commander'); const pkg = require("./package.json"); const fs = require("fs"); const validUrl = require("valid-url"); -const request = require("request"); const ora = require("ora"); const Funnies = require("funnies").Funnies; +const ttmsh = require("./index.js"); let funnies = new Funnies(); @@ -77,7 +79,7 @@ async function shorten(url) { } // this is run when we need to contact ttm.sh (via the module index.js) -function doRequest(action, data) { +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(); diff --git a/index.js b/index.js index abd76e1..30ca9b6 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,5 @@ const rp = require("request-promise"); +const fs = require("fs"); /** * A wrapper for communication with ttm.sh diff --git a/package.json b/package.json index 1872845..9463aa2 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "ttmsh-cli", + "name": "ttmsh", "version": "1.0.0", "main": "index.js", "repository": "https://tildegit.org/jakew/ttmsh-cli.git", @@ -12,6 +12,7 @@ "funnies": "^2.0.0", "ora": "^3.2.0", "request": "^2.88.0", + "request-promise": "^4.2.4", "valid-url": "^1.0.9" }, "bin": { diff --git a/yarn.lock b/yarn.lock index 9c1e120..7119fb7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -70,6 +70,11 @@ bcrypt-pbkdf@^1.0.0: dependencies: tweetnacl "^0.14.3" +bluebird@^3.5.0: + version "3.5.3" + resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.5.3.tgz#7d01c6f9616c9a51ab0f8c549a79dfe6ec33efa7" + integrity sha512-/qKPUQlaW1OyR51WeCPBvRnAlnZFUJkCSG5HzGnuIqhgyJtF+T94lFnn33eiazjRm2LAHVy2guNnaq48X9SJuw== + caseless@~0.12.0: version "0.12.0" resolved "https://registry.yarnpkg.com/caseless/-/caseless-0.12.0.tgz#1b681c21ff84033c826543090689420d187151dc" @@ -307,7 +312,7 @@ jsprim@^1.2.2: json-schema "0.2.3" verror "1.10.0" -lodash@^4.13.1: +lodash@^4.13.1, 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== @@ -386,7 +391,7 @@ prop-types@^15.5.6: object-assign "^4.1.1" react-is "^16.8.1" -psl@^1.1.24: +psl@^1.1.24, psl@^1.1.28: version "1.1.31" resolved "https://registry.yarnpkg.com/psl/-/psl-1.1.31.tgz#e9aa86d0101b5b105cbe93ac6b784cd547276184" integrity sha512-/6pt4+C+T+wZUieKR620OpzN/LlnNKuWjy1iFLQ/UG35JqHlR/89MP1d96dUfkf6Dne3TuLQzOYEYshJ+Hx8mw== @@ -396,7 +401,7 @@ punycode@^1.4.1: resolved "https://registry.yarnpkg.com/punycode/-/punycode-1.4.1.tgz#c0d5a63b2718800ad8e1eb0fa5269c84dd41845e" integrity sha1-wNWmOycYgArY4esPpSachN1BhF4= -punycode@^2.1.0: +punycode@^2.1.0, punycode@^2.1.1: version "2.1.1" resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.1.1.tgz#b58b010ac40c22c5657616c8d2c2c02c7bf479ec" integrity sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A== @@ -434,6 +439,23 @@ regenerator-runtime@^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" + integrity sha512-UHYyq1MO8GsefGEt7EprS8UrXsm1TxEvFUX1IMTuSLU2Rh7fTIdFtl8xD7JiEYiWU2dl+NYAjCTksTehQUxPag== + dependencies: + lodash "^4.17.11" + +request-promise@^4.2.4: + version "4.2.4" + resolved "https://registry.yarnpkg.com/request-promise/-/request-promise-4.2.4.tgz#1c5ed0d71441e38ad58c7ce4ea4ea5b06d54b310" + integrity sha512-8wgMrvE546PzbR5WbYxUQogUnUDfM0S7QIFZMID+J73vdFARkFy+HElj4T+MWYhpXwlLp0EQ8Zoj8xUA0he4Vg== + dependencies: + bluebird "^3.5.0" + request-promise-core "1.1.2" + stealthy-require "^1.1.1" + tough-cookie "^2.3.3" + request@^2.88.0: version "2.88.0" resolved "https://registry.yarnpkg.com/request/-/request-2.88.0.tgz#9c2fca4f7d35b592efe57c7f0a55e81052124fef" @@ -498,6 +520,11 @@ sshpk@^1.7.0: safer-buffer "^2.0.2" tweetnacl "~0.14.0" +stealthy-require@^1.1.1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/stealthy-require/-/stealthy-require-1.1.1.tgz#35b09875b4ff49f26a777e509b3090a3226bf24b" + integrity sha1-NbCYdbT/SfJqd35QmzCQoyJr8ks= + strip-ansi@^5.0.0: version "5.2.0" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-5.2.0.tgz#8c9a536feb6afc962bdfa5b104a5091c1ad9c0ae" @@ -512,6 +539,14 @@ supports-color@^5.3.0: dependencies: has-flag "^3.0.0" +tough-cookie@^2.3.3: + version "2.5.0" + resolved "https://registry.yarnpkg.com/tough-cookie/-/tough-cookie-2.5.0.tgz#cd9fb2a0aa1d5a12b473bd9fb96fa3dcff65ade2" + integrity sha512-nlLsUzgm1kfLXSXfRZMc1KLAugd4hqJHDTvc2hDIwS3mZAfMEuMbc03SujMF+GEcpaX/qboeycw6iO8JwVv2+g== + dependencies: + psl "^1.1.28" + punycode "^2.1.1" + tough-cookie@~2.4.3: version "2.4.3" resolved "https://registry.yarnpkg.com/tough-cookie/-/tough-cookie-2.4.3.tgz#53f36da3f47783b0925afa06ff9f3b165280f781"