我可以自动发现shell或Perl脚本的参数到“meta”程序WEB UI吗?

时间:2021-10-04 07:10:48

Is it possible to auto-discover parameters to shell/Perl scripts in order to "meta" program WEB UIs for them?

是否可以自动发现shell / Perl脚本的参数,以便“meta”为它们编写WEB UI?


I have a bunch of "legacy" scripts that I'd like to "web wrap". So far I have created a CGI-BIN web app with about 3 parameters that can call a bash/Perl reporting script.

我有一堆“遗留”脚本,我想“网络包装”。到目前为止,我已经创建了一个CGI-BIN Web应用程序,其中包含大约3个可以调用bash / Perl报告脚本的参数。

But it now occurs to me maybe there is quicker or automatic way to wrap these 100s of scripts.

但现在我想到可能有更快或自动的方式来包装这100个脚本。

So basically I'd like to find out about techniques for metaprogramming where I'd discover what input parameters a particular bash or Perl script takes and then generate corresponding HTML FORM elements with those input parameters as TEXT INPUT or SELECT dropt down boxes etc.

所以基本上我想了解元编程的技巧,我会发现特定的bash或Perl脚本所采用的输入参数,然后使用TEXT INPUT或SELECT dropt down box等输入参数生成相应的HTML FORM元素。

Any ideas or links to examples?

任何想法或示例链接?

3 个解决方案

#1


There isn't a way to look at random Perl source code to determine what arguments it takes, what those arguments mean, or how they are constrained.

没有办法查看随机的Perl源代码来确定它所采用的参数,这些参数的含义或它们如何受到约束。

If the Perl scripts you deal with all use a common library to process arguments, such as GetOpt::Long, then you could use the information the script passes to the argument processor to get most of the information.

如果您处理的Perl脚本都使用公共库来处理参数,例如GetOpt :: Long,那么您可以使用脚本传递给参数处理器的信息来获取大部分信息。

Other than that, you're out of luck.

除此之外,你运气不好。

#2


Aside from Catalyst, CGI has a standard way to send in parameters via GET or POST, and CGI.pm makes it easy.

除了Catalyst之外,CGI还有一种通过GET或POST发送参数的标准方法,CGI.pm使其变得简单。


You've added the requirement "I'd like to find out about techniques for metaprogramming where I'd discover what input parameters a particular bash or perl script takes and then generate corresponding HTML FORM elements with those input parameters as TEXT INPUT or SELECT drop down boxes etc."

你已经添加了一个要求“我想了解元编程的技巧,我会发现特定bash或perl脚本所需的输入参数,然后生成相应的HTML FORM元素,这些输入参数为TEXT INPUT或SELECT drop下框等“

There isn't a standard way to "discover what input parameters a particular bash or perl script takes" because there isn't a standard way for these scripts to report this information. There are close-to-standard possibilities (parsing the troff source of the corresponding man page, calling the script with "--help" and parsing the output), or you could keep this information in a database of some sort.

没有标准的方法来“发现特定bash或perl脚本采用的输入参数”,因为这些脚本没有标准的方式来报告此信息。有接近标准的可能性(解析相应手册页的troff源,用“--help”调用脚本并解析输出),或者你可以将这些信息保存在某种类型的数据库中。

There is a standard way to determine which parameters were sent to a CGI script, and then display those parameters as settable form elements. CGI.pm will bring them in as a hash, which you can loop through (displaying the key as the label for your text box and the value as the text in the corresponding text box).

有一种标准方法可以确定将哪些参数发送到CGI脚本,然后将这些参数显示为可设置的表单元素。 CGI.pm将把它们作为哈希引入,你可以循环(将键显示为文本框的标签,将值显示为相应文本框中的文本)。

#3


To expand on what brian said, if you can provide us a few code samples, we can maybe help a little more. If the scripts use the same (or similar) methods for parsing their parameters, then we have a chance to write some code.

要扩展brian所说的内容,如果您能为我们提供一些代码示例,我们可以提供更多帮助。如果脚本使用相同(或类似)的方法来解析它们的参数,那么我们就有机会编写一些代码。

It may well be that you can write a meta-programming solution for the portion of your legacy scripts that are "regular", and write a table-based solution for the "irregular" ones.

您可以为遗留脚本中的“常规”部分编写元编程解决方案,并为“不规则”编写基于表的解决方案。

#1


There isn't a way to look at random Perl source code to determine what arguments it takes, what those arguments mean, or how they are constrained.

没有办法查看随机的Perl源代码来确定它所采用的参数,这些参数的含义或它们如何受到约束。

If the Perl scripts you deal with all use a common library to process arguments, such as GetOpt::Long, then you could use the information the script passes to the argument processor to get most of the information.

如果您处理的Perl脚本都使用公共库来处理参数,例如GetOpt :: Long,那么您可以使用脚本传递给参数处理器的信息来获取大部分信息。

Other than that, you're out of luck.

除此之外,你运气不好。

#2


Aside from Catalyst, CGI has a standard way to send in parameters via GET or POST, and CGI.pm makes it easy.

除了Catalyst之外,CGI还有一种通过GET或POST发送参数的标准方法,CGI.pm使其变得简单。


You've added the requirement "I'd like to find out about techniques for metaprogramming where I'd discover what input parameters a particular bash or perl script takes and then generate corresponding HTML FORM elements with those input parameters as TEXT INPUT or SELECT drop down boxes etc."

你已经添加了一个要求“我想了解元编程的技巧,我会发现特定bash或perl脚本所需的输入参数,然后生成相应的HTML FORM元素,这些输入参数为TEXT INPUT或SELECT drop下框等“

There isn't a standard way to "discover what input parameters a particular bash or perl script takes" because there isn't a standard way for these scripts to report this information. There are close-to-standard possibilities (parsing the troff source of the corresponding man page, calling the script with "--help" and parsing the output), or you could keep this information in a database of some sort.

没有标准的方法来“发现特定bash或perl脚本采用的输入参数”,因为这些脚本没有标准的方式来报告此信息。有接近标准的可能性(解析相应手册页的troff源,用“--help”调用脚本并解析输出),或者你可以将这些信息保存在某种类型的数据库中。

There is a standard way to determine which parameters were sent to a CGI script, and then display those parameters as settable form elements. CGI.pm will bring them in as a hash, which you can loop through (displaying the key as the label for your text box and the value as the text in the corresponding text box).

有一种标准方法可以确定将哪些参数发送到CGI脚本,然后将这些参数显示为可设置的表单元素。 CGI.pm将把它们作为哈希引入,你可以循环(将键显示为文本框的标签,将值显示为相应文本框中的文本)。

#3


To expand on what brian said, if you can provide us a few code samples, we can maybe help a little more. If the scripts use the same (or similar) methods for parsing their parameters, then we have a chance to write some code.

要扩展brian所说的内容,如果您能为我们提供一些代码示例,我们可以提供更多帮助。如果脚本使用相同(或类似)的方法来解析它们的参数,那么我们就有机会编写一些代码。

It may well be that you can write a meta-programming solution for the portion of your legacy scripts that are "regular", and write a table-based solution for the "irregular" ones.

您可以为遗留脚本中的“常规”部分编写元编程解决方案,并为“不规则”编写基于表的解决方案。