在cmder中添加命令提示功能,添加了goctl命令的提示
经常用cmder会发现输入
git
后按tab
键会自动提示git
命令的子命令,非常的方便。
最近我在用go-zero框架,但是每次敲goctl命令都需要翻一下笔记。
因此我想让cmder
支持goctl
命令的自动提示功能,最终发现cmder\vendor\clink-completions\git.lua
就是实现git
自动联想的脚本。
因此我仿照着写了一份goctl
的脚本,由于没有深入研究,写的都很粗浅,但是常用命令支持是没问题的。
下面是脚本goctl.lua
:
local parser = clink.arg.new_parser
local style_parser = parser({
"gozero","go_zero","GoZero"
})
local goctl_parser = parser(
{
"upgrade",
"api" .. parser({
"-o",
"new",
"format" .. parser({
"-dir",
"-iu",
"-stdin"
}),
"validate" .. parser({
"-api"
}),
"doc" .. parser({
"-dir"
}),
"go" .. parser({
"-dir",
"-api",
"-force",
"-style" .. style_parser
}),
"java" .. parser({
"-dir",
"-api"
}),
"ts" .. parser({
"-dir",
"-api",
"webapi",
"caller",
"unwrap"
}),
"dart" .. parser({
"-dir",
"-api"
}),
"kt" .. parser({
"-dir",
"-api",
"-pkg"
}),
"plugin" .. parser({
"-plugin",
"-dir",
"-api",
"-style" .. style_parser
})
}),
"docker" .. parser({"-go","-port"}),
"kube" .. parser({
"deploy" .. parser({
"-name","-namespace","-image","-secret","-requestCpu","-requestMem","-limitCpu","-limitMem","-o",
"-replicas","-revisions","-port","-nodePort","-minReplicas","-maxReplicas"
})
}),
"rpc" .. parser({
"new" .. parser({"-idea","-style" .. style_parser}),
"templae" .. parser({"-idea","-o"}),
"proto" .. parser({"-src","-s","-proto_path","-l","-dir","-d","-idea","-style" .. style_parser})
}),
"model" .. parser({
"mysql" .. parser({
"ddl" .. parser({"-src","-s","-dir","-d","-cache","-c","-idea","-style" .. style_parser}),
"datasource" .. parser({"-url","-table","-t","-dir","-d","-cache","-c","-idea","-style" .. style_parser})
})
}),
"config" .. parser({"-p"}),
"template" .. parser({
"init",
"clean",
"update" .. parser({"-c"}),
"revert" .. parser({"-c","-n"})
}),
"help",
"h"
},
"--help",
"-h",
"--version",
"-v"
)
clink.arg.register_parser("goctl", goctl_parser)
最终放到cmder\vendor\clink-completions\goctl.lua
目录就可以了。