From f7eb8ae842f209cad0c30316f7dad1fb0b8bb6dc Mon Sep 17 00:00:00 2001
From: metowolf
Date: Tue, 23 Oct 2018 22:46:47 +0800
Subject: [PATCH] :umbrella: 0.2.0, Command-line mode
---
README.md | 30 +++++++++++++++++++++++++++---
lib/cli.js | 38 ++++++++++++++++++++++++++++++++++++++
package.json | 11 +++++++----
3 files changed, 72 insertions(+), 7 deletions(-)
create mode 100755 lib/cli.js
diff --git a/README.md b/README.md
index 83d1afb..b391430 100644
--- a/README.md
+++ b/README.md
@@ -10,7 +10,29 @@
-## SMMS-cli
+## Command-line Usage
+
+### Installation
+
+```bash
+npm install smms-cli -g
+```
+
+### Usage
+
+Upload a single image
+
+```bash
+smms dog.png
+```
+
+Display smms-cli version:
+
+```bash
+smms --version
+```
+
+## Module Usage
### Installation
@@ -123,6 +145,8 @@ imgur.delete(hash)
})
```
-## License
+## Author
+
+**smms-cli** © [metowolf](https://github.com/metowolf), Released under the [MIT](./LICENSE) License.
-#### MIT
+> Blog [@meto](https://i-meto.com) · GitHub [@metowolf](https://github.com/metowolf) · Twitter [@metowolf](https://twitter.com/metowolf) · Telegram Channel [@metooooo](https://t.me/metooooo)
diff --git a/lib/cli.js b/lib/cli.js
new file mode 100755
index 0000000..5415243
--- /dev/null
+++ b/lib/cli.js
@@ -0,0 +1,38 @@
+#!/usr/bin/env node
+
+const fs = require('fs')
+const meow = require('meow')
+const smms = require('../')
+
+const cli = meow(`
+ Usage
+ $ smms
+
+ Options
+ --version, -V show smms-cli version
+
+ Examples
+ $ smms example.png
+ $ smms -V
+`, {
+ flags: {
+ version: {
+ alias: 'V'
+ }
+ }
+})
+
+if (cli.input.length === 0 && process.stdin.isTTY) {
+ console.error('filename required')
+ process.exit(1)
+}
+
+if (cli.input.length) {
+ smms
+ .upload(cli.input[0])
+ .then(res => console.log(res.data.url))
+ .catch(res => {
+ console.error(err)
+ process.exit(1)
+ })
+}
diff --git a/package.json b/package.json
index e7f2a37..7e7c4ce 100644
--- a/package.json
+++ b/package.json
@@ -1,23 +1,26 @@
{
"name": "smms-cli",
- "version": "0.1.1",
+ "version": "0.2.0",
"description": "Upload images to sm.ms",
"main": "lib/smms.js",
- "repository": "https://github.com/metowolf/smms-cli.git",
- "author": "metowolf ",
- "license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/metowolf/smms-cli.git"
},
+ "author": "metowolf ",
+ "license": "MIT",
"bugs": {
"url": "https://github.com/metowolf/smms-cli/issues"
},
"dependencies": {
+ "meow": "^5.0.0",
"request": "^2.88.0",
"request-promise": "^4.2.2"
},
"scripts": {
"test": "cd test && node example.js"
+ },
+ "bin": {
+ "smms": "./lib/cli.js"
}
}