Best approach for git-like interface

旧街凉风 提交于 2019-12-23 18:16:40

问题


I'm writing a little command line todo app that has a general git-like interface.

It has several tasks it can perform: add, list, complete, ... all of these should be accessible via the todo <task> interface. Eg todo list.

Like with git, some of these task take variables or options, and the todo app can also take options (which are applicable to any type of task, e.g. the location of the config file).

Eventually one should be able to write something like:

todo -c ~/.config/todorc add --desc "walk the dog"

Note the order of things here: the global options are given (and can only be given) before the actual task. The skeleton for a typical call is then:

todo [global options] <task> [task options/arguments]

I'm writing this project in C++ and the basic backend library is finished. I'm trying to figure out how to write the user interface now.

Should I use one big main that handles every task separatly or should I split up the program into several subprograms and call them from a simple shell script (which is what git does if I'm correct). The latter seems easier to maintain, but makes it harder to pass on the global options to the task executable.

Is there any literature on this subject?


回答1:


You wrote it is for a little command line application. Then I would go for one single binary. The easiest way to go is probably to use Boost.Program_options.

From my point of view constraining the position of some options is a very bad idea. It will confuse most of the user. The worst case is when position change the semantic of the option. gcc did that with the -l option and 10 years after you still find new users complaining about their program not linking correctly.



来源:https://stackoverflow.com/questions/12440299/best-approach-for-git-like-interface

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!