From 6dd2dca097facbed91b08d463ed5983a324d710a Mon Sep 17 00:00:00 2001 From: Jane Roxanne Date: Sun, 15 Dec 2019 12:56:50 -0500 Subject: [PATCH] Oh yeah, competion time. --- completion/zsh/_luacomp | 24 ++++++++++++++++++++++++ src/application.lua | 23 +++++++++++++++++++++-- 2 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 completion/zsh/_luacomp diff --git a/completion/zsh/_luacomp b/completion/zsh/_luacomp new file mode 100644 index 0000000..4e9f979 --- /dev/null +++ b/completion/zsh/_luacomp @@ -0,0 +1,24 @@ +#compdef luacomp + +_luacomp() { + local -a options=( + {-h,--help}"[Show this help message and exit]" + {-O,--output}"[Output file]: :_files" + {-m,--minifier}"[Sets the postprocessor (default\: none)]: :( ${(f)'luacomp --post-processors'} )" + {-x,--executable}"[Makes the script an executable (default\: current lua version)]: :_path_commands" + "--generator-code[Outputs only the code from the generator]" + "--verbose[Verbose output]" + "--post-processors[Lists postprocessors]" + "--directives[Lists directives]" + {-v,--version}"[Prints the version and exits]" + "--completion[Output a shell completion script for the specified shell]: :(bash zsh fish)" + ) + _arguments -s -S \ + $options \ + ": :_files" \ + && return 0 + + return 1 +} + +_luacomp diff --git a/src/application.lua b/src/application.lua index 10ec2b3..e23f3c2 100644 --- a/src/application.lua +++ b/src/application.lua @@ -22,12 +22,31 @@ parser:option("-m --minifier", "Sets the postprocessor", "none") parser:option("-x --executable", "Makes the script an executable (default: current lua version)"):args "?" parser:flag("--generator-code", "Outputs only the code from the generator.") parser:flag("--verbose", "Verbose output. (Debugging)"):action(function() VERBOSE=true end) -parser:flag("--post-processors", "Lists postprocessors"):action(function() preload_providers() for k, v in pairs(providers) do print(k) end os.exit(0) end) -parser:flag("--directives", "Lists directives"):action(function() preload_directives() for k, v in pairs(directives) do print(k) end os.exit(0) end) +parser:flag("--post-processors", "Lists postprocessors"):action(function() + preload_providers() + local provs = {} + for k, v in pairs(providers) do + provs[#provs+1] = k + end + table.sort(provs) + print(table.concat(provs, "\n")) + os.exit(0) +end) +parser:flag("--directives", "Lists directives"):action(function() + preload_directives() + local dirs = {} + for k, v in pairs(directives) do + dirs[#dirs+1] = k + end + table.sort(dirs) + print(table.concat(dirs, "\n")) + os.exit(0) +end) parser:flag("-v --version", "Prints the version and exits"):action(function() print(LUACOMP_VERSION) os.exit(0) end) +parser:add_complete() local args = parser:parse() local file = args.input _sv("LUACOMP_MINIFIER", args.minifier)