类似于git的界面的最佳方法

类似于git的界面的最佳方法

本文介绍了类似于git的界面的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个具有通用git界面的命令行小程序。

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

它可以执行多项任务:添加列表完整,...所有这些都可以通过以下方式访问 todo< task> 界面。例如待办事项列表

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

像git一样,其中一些任务采用变量或选项,而 todo 应用程序还可以使用选项(适用于任何类型的任务,例如配置文件的位置)。

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]

我正在用C ++编写此项目,基本的后端库已完成。我正在尝试弄清楚如何编写用户界面。

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.

我应该使用一个大的 main 分别处理每个任务,还是应该将程序分成几个子程序,然后从简单的shell脚本调用它们(如果我正确的话,这就是git所做的事情)。后者似乎更易于维护,但是使将全局选项传递给任务可执行文件变得困难。

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?

推荐答案

您编写的代码是用于命令行应用程序的。然后我会选择一个二进制文件。最简单的方法可能是使用 Boost.Program_options

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.

从我的角度来看,限制某些选择权是一个非常糟糕的主意。它将使大多数用户感到困惑。最坏的情况是当头寸改变期权的语义时。 gcc 使用 -l 选项做到了这一点,十年后您仍然发现新用户抱怨他们的程序无法正确链接

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.

这篇关于类似于git的界面的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 08:42