From 4c631bba292ea177e80a652c685a8b47a79b30b2 Mon Sep 17 00:00:00 2001 From: Wesley Kerfoot Date: Sat, 21 Dec 2019 17:23:35 -0500 Subject: [PATCH] write proper help message --- src/twit2blog.nim | 7 ++++--- src/twit2blogpkg/help.nim | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 src/twit2blogpkg/help.nim diff --git a/src/twit2blog.nim b/src/twit2blog.nim index 14a0461..9881274 100644 --- a/src/twit2blog.nim +++ b/src/twit2blog.nim @@ -1,4 +1,4 @@ -import twit2blogpkg/twitter +import twit2blogpkg/twitter, twit2blogpkg/help import os, system, parseopt, strutils, tables when isMainModule: @@ -12,6 +12,8 @@ when isMainModule: case args.kind of cmdEnd: break of cmdShortOption, cmdLongOption: + if (args.key == "help") or (args.key == "h"): + writeHelp() if args.val == "": continue else: @@ -27,7 +29,6 @@ when isMainModule: twitterParams["thread"] = twitterParams["t"] if not (twitterParams.hasKey("user") and twitterParams.hasKey("thread")): - stderr.writeLine("Invalid Arguments. Must provide both --user and --thread (or -u and -t). E.g. -u:foo -t:123") - quit(1) + writeHelp() echo twitterParams["thread"].renderThread(twitterParams["user"]) diff --git a/src/twit2blogpkg/help.nim b/src/twit2blogpkg/help.nim new file mode 100644 index 0000000..3457d1d --- /dev/null +++ b/src/twit2blogpkg/help.nim @@ -0,0 +1,18 @@ +import system + +const + help = """ +Usage: twit2blog [opts] + +Options: + -u, --user The screen name of the twitter user. E.g. If your twitter is https://twitter.com/foobar, then `foobar`. + -t, --thread The ID of the last tweet in your thread. E.g. 12345. + +For more information read the Github readme: + https://github.com/weskerfoot/Twit2Blog#readme +""" + +proc writeHelp*(quit=true) = + echo(help) + if quit: + quit(1)