Skip to content

Commit

Permalink
0.0.3: new cli features
Browse files Browse the repository at this point in the history
  • Loading branch information
disruptek committed May 8, 2020
1 parent 7e9e311 commit 361adfc
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 13 deletions.
48 changes: 37 additions & 11 deletions datamuse.nim
Original file line number Diff line number Diff line change
@@ -1,27 +1,53 @@
import std/sequtils
import std/options
import std/uri
import std/asyncdispatch
import std/httpclient
import std/options
import std/json

import bump
import rest
import cutelog
import bump

const
datamuseUrl = "https://api.datamuse.com/words".parseUri
proc newDataMuseCall*(url: Uri; name = "datamuse"): RestCall =
result = RestCall(name: name, meth: HttpGet, url: url)

proc newDataMuseCall*(args: openArray[tuple[key, val: string]];
name = "datamuse"): RestCall =
result = RestCall(name: name, meth: HttpGet, url: datamuseUrl ? args)
proc newWordsCall*(args: openArray[tuple[key, val: string]]): RestCall =
const
wordsUrl = "https://api.datamuse.com/words".parseUri
result = newDataMuseCall(wordsUrl ? args, name = "datamuse words")

proc name(rhyme = "") =
proc newSuggCall*(args: openArray[tuple[key, val: string]]): RestCall =
const
suggUrl = "https://api.datamuse.com/sug".parseUri
result = newDataMuseCall(suggUrl ? args, name = "datamuse suggestions")

proc muse(rel_rhy = ""; rel_trg = ""; rel_jja = ""; rel_jjb = "";
sp = ""; ml = ""; sl = ""; sugg = ""; lc = "") =
var
args = toSeq {
"rel_rhy": rel_rhy,
"rel_trg": rel_trg,
"rel_jja": rel_jja,
"rel_jjb": rel_jjb,
"s": sugg,
"sp": sp,
"lc": lc,
"ml": ml,
"sl": sl,
}
args.keepItIf it[1] != ""
var
call = newDataMuseCall {"rel_rhy": rhyme}
call =
if sugg != "":
newSuggCall args
else:
newWordsCall args
let
request = newRecallable(call)
response = request.retried
debug waitfor response.body
js = parseJson(waitfor response.body)
debug js.pretty

when isMainModule:
import cligen
Expand All @@ -38,7 +64,7 @@ when isMainModule:
else:
clCfg.version = "(unknown version)"

dispatchCf name, cmdName = "name", cf = clCfg
dispatchCf muse, cmdName = "muse", cf = clCfg
when false:
dispatchCf name, cmdName = "name", cf = clCfg,
usage = "Options(opt-arg sep :|=|spc):\n$options",
Expand Down
4 changes: 2 additions & 2 deletions datamuse.nimble
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
version = "0.0.2"
version = "0.0.3"
author = "disruptek"
description = "generate random names"
license = "MIT"
requires "nim >= 1.0.0"
requires "cligen < 1.0.0"
requires "cligen < 0.9.40"
requires "https://github.com/disruptek/cutelog < 2.0.0"
requires "https://github.com/disruptek/rest < 2.0.0"
requires "https://github.com/disruptek/bump < 2.0.0"
Expand Down

0 comments on commit 361adfc

Please sign in to comment.