User friendly CLI apps for Elixir.
Here is a small screencast of what a generated CLI app looks like.
Add ex_cli
to your list of dependencies in mix.exs
:
def deps do
[{:ex_cli, "~> 0.1.0"}]
end
The basic usage is to use ExCLI.DSL
to define your CLI, and ExCLI.run
to run it.Here is a sample application:
defmodule MyApp.SampleCLI do
use ExCLI.DSL
name "mycli"
description "My CLI"
long_description ~s"""
This is my long description
"""
option :verbose, count: true, aliases: [:v]
command :hello do
aliases [:hi]
description "Greets the user"
long_description """
Gives a nice a warm greeting to whoever would listen
"""
argument :name
option :from, help: "the sender of hello"
run context do
if context.verbose > 0 do
IO.puts("Running hello command")
end
if from = context[:from] do
IO.write("#{from} says: ")
end
IO.puts("Hello #{context.name}!")
end
end
end
ExCLI.run!(MyApp.SampleCLI)
Which can be used in the following way.
sample_cli hello -vv world --from me
or using the command's alias:
sample_cli hi -vv world --from me
The application usage will be shown if the parsing fails. The above example would show:
usage: mycli [--verbose] <command> [<args>]
Commands
hello Greets the user
escript
and mix
integrationYou can very easily generate a mix task or an escript using ExCLI
escript
Pass escript: true
to the use ExCLI.DSL
and set the module as escript
:main_module
:
# lib/my_escript_cli.ex
defmodule MyEscriptCLI do
use ExCLI.DSL, escript: true
end
# mix.exs
defmodule MyApp.Mixfile do
def project do
[app: :my_app,
escript: [main_module: MyEscriptCLI]]
end
end
mix
integrationPass mix_task: TASK_NAME
to the use ExCLI.DSL
.
# lib/my_cli_task.ex
defmodule MyCLITask do
use ExCLI.DSL, mix_task: :great_task
end
You can then run
mix great_task
and get nicely formatted help with
mix help great_task
Check out the documentation for more information.
Command parser
The command parser is now working and should be enough for a good number of tasks.
Integration with escript
and mix
ExCLI.DSL
can generate a module compatible with escript.build
as well as a mix
task.
Usage generation
A nicely formatted usage is generated from the DSL.
Help command
Then the goal will be to add a help
command which can be used as app help command
to show help about command
.
Command parser improvements
When the usage and help parts are done, there are a few improvements that will be nice to have in the command parser:
Man page generation
When all this is done, the last part will to generate documentation in man page and markdown formats, which will probably be done as a mix task.
Contributions are very welcome, feel free to open an issue or a PR.
I am also looking for a better name, ideas are welcome!
wpa_cli 与wpa_supplicant交互的命令行客户端。 wpa_cli [-p<path to ctrl sockets>][-i<ifname>] [-hvB] [-a<action file>] \ [-P<pid file>] [-g<global ctrl>] [-G<pinginterval>] [command..] -h =help (show thi
1. 字符串相关操作 1. 设置值(set key value) # set key value [EX seconds] [PX milliseconds] [NX|XX] 127.0.0.1:6379> set name test1 OK 2. 获取值(get key), 删除(del key) # get key 127.0.0.1:6379> get name "test1" 3. 不存在
前言 php cli main 函数 configure & make 默认构建目标为 php-cli,相关代码在 sapi/cli 目录下,php_cli.c 文件中能够找到 main(入口)函数,大概流程如下: 命令行参数处理 cli_sapi_module 初始化 sapi_module->startup do_cli or do_cli_server 清理工作 sapi_module_st
要学习数组,必须先了解跟踪句柄。 一、跟踪句柄 跟踪句柄类似于本地C++指针,但也有很大区别。跟踪句柄确实存储着某个对象的地址,但当CLR压缩堆过程中改变了该对象的地址,则垃圾回收器自动更新句柄所包含的地址。我们不能像本地指针那样用跟踪句柄来执行地址的算术运算,也不允许对跟踪句柄进行强制类型转换。 在 CLR堆中创建的对象必须被跟踪句柄引用。所有属于引用类型的对象都存储在堆中,因此为引用这些对