c-blake / cligen

Nim library to infer/generate command-line-interfaces / option / argument parsing; Docs at
https://c-blake.github.io/cligen/
ISC License
509 stars 24 forks source link

initFromCL() doc and short parameters doesn't take values from variables. #110

Closed 0xACE closed 4 years ago

0xACE commented 5 years ago

Using nim v0.20.0 and cligen-0.9.31.

const appsummary = "Description of this app"
type App* = object
  output*: string     ## outputfile
  vargs*: seq[string] ## Arguments
const appdef* = App(output: "nimcc")
const appsummary = "Description of this app"
const appshort = {"output": 'f'}

when isMainModule:
  import cligen
  var app = initFromCL(appdef, doc = appsummary, short = appshort)
  echo "app: ", app

and then running it as: myapp -h doesn't display the content of string Description of this app string, but rather just the variable name appsummary

and myapp -f example doesn't work as appshort doesn't get applied to short

c-blake commented 5 years ago

Yeah...You have to use a string literal in the template/macro calls themselves. I think that can maybe be addressed with some kind of static[T] work, but that feature of Nim is also often pretty iffy/touchy. PRs welcome if you want to try. But for now you can just write your strings inline. (You probably can't do a "string expression" either..just a big literal, though triple quoted strings do work fine.)

c-blake commented 5 years ago

Also, if you put a big double-hash/sharp/number/pound '##' at the top of the module, you may be able to use docFromModuleOf as in test/MultiMultiMulti.nim. And you might also have more luck with a let than a const. test/FullyAutoMulti.nim does a let docLine =.. and later uses doc=docLine for dispatchMulti. I don't think I've tried that with initFromCL.

c-blake commented 4 years ago

Just as a more local note here than in my comment for https://github.com/c-blake/cligen/commit/83f5d51277e0d9d72c1ddf9483042d4ca9bd2eb0, to have any hope of working the syntax for a const short would need to be ammended to:

const appShort = {"output": 'f'}.toTable

and similarly for the help parameter to things like dispatch.

Also, someone really needs to go through every parameter to make them work with typed values as well as just literals. PRs welcome.

c-blake commented 4 years ago

(And once all parameters can be handled this way, a single omnibus new test/PassValues.nim should probably test that they work.)