* [PATCH 01/25] Add variables for all commands and options.
2018-05-26 15:06 [PATCH 00/25] *** Add completion for luarocks *** doron.behar
@ 2018-05-26 15:06 ` doron.behar
2018-05-26 15:06 ` [PATCH 02/25] Remove architecture related option completion doron.behar
` (24 subsequent siblings)
25 siblings, 0 replies; 28+ messages in thread
From: doron.behar @ 2018-05-26 15:06 UTC (permalink / raw)
To: zsh-workers
From: Doron Behar <doron.behar@gmail.com>
---
Completion/Unix/Command/_luarocks | 178 ++++++++++++++++++++++++++++++
1 file changed, 178 insertions(+)
create mode 100644 Completion/Unix/Command/_luarocks
diff --git a/Completion/Unix/Command/_luarocks b/Completion/Unix/Command/_luarocks
new file mode 100644
index 000000000..753fdb381
--- /dev/null
+++ b/Completion/Unix/Command/_luarocks
@@ -0,0 +1,178 @@
+#compdef luarocks
+
+local general_options=(
+ '(--server --only-server)--server=[Fetch rocks/rockspecs from this server]:HOST:_hosts'
+ '(--server --only-server)--only-server=[Fetch rocks/rockspecs from this server only]:HOST:_hosts'
+ '--only-sources=[Restrict downloads to paths matching the given URL]:URL:_urls'
+ '--tree=[Which tree to operate on]:TREE:'
+ '--local[Use the tree in the user'"'"'s home directory]'
+ '--verbose[Display verbose output of commands executed]'
+ '--timeout=[Timeout on network operations]:SECONDS:{_message "timeout (seconds)"}'
+)
+# SYNOPSIS: /usr/bin/luarocks [--server=<server> | --only-server=<server>] [--tree=<tree>] [VAR=VALUE]... <command> [<argument>]
+local commands=(
+ 'build[Build/compile a rock]'
+ 'config[Query information about the LuaRocks configuration]'
+ 'doc[Show documentation for an installed rock]'
+ 'download[Download a specific rock file from a rocks server]'
+ 'help[Help on commands]'
+ 'install[Install a rock]'
+ 'lint[Check syntax of a rockspec]'
+ 'list[List currently installed rocks]'
+ 'make[Compile package in current directory using a rockspec]'
+ 'new_version[Auto-write a rockspec for a new version of a rock]'
+ 'pack[Create a rock, packing sources or binaries]'
+ 'path[Return the currently configured package path]'
+ 'purge[Remove all installed rocks from a tree]'
+ 'remove[Uninstall a rock]'
+ 'search[Query the LuaRocks servers]'
+ 'show[Show information about an installed rock]'
+ 'unpack[Unpack the contents of a rock]'
+ 'upload[Upload a rockspec to the public rocks repository]'
+ 'write_rockspect[Write a template for a rockspec file]'
+)
+
+# `build` command receives as an argument a .rockspec file, or external rock and afterwards a version
+local make_command_options=(
+ '--pack-binary-rock[Produce a .rock file with the contents of compilation inside the current directory instead of installing it]'
+ '--keep[Do not remove previously installed versions of the rock after building a new one]'
+ '--branch=[Override the `source.branch` field in the loaded rockspec]:NAME:{_message "branch name"}'
+)
+local option_deps_mode='--deps-mode=[How to handle dependencies. Four modes are supported:MODE:_luarocks_build_deps_mode'
+local build_command_options=(
+ "${make_command_options[@]}"
+ '--only-deps[Installs only the dependencies of the rock]'
+ $option_deps_mode
+)
+_luarocks_build_deps_mode(){
+ local modes=(
+ 'all:use all trees from the rocks_trees list for finding dependencies'
+ 'one:use only the current tree (possibly set with --tree)'
+ 'order:use trees based on order (use the current tree and all trees below it on the rocks_trees list)'
+ 'none:ignore dependencies altogether'
+ )
+ _describe 'dependencies mode' modes
+}
+
+# `config` command sets a flag in the format VAR=VALUE
+local config_command_options=(
+ '--lua-incdir[Path to Lua header files]'
+ '--lua-libdir[Path to Lua library files]'
+ '--lua-ver[Lua version (in major.minor format)]'
+ '--system-config[Location of the system config file]'
+ '--user-config[Location of the user config file]'
+ '--rock-trees[Rocks trees in useFirst the user tree, then the system tree]'
+)
+
+# `doc` command ... TODO: what kind of argument it receives
+local doc_command_options=(
+ '--home[Open the home page of project]'
+ '--list[List documentation files only]'
+)
+
+# `download` command receives an argument of an external only rockspec
+local download_command_options=(
+ '--all[Download all files if there are multiple matches]'
+ '--source[Download .src.rock if available]'
+ '--rockspec[Download .rockspec if available]'
+ '--arch=[Download rock for a specific architecture]:ARCH:_luarocks_architecture'
+)
+_luarocks_architecture(){
+}
+
+# `help` command receives an argument of an internal command
+
+# `install` command receives the same argument as the build command and it accepts the same options as well
+
+# `lint` command receives an argument of a rockspec file
+
+# `list` command receives only options
+local list_command_options=(
+ '--outdated[List only rocks for which there is a higher version available in the rocks server]'
+ '--porcelain[Produce machine-friendly output]'
+)
+
+# `make` command receives an argument of a rockspec file
+# it's options were already described above.
+
+# `new_version` command receives an argument a .rockspec file, or external rock and afterwards a version and optionally afterwards a URL
+local new_version_command_options=(
+ '--tag=[if no version is specified, this option'"'"'s argument is used instead]:TAG:__git_tag'
+)
+
+# `pack` command receives as an argument a .rockspec file, or external rock and afterwards a version
+
+# `path` command receives only options
+local path_command_options=(
+ '--bin[Adds the system path to the output]'
+ '--append[Appends the paths to the existing paths]'
+ '--lr-path[Exports the Lua path (not formatted as shell command)]'
+ '--lr-cpath[Exports the Lua cpath (not formatted as shell command)]'
+ '--lr-bin[Exports the system path (not formatted as shell command)]'
+)
+
+# `purge` command receives only options, --tree is mandatory, --force can be used only in conjunction with --old-versions
+local option_force='--force[Force removing old versions when]'
+local purge_command_options=(
+ '--old-versions[Keep the highest-numbered version of each rock and remove the other ones]'
+ $option_force
+)
+
+
+# `remove` command receives as an argument a name of a locally installed rock
+local option_force_fast='--force-fast[works like --force but doesn'"'"'t reports forced removals]'
+local remove_command_options=(
+ $option_deps_mode
+ $option_force
+ $option_force_fast
+)
+
+# `search` command receives as an argument only a string as a search query
+local search_command_options=(
+ '--source[Return only rockspecs and source rocks]'
+ '--binary[Return only pure Lua and binary rocks (rocks that can be used with the "install" command without requiring a C toolchain)]'
+ '--all[List all contents of the server that are suitable to this platform, do not filter by name]'
+)
+
+# `show` command receives as an argument only an installed rock
+local show_command_options=(
+ '--home[home page of project]'
+ '--modules[all modules provided by this package as used by require()]'
+ '--deps[packages this package depends on]'
+ '--rockspec[the full path of the rockspec file]'
+ '--mversion[the package version]'
+ '--rock-tree[local tree where rock is installed]'
+ '--rock-dir[data directory of the installed rock]'
+)
+
+# `unpack` command receives as an argument a rock package or an external rock and afterwards a version
+local unpack_command_options=(
+ '--force[Unpack files even if the output directory already exists]'
+)
+
+# `upload` command receives as an argument a rockspec file with .src.rock extension
+local upload_command_options=(
+ '--skip-pack[Do not pack and send source rock]'
+ '--api-key=[Give it an API key]:KEY:{_message "api key"}'
+ '--force[Replace existing rockspec if the same revision of a module already exists]'
+)
+
+# `write_rockspec` command receives as an argument a name and a version with optionally a URL/PATH
+
+local write_rockspec_command_options=(
+ '--output=[Write the rockspec with the given filename]:FILE:_files'
+ '--license=[A license string, ]:LICENSE:{_message -e "write a license string such as "MIT/X11" or "GNU GPL v3"}'
+ '--summary=[A short one-line description summary]:SUMMARY_TEXT:{_message -e "write a short summary of the rock"}'
+ '--detailed=[A longer description string]:DETAILED_TEXT:{_message -e "write a detailed description of the rock"}'
+ '--homepage=[Project homepage]:URL:_luarocks_write_rockspec_homepage'
+ '--lua-version=[Supported Lua versions]:LUA_VER:_luarocks_version'
+ '--rockspec-format=[Rockspec format version, such as "1.0" or "1.1"]:VER: '
+ '--tag=[Tag to use. Will attempt to extract version number from it]:TAG:__git_tag'
+ '--lib=[A comma-separated list of libraries that C files need to link to]:_luarocks_write_rockspec_lib'
+)
+_luarocks_write_rockspec_lib(){
+}
+# TODO
+_luarocks_version(){
+ _values -s ,
+}
--
2.17.0
^ permalink raw reply [flat|nested] 28+ messages in thread
* [PATCH 02/25] Remove architecture related option completion.
2018-05-26 15:06 [PATCH 00/25] *** Add completion for luarocks *** doron.behar
2018-05-26 15:06 ` [PATCH 01/25] Add variables for all commands and options doron.behar
@ 2018-05-26 15:06 ` doron.behar
2018-05-26 15:06 ` [PATCH 03/25] Add marker style comments doron.behar
` (23 subsequent siblings)
25 siblings, 0 replies; 28+ messages in thread
From: doron.behar @ 2018-05-26 15:06 UTC (permalink / raw)
To: zsh-workers
From: Doron Behar <doron.behar@gmail.com>
---
Completion/Unix/Command/_luarocks | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/Completion/Unix/Command/_luarocks b/Completion/Unix/Command/_luarocks
index 753fdb381..6d5cb35bd 100644
--- a/Completion/Unix/Command/_luarocks
+++ b/Completion/Unix/Command/_luarocks
@@ -75,10 +75,8 @@ local download_command_options=(
'--all[Download all files if there are multiple matches]'
'--source[Download .src.rock if available]'
'--rockspec[Download .rockspec if available]'
- '--arch=[Download rock for a specific architecture]:ARCH:_luarocks_architecture'
+ '--arch=[Download rock for a specific architecture]:ARCH:'
)
-_luarocks_architecture(){
-}
# `help` command receives an argument of an internal command
--
2.17.0
^ permalink raw reply [flat|nested] 28+ messages in thread
* [PATCH 03/25] Add marker style comments.
2018-05-26 15:06 [PATCH 00/25] *** Add completion for luarocks *** doron.behar
2018-05-26 15:06 ` [PATCH 01/25] Add variables for all commands and options doron.behar
2018-05-26 15:06 ` [PATCH 02/25] Remove architecture related option completion doron.behar
@ 2018-05-26 15:06 ` doron.behar
2018-05-26 15:06 ` [PATCH 04/25] Remove variables and use their contents directly doron.behar
` (22 subsequent siblings)
25 siblings, 0 replies; 28+ messages in thread
From: doron.behar @ 2018-05-26 15:06 UTC (permalink / raw)
To: zsh-workers
From: Doron Behar <doron.behar@gmail.com>
---
Completion/Unix/Command/_luarocks | 92 +++++++++++++++++--------------
1 file changed, 51 insertions(+), 41 deletions(-)
diff --git a/Completion/Unix/Command/_luarocks b/Completion/Unix/Command/_luarocks
index 6d5cb35bd..bb5588251 100644
--- a/Completion/Unix/Command/_luarocks
+++ b/Completion/Unix/Command/_luarocks
@@ -1,5 +1,6 @@
#compdef luarocks
+# {{{ General options
local general_options=(
'(--server --only-server)--server=[Fetch rocks/rockspecs from this server]:HOST:_hosts'
'(--server --only-server)--only-server=[Fetch rocks/rockspecs from this server only]:HOST:_hosts'
@@ -9,7 +10,8 @@ local general_options=(
'--verbose[Display verbose output of commands executed]'
'--timeout=[Timeout on network operations]:SECONDS:{_message "timeout (seconds)"}'
)
-# SYNOPSIS: /usr/bin/luarocks [--server=<server> | --only-server=<server>] [--tree=<tree>] [VAR=VALUE]... <command> [<argument>]
+# }}}
+# {{{ All commands
local commands=(
'build[Build/compile a rock]'
'config[Query information about the LuaRocks configuration]'
@@ -31,8 +33,8 @@ local commands=(
'upload[Upload a rockspec to the public rocks repository]'
'write_rockspect[Write a template for a rockspec file]'
)
-
-# `build` command receives as an argument a .rockspec file, or external rock and afterwards a version
+# }}}
+# {{{ `build` command receives as an argument a .rockspec file, or external rock and afterwards a version
local make_command_options=(
'--pack-binary-rock[Produce a .rock file with the contents of compilation inside the current directory instead of installing it]'
'--keep[Do not remove previously installed versions of the rock after building a new one]'
@@ -53,8 +55,8 @@ _luarocks_build_deps_mode(){
)
_describe 'dependencies mode' modes
}
-
-# `config` command sets a flag in the format VAR=VALUE
+# }}}
+# {{{ `config` command sets a flag in the format VAR=VALUE
local config_command_options=(
'--lua-incdir[Path to Lua header files]'
'--lua-libdir[Path to Lua library files]'
@@ -63,44 +65,44 @@ local config_command_options=(
'--user-config[Location of the user config file]'
'--rock-trees[Rocks trees in useFirst the user tree, then the system tree]'
)
-
-# `doc` command ... TODO: what kind of argument it receives
+# }}}
+# {{{ `doc` command ... TODO: what kind of argument it receives
local doc_command_options=(
'--home[Open the home page of project]'
'--list[List documentation files only]'
)
-
-# `download` command receives an argument of an external only rockspec
+# }}}
+# {{{ `download` command receives an argument of an external only rockspec
local download_command_options=(
'--all[Download all files if there are multiple matches]'
'--source[Download .src.rock if available]'
'--rockspec[Download .rockspec if available]'
'--arch=[Download rock for a specific architecture]:ARCH:'
)
-
-# `help` command receives an argument of an internal command
-
-# `install` command receives the same argument as the build command and it accepts the same options as well
-
-# `lint` command receives an argument of a rockspec file
-
-# `list` command receives only options
+# }}}
+# {{{ `help` command receives an argument of an internal command
+# }}}
+# {{{ `install` command receives the same argument as the build command and it accepts the same options as well
+# }}}
+# {{{ `lint` command receives an argument of a rockspec file
+# }}}
+# {{{ `list` command receives only options
local list_command_options=(
'--outdated[List only rocks for which there is a higher version available in the rocks server]'
'--porcelain[Produce machine-friendly output]'
)
-
-# `make` command receives an argument of a rockspec file
+# }}}
+# {{{ `make` command receives an argument of a rockspec file
# it's options were already described above.
-
-# `new_version` command receives an argument a .rockspec file, or external rock and afterwards a version and optionally afterwards a URL
+# }}}
+# {{{ `new_version` command receives an argument a .rockspec file, or external rock and afterwards a version and optionally afterwards a URL
local new_version_command_options=(
'--tag=[if no version is specified, this option'"'"'s argument is used instead]:TAG:__git_tag'
)
-
-# `pack` command receives as an argument a .rockspec file, or external rock and afterwards a version
-
-# `path` command receives only options
+# }}}
+# {{{ `pack` command receives as an argument a .rockspec file, or external rock and afterwards a version
+# }}}
+# {{{ `path` command receives only options
local path_command_options=(
'--bin[Adds the system path to the output]'
'--append[Appends the paths to the existing paths]'
@@ -108,31 +110,30 @@ local path_command_options=(
'--lr-cpath[Exports the Lua cpath (not formatted as shell command)]'
'--lr-bin[Exports the system path (not formatted as shell command)]'
)
-
-# `purge` command receives only options, --tree is mandatory, --force can be used only in conjunction with --old-versions
+# }}}
+# {{{ `purge` command receives only options, --tree is mandatory, --force can be used only in conjunction with --old-versions
local option_force='--force[Force removing old versions when]'
local purge_command_options=(
'--old-versions[Keep the highest-numbered version of each rock and remove the other ones]'
$option_force
)
-
-
-# `remove` command receives as an argument a name of a locally installed rock
+# }}}
+# {{{ `remove` command receives as an argument a name of a locally installed rock
local option_force_fast='--force-fast[works like --force but doesn'"'"'t reports forced removals]'
local remove_command_options=(
$option_deps_mode
$option_force
$option_force_fast
)
-
-# `search` command receives as an argument only a string as a search query
+# }}}
+# {{{ `search` command receives as an argument only a string as a search query
local search_command_options=(
'--source[Return only rockspecs and source rocks]'
'--binary[Return only pure Lua and binary rocks (rocks that can be used with the "install" command without requiring a C toolchain)]'
'--all[List all contents of the server that are suitable to this platform, do not filter by name]'
)
-
-# `show` command receives as an argument only an installed rock
+# }}}
+# {{{ `show` command receives as an argument only an installed rock
local show_command_options=(
'--home[home page of project]'
'--modules[all modules provided by this package as used by require()]'
@@ -142,21 +143,20 @@ local show_command_options=(
'--rock-tree[local tree where rock is installed]'
'--rock-dir[data directory of the installed rock]'
)
-
-# `unpack` command receives as an argument a rock package or an external rock and afterwards a version
+# }}}
+# {{{ `unpack` command receives as an argument a rock package or an external rock and afterwards a version
local unpack_command_options=(
'--force[Unpack files even if the output directory already exists]'
)
-
-# `upload` command receives as an argument a rockspec file with .src.rock extension
+# }}}
+# {{{ `upload` command receives as an argument a rockspec file with .src.rock extension
local upload_command_options=(
'--skip-pack[Do not pack and send source rock]'
'--api-key=[Give it an API key]:KEY:{_message "api key"}'
'--force[Replace existing rockspec if the same revision of a module already exists]'
)
-
-# `write_rockspec` command receives as an argument a name and a version with optionally a URL/PATH
-
+# }}}
+# {{{ `write_rockspec` command receives as an argument a name and a version with optionally a URL/PATH
local write_rockspec_command_options=(
'--output=[Write the rockspec with the given filename]:FILE:_files'
'--license=[A license string, ]:LICENSE:{_message -e "write a license string such as "MIT/X11" or "GNU GPL v3"}'
@@ -174,3 +174,13 @@ _luarocks_write_rockspec_lib(){
_luarocks_version(){
_values -s ,
}
+# }}}
+
+# {{{ Helpers
+_luarocks_commands(){
+ _describe 'command' commands
+}
+# }}}
+
+# The real thing
+_arguments "${general_options[@]}" '*:COMMAND:_luarocks_commands'
--
2.17.0
^ permalink raw reply [flat|nested] 28+ messages in thread
* [PATCH 04/25] Remove variables and use their contents directly.
2018-05-26 15:06 [PATCH 00/25] *** Add completion for luarocks *** doron.behar
` (2 preceding siblings ...)
2018-05-26 15:06 ` [PATCH 03/25] Add marker style comments doron.behar
@ 2018-05-26 15:06 ` doron.behar
2018-05-26 15:06 ` [PATCH 05/25] Add curcontext case for every subcommand doron.behar
` (21 subsequent siblings)
25 siblings, 0 replies; 28+ messages in thread
From: doron.behar @ 2018-05-26 15:06 UTC (permalink / raw)
To: zsh-workers
From: Doron Behar <doron.behar@gmail.com>
---
Completion/Unix/Command/_luarocks | 108 +++++++++++++++++++-----------
1 file changed, 69 insertions(+), 39 deletions(-)
diff --git a/Completion/Unix/Command/_luarocks b/Completion/Unix/Command/_luarocks
index bb5588251..b14f6a8b3 100644
--- a/Completion/Unix/Command/_luarocks
+++ b/Completion/Unix/Command/_luarocks
@@ -1,39 +1,5 @@
#compdef luarocks
-# {{{ General options
-local general_options=(
- '(--server --only-server)--server=[Fetch rocks/rockspecs from this server]:HOST:_hosts'
- '(--server --only-server)--only-server=[Fetch rocks/rockspecs from this server only]:HOST:_hosts'
- '--only-sources=[Restrict downloads to paths matching the given URL]:URL:_urls'
- '--tree=[Which tree to operate on]:TREE:'
- '--local[Use the tree in the user'"'"'s home directory]'
- '--verbose[Display verbose output of commands executed]'
- '--timeout=[Timeout on network operations]:SECONDS:{_message "timeout (seconds)"}'
-)
-# }}}
-# {{{ All commands
-local commands=(
- 'build[Build/compile a rock]'
- 'config[Query information about the LuaRocks configuration]'
- 'doc[Show documentation for an installed rock]'
- 'download[Download a specific rock file from a rocks server]'
- 'help[Help on commands]'
- 'install[Install a rock]'
- 'lint[Check syntax of a rockspec]'
- 'list[List currently installed rocks]'
- 'make[Compile package in current directory using a rockspec]'
- 'new_version[Auto-write a rockspec for a new version of a rock]'
- 'pack[Create a rock, packing sources or binaries]'
- 'path[Return the currently configured package path]'
- 'purge[Remove all installed rocks from a tree]'
- 'remove[Uninstall a rock]'
- 'search[Query the LuaRocks servers]'
- 'show[Show information about an installed rock]'
- 'unpack[Unpack the contents of a rock]'
- 'upload[Upload a rockspec to the public rocks repository]'
- 'write_rockspect[Write a template for a rockspec file]'
-)
-# }}}
# {{{ `build` command receives as an argument a .rockspec file, or external rock and afterwards a version
local make_command_options=(
'--pack-binary-rock[Produce a .rock file with the contents of compilation inside the current directory instead of installing it]'
@@ -55,6 +21,8 @@ _luarocks_build_deps_mode(){
)
_describe 'dependencies mode' modes
}
+_luarocks_build(){
+}
# }}}
# {{{ `config` command sets a flag in the format VAR=VALUE
local config_command_options=(
@@ -65,12 +33,16 @@ local config_command_options=(
'--user-config[Location of the user config file]'
'--rock-trees[Rocks trees in useFirst the user tree, then the system tree]'
)
+_luarocks_config(){
+}
# }}}
# {{{ `doc` command ... TODO: what kind of argument it receives
local doc_command_options=(
'--home[Open the home page of project]'
'--list[List documentation files only]'
)
+_luarocks_doc(){
+}
# }}}
# {{{ `download` command receives an argument of an external only rockspec
local download_command_options=(
@@ -79,28 +51,44 @@ local download_command_options=(
'--rockspec[Download .rockspec if available]'
'--arch=[Download rock for a specific architecture]:ARCH:'
)
+_luarocks_download(){
+}
# }}}
# {{{ `help` command receives an argument of an internal command
+_luarocks_help(){
+}
# }}}
# {{{ `install` command receives the same argument as the build command and it accepts the same options as well
+_luarocks_install(){
+}
# }}}
# {{{ `lint` command receives an argument of a rockspec file
+_luarocks_lint(){
+}
# }}}
# {{{ `list` command receives only options
local list_command_options=(
'--outdated[List only rocks for which there is a higher version available in the rocks server]'
'--porcelain[Produce machine-friendly output]'
)
+_luarocks_list(){
+}
# }}}
# {{{ `make` command receives an argument of a rockspec file
# it's options were already described above.
+_luarocks_make(){
+}
# }}}
# {{{ `new_version` command receives an argument a .rockspec file, or external rock and afterwards a version and optionally afterwards a URL
local new_version_command_options=(
'--tag=[if no version is specified, this option'"'"'s argument is used instead]:TAG:__git_tag'
)
+_luarocks_new_version(){
+}
# }}}
# {{{ `pack` command receives as an argument a .rockspec file, or external rock and afterwards a version
+_luarocks_pack(){
+}
# }}}
# {{{ `path` command receives only options
local path_command_options=(
@@ -110,6 +98,8 @@ local path_command_options=(
'--lr-cpath[Exports the Lua cpath (not formatted as shell command)]'
'--lr-bin[Exports the system path (not formatted as shell command)]'
)
+_luarocks_path(){
+}
# }}}
# {{{ `purge` command receives only options, --tree is mandatory, --force can be used only in conjunction with --old-versions
local option_force='--force[Force removing old versions when]'
@@ -117,6 +107,8 @@ local purge_command_options=(
'--old-versions[Keep the highest-numbered version of each rock and remove the other ones]'
$option_force
)
+_luarocks_purge(){
+}
# }}}
# {{{ `remove` command receives as an argument a name of a locally installed rock
local option_force_fast='--force-fast[works like --force but doesn'"'"'t reports forced removals]'
@@ -125,6 +117,8 @@ local remove_command_options=(
$option_force
$option_force_fast
)
+_luarocks_remove(){
+}
# }}}
# {{{ `search` command receives as an argument only a string as a search query
local search_command_options=(
@@ -132,6 +126,8 @@ local search_command_options=(
'--binary[Return only pure Lua and binary rocks (rocks that can be used with the "install" command without requiring a C toolchain)]'
'--all[List all contents of the server that are suitable to this platform, do not filter by name]'
)
+_luarocks_search(){
+}
# }}}
# {{{ `show` command receives as an argument only an installed rock
local show_command_options=(
@@ -143,11 +139,15 @@ local show_command_options=(
'--rock-tree[local tree where rock is installed]'
'--rock-dir[data directory of the installed rock]'
)
+_luarocks_show(){
+}
# }}}
# {{{ `unpack` command receives as an argument a rock package or an external rock and afterwards a version
local unpack_command_options=(
'--force[Unpack files even if the output directory already exists]'
)
+_luarocks_unpack(){
+}
# }}}
# {{{ `upload` command receives as an argument a rockspec file with .src.rock extension
local upload_command_options=(
@@ -155,6 +155,8 @@ local upload_command_options=(
'--api-key=[Give it an API key]:KEY:{_message "api key"}'
'--force[Replace existing rockspec if the same revision of a module already exists]'
)
+_luarocks_upload(){
+}
# }}}
# {{{ `write_rockspec` command receives as an argument a name and a version with optionally a URL/PATH
local write_rockspec_command_options=(
@@ -176,11 +178,39 @@ _luarocks_version(){
}
# }}}
-# {{{ Helpers
-_luarocks_commands(){
+# The real thing
+_luarocks_command(){
+ local -a commands=(
+ build:'Build/compile a rock'
+ config:'Query information about the LuaRocks configuration'
+ doc:'Show documentation for an installed rock'
+ download:'Download a specific rock file from a rocks server'
+ help:'Help on commands'
+ install:'Install a rock'
+ lint:'Check syntax of a rockspec'
+ list:'List currently installed rocks'
+ make:'Compile package in current directory using a rockspec'
+ new_version:'Auto-write a rockspec for a new version of a rock'
+ pack:'Create a rock, packing sources or binaries'
+ path:'Return the currently configured package path'
+ purge:'Remove all installed rocks from a tree'
+ remove:'Uninstall a rock'
+ search:'Query the LuaRocks servers'
+ show:'Show information about an installed rock'
+ unpack:'Unpack the contents of a rock'
+ upload:'Upload a rockspec to the public rocks repository'
+ write_rockspect:'Write a template for a rockspec file'
+ )
_describe 'command' commands
}
-# }}}
-# The real thing
-_arguments "${general_options[@]}" '*:COMMAND:_luarocks_commands'
+_arguments \
+ '(--server --only-server)--server=[Fetch rocks/rockspecs from this server]:HOST:_hosts' \
+ '(--server --only-server)--only-server=[Fetch rocks/rockspecs from this server only]:HOST:_hosts' \
+ '--only-sources=[Restrict downloads to paths matching the given URL]:URL:_urls' \
+ '--tree=[Which tree to operate on]:TREE:{_files -/}' \
+ '--local[Use the tree in the user'"'"'s home directory]' \
+ '--verbose[Display verbose output of commands executed]' \
+ '--timeout=[Timeout on network operations]:SECONDS:{_message "timeout (seconds)"}' \
+ '*:COMMAND:_luarocks_command'
+
--
2.17.0
^ permalink raw reply [flat|nested] 28+ messages in thread
* [PATCH 05/25] Add curcontext case for every subcommand.
2018-05-26 15:06 [PATCH 00/25] *** Add completion for luarocks *** doron.behar
` (3 preceding siblings ...)
2018-05-26 15:06 ` [PATCH 04/25] Remove variables and use their contents directly doron.behar
@ 2018-05-26 15:06 ` doron.behar
2018-05-26 15:06 ` [PATCH 06/25] Use better naming scheme for common helpers doron.behar
` (20 subsequent siblings)
25 siblings, 0 replies; 28+ messages in thread
From: doron.behar @ 2018-05-26 15:06 UTC (permalink / raw)
To: zsh-workers
From: Doron Behar <doron.behar@gmail.com>
Thanks `src/_android`!
---
Completion/Unix/Command/_luarocks | 74 +++++++++++++++++++++++++++++--
1 file changed, 70 insertions(+), 4 deletions(-)
diff --git a/Completion/Unix/Command/_luarocks b/Completion/Unix/Command/_luarocks
index b14f6a8b3..1b3767b17 100644
--- a/Completion/Unix/Command/_luarocks
+++ b/Completion/Unix/Command/_luarocks
@@ -175,6 +175,7 @@ _luarocks_write_rockspec_lib(){
# TODO
_luarocks_version(){
_values -s ,
+_luarocks_write_rockspec(){
}
# }}}
@@ -199,12 +200,12 @@ _luarocks_command(){
show:'Show information about an installed rock'
unpack:'Unpack the contents of a rock'
upload:'Upload a rockspec to the public rocks repository'
- write_rockspect:'Write a template for a rockspec file'
+ write_rockspec:'Write a template for a rockspec file'
)
- _describe 'command' commands
+ _describe -t commands 'command' commands "$@"
}
-_arguments \
+_arguments -C \
'(--server --only-server)--server=[Fetch rocks/rockspecs from this server]:HOST:_hosts' \
'(--server --only-server)--only-server=[Fetch rocks/rockspecs from this server only]:HOST:_hosts' \
'--only-sources=[Restrict downloads to paths matching the given URL]:URL:_urls' \
@@ -212,5 +213,70 @@ _arguments \
'--local[Use the tree in the user'"'"'s home directory]' \
'--verbose[Display verbose output of commands executed]' \
'--timeout=[Timeout on network operations]:SECONDS:{_message "timeout (seconds)"}' \
- '*:COMMAND:_luarocks_command'
+ '1: :_luarocks_command' \
+ '*::arg:->args'
+case "$state" in
+ (args)
+ curcontext="${curcontext%:*:*}:luarocks_${words[1]}:"
+ case $words[1] in
+ (build)
+ _luarocks_build
+ ;;
+ (config)
+ _luarocks_config
+ ;;
+ (doc)
+ _luarocks_doc
+ ;;
+ (download)
+ _luarocks_download
+ ;;
+ (help)
+ _luarocks_help
+ ;;
+ (install)
+ _luarocks_install
+ ;;
+ (lint)
+ _luarocks_lint
+ ;;
+ (list)
+ _luarocks_list
+ ;;
+ (make)
+ _luarocks_make
+ ;;
+ (new_version)
+ _luarocks_new_version
+ ;;
+ (pack)
+ _luarocks_pack
+ ;;
+ (path)
+ _luarocks_path
+ ;;
+ (purge)
+ _luarocks_purge
+ ;;
+ (remove)
+ _luarocks_remove
+ ;;
+ (search)
+ _luarocks_search
+ ;;
+ (show)
+ _luarocks_show
+ ;;
+ (unpack)
+ _luarocks_unpack
+ ;;
+ (upload)
+ _luarocks_upload
+ ;;
+ (write_rockspec)
+ _luarocks_write_rockspec
+ ;;
+ esac
+ ;;
+esac
--
2.17.0
^ permalink raw reply [flat|nested] 28+ messages in thread
* [PATCH 06/25] Use better naming scheme for common helpers.
2018-05-26 15:06 [PATCH 00/25] *** Add completion for luarocks *** doron.behar
` (4 preceding siblings ...)
2018-05-26 15:06 ` [PATCH 05/25] Add curcontext case for every subcommand doron.behar
@ 2018-05-26 15:06 ` doron.behar
2018-05-26 15:06 ` [PATCH 07/25] Write better sub commands comments doron.behar
` (19 subsequent siblings)
25 siblings, 0 replies; 28+ messages in thread
From: doron.behar @ 2018-05-26 15:06 UTC (permalink / raw)
To: zsh-workers
From: Doron Behar <doron.behar@gmail.com>
Rename `_luarocks_build_deps_mode` to `__luarocks_deps_mode`.
Rename `_luarocks_version` to `__luarocks_version`.
---
Completion/Unix/Command/_luarocks | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/Completion/Unix/Command/_luarocks b/Completion/Unix/Command/_luarocks
index 1b3767b17..990582d99 100644
--- a/Completion/Unix/Command/_luarocks
+++ b/Completion/Unix/Command/_luarocks
@@ -6,13 +6,13 @@ local make_command_options=(
'--keep[Do not remove previously installed versions of the rock after building a new one]'
'--branch=[Override the `source.branch` field in the loaded rockspec]:NAME:{_message "branch name"}'
)
-local option_deps_mode='--deps-mode=[How to handle dependencies. Four modes are supported:MODE:_luarocks_build_deps_mode'
+local option_deps_mode='--deps-mode=[How to handle dependencies. Four modes are supported:MODE:__luarocks_deps_mode'
local build_command_options=(
"${make_command_options[@]}"
'--only-deps[Installs only the dependencies of the rock]'
$option_deps_mode
)
-_luarocks_build_deps_mode(){
+__luarocks_deps_mode(){
local modes=(
'all:use all trees from the rocks_trees list for finding dependencies'
'one:use only the current tree (possibly set with --tree)'
@@ -165,7 +165,7 @@ local write_rockspec_command_options=(
'--summary=[A short one-line description summary]:SUMMARY_TEXT:{_message -e "write a short summary of the rock"}'
'--detailed=[A longer description string]:DETAILED_TEXT:{_message -e "write a detailed description of the rock"}'
'--homepage=[Project homepage]:URL:_luarocks_write_rockspec_homepage'
- '--lua-version=[Supported Lua versions]:LUA_VER:_luarocks_version'
+ '--lua-version=[Supported Lua versions]:LUA_VER:__luarocks_version'
'--rockspec-format=[Rockspec format version, such as "1.0" or "1.1"]:VER: '
'--tag=[Tag to use. Will attempt to extract version number from it]:TAG:__git_tag'
'--lib=[A comma-separated list of libraries that C files need to link to]:_luarocks_write_rockspec_lib'
@@ -173,7 +173,7 @@ local write_rockspec_command_options=(
_luarocks_write_rockspec_lib(){
}
# TODO
-_luarocks_version(){
+__luarocks_version(){
_values -s ,
_luarocks_write_rockspec(){
}
--
2.17.0
^ permalink raw reply [flat|nested] 28+ messages in thread
* [PATCH 07/25] Write better sub commands comments.
2018-05-26 15:06 [PATCH 00/25] *** Add completion for luarocks *** doron.behar
` (5 preceding siblings ...)
2018-05-26 15:06 ` [PATCH 06/25] Use better naming scheme for common helpers doron.behar
@ 2018-05-26 15:06 ` doron.behar
2018-05-26 15:06 ` [PATCH 08/25] Add helpers section doron.behar
` (18 subsequent siblings)
25 siblings, 0 replies; 28+ messages in thread
From: doron.behar @ 2018-05-26 15:06 UTC (permalink / raw)
To: zsh-workers
From: Doron Behar <doron.behar@gmail.com>
---
Completion/Unix/Command/_luarocks | 87 ++++++++++++++++++++++++-------
1 file changed, 67 insertions(+), 20 deletions(-)
diff --git a/Completion/Unix/Command/_luarocks b/Completion/Unix/Command/_luarocks
index 990582d99..b9f6c8af6 100644
--- a/Completion/Unix/Command/_luarocks
+++ b/Completion/Unix/Command/_luarocks
@@ -1,6 +1,9 @@
#compdef luarocks
-# {{{ `build` command receives as an argument a .rockspec file, or external rock and afterwards a version
+# {{{ `build` command
+# arguments:
+# - must: .rockspec file / external rock
+# - optional: version (only when chossing external rock)
local make_command_options=(
'--pack-binary-rock[Produce a .rock file with the contents of compilation inside the current directory instead of installing it]'
'--keep[Do not remove previously installed versions of the rock after building a new one]'
@@ -24,7 +27,9 @@ __luarocks_deps_mode(){
_luarocks_build(){
}
# }}}
-# {{{ `config` command sets a flag in the format VAR=VALUE
+# {{{ `config` command
+# arguments:
+# - must: VAR=VALUE
local config_command_options=(
'--lua-incdir[Path to Lua header files]'
'--lua-libdir[Path to Lua library files]'
@@ -36,7 +41,9 @@ local config_command_options=(
_luarocks_config(){
}
# }}}
-# {{{ `doc` command ... TODO: what kind of argument it receives
+# {{{ `doc` command
+# arguments:
+# - TODO
local doc_command_options=(
'--home[Open the home page of project]'
'--list[List documentation files only]'
@@ -44,7 +51,9 @@ local doc_command_options=(
_luarocks_doc(){
}
# }}}
-# {{{ `download` command receives an argument of an external only rockspec
+# {{{ `download` command
+# arguments:
+# - must: external only rockspec
local download_command_options=(
'--all[Download all files if there are multiple matches]'
'--source[Download .src.rock if available]'
@@ -54,19 +63,28 @@ local download_command_options=(
_luarocks_download(){
}
# }}}
-# {{{ `help` command receives an argument of an internal command
+# {{{ `help` command
+# arguments:
+# must: luarocks sub command
_luarocks_help(){
}
# }}}
-# {{{ `install` command receives the same argument as the build command and it accepts the same options as well
+# {{{ `install` command
+# arguments:
+# - must: .rockspec file, or external rock
+# - optional: version
+# NOTE: it receives the same argument as the build command and it accepts the same options as well
_luarocks_install(){
}
# }}}
-# {{{ `lint` command receives an argument of a rockspec file
+# {{{ `lint` command
+# arguments:
+# must: rockspec file (first and last)
_luarocks_lint(){
}
# }}}
-# {{{ `list` command receives only options
+# {{{ `list` command
+# NOTE: receives only options
local list_command_options=(
'--outdated[List only rocks for which there is a higher version available in the rocks server]'
'--porcelain[Produce machine-friendly output]'
@@ -74,23 +92,33 @@ local list_command_options=(
_luarocks_list(){
}
# }}}
-# {{{ `make` command receives an argument of a rockspec file
-# it's options were already described above.
+# {{{ `make` command
+# arguments:
+# - optional: rockspec file
+# NOTE: it's options were already described above.
_luarocks_make(){
}
# }}}
-# {{{ `new_version` command receives an argument a .rockspec file, or external rock and afterwards a version and optionally afterwards a URL
+# {{{ `new_version` command
+# arguments:
+# - optional: .rockspec file / external rock
+# - optional: version (unless a --tag was given)
+# - optional: URL
local new_version_command_options=(
'--tag=[if no version is specified, this option'"'"'s argument is used instead]:TAG:__git_tag'
)
_luarocks_new_version(){
}
# }}}
-# {{{ `pack` command receives as an argument a .rockspec file, or external rock and afterwards a version
+# {{{ `pack` command
+# arguments:
+# - must: .rockspec file / external rock
+# - optional: version
_luarocks_pack(){
}
# }}}
-# {{{ `path` command receives only options
+# {{{ `path` command
+# NOTE: receives only options
local path_command_options=(
'--bin[Adds the system path to the output]'
'--append[Appends the paths to the existing paths]'
@@ -101,7 +129,9 @@ local path_command_options=(
_luarocks_path(){
}
# }}}
-# {{{ `purge` command receives only options, --tree is mandatory, --force can be used only in conjunction with --old-versions
+# {{{ `purge` command
+# NOTE: receives only options yet --tree is mandatory
+# NOTE: --force can be used only in conjunction with --old-versions
local option_force='--force[Force removing old versions when]'
local purge_command_options=(
'--old-versions[Keep the highest-numbered version of each rock and remove the other ones]'
@@ -110,7 +140,10 @@ local purge_command_options=(
_luarocks_purge(){
}
# }}}
-# {{{ `remove` command receives as an argument a name of a locally installed rock
+# {{{ `remove` command
+# arguments:
+# - must: locally installed rock
+# - optional: version
local option_force_fast='--force-fast[works like --force but doesn'"'"'t reports forced removals]'
local remove_command_options=(
$option_deps_mode
@@ -120,7 +153,9 @@ local remove_command_options=(
_luarocks_remove(){
}
# }}}
-# {{{ `search` command receives as an argument only a string as a search query
+# {{{ `search` command
+# arguments:
+# - must: string as a search query
local search_command_options=(
'--source[Return only rockspecs and source rocks]'
'--binary[Return only pure Lua and binary rocks (rocks that can be used with the "install" command without requiring a C toolchain)]'
@@ -129,7 +164,9 @@ local search_command_options=(
_luarocks_search(){
}
# }}}
-# {{{ `show` command receives as an argument only an installed rock
+# {{{ `show` command
+# arguments:
+# - must: installed rock
local show_command_options=(
'--home[home page of project]'
'--modules[all modules provided by this package as used by require()]'
@@ -142,14 +179,19 @@ local show_command_options=(
_luarocks_show(){
}
# }}}
-# {{{ `unpack` command receives as an argument a rock package or an external rock and afterwards a version
+# {{{ `unpack` command
+# arguments:
+# - must: rock package file / an external rock
+# - optional: version (only when chossing external rock)
local unpack_command_options=(
'--force[Unpack files even if the output directory already exists]'
)
_luarocks_unpack(){
}
# }}}
-# {{{ `upload` command receives as an argument a rockspec file with .src.rock extension
+# {{{ `upload` command
+# arguments:
+# - must: rockspec file with .src.rock extension
local upload_command_options=(
'--skip-pack[Do not pack and send source rock]'
'--api-key=[Give it an API key]:KEY:{_message "api key"}'
@@ -158,7 +200,12 @@ local upload_command_options=(
_luarocks_upload(){
}
# }}}
-# {{{ `write_rockspec` command receives as an argument a name and a version with optionally a URL/PATH
+# {{{ `write_rockspec` command
+# arguments:
+# - optional: name
+# - optional: version
+# - optional: URL / PATH
+# receives as an argument a name and a version with optionally a URL/PATH
local write_rockspec_command_options=(
'--output=[Write the rockspec with the given filename]:FILE:_files'
'--license=[A license string, ]:LICENSE:{_message -e "write a license string such as "MIT/X11" or "GNU GPL v3"}'
--
2.17.0
^ permalink raw reply [flat|nested] 28+ messages in thread
* [PATCH 08/25] Add helpers section.
2018-05-26 15:06 [PATCH 00/25] *** Add completion for luarocks *** doron.behar
` (6 preceding siblings ...)
2018-05-26 15:06 ` [PATCH 07/25] Write better sub commands comments doron.behar
@ 2018-05-26 15:06 ` doron.behar
2018-05-26 15:06 ` [PATCH 09/25] Make *all* helpers functions begin with __luarocks doron.behar
` (17 subsequent siblings)
25 siblings, 0 replies; 28+ messages in thread
From: doron.behar @ 2018-05-26 15:06 UTC (permalink / raw)
To: zsh-workers
From: Doron Behar <doron.behar@gmail.com>
---
Completion/Unix/Command/_luarocks | 65 ++++++++++++++++++++++++-------
1 file changed, 50 insertions(+), 15 deletions(-)
diff --git a/Completion/Unix/Command/_luarocks b/Completion/Unix/Command/_luarocks
index b9f6c8af6..acbc16cb4 100644
--- a/Completion/Unix/Command/_luarocks
+++ b/Completion/Unix/Command/_luarocks
@@ -1,5 +1,55 @@
#compdef luarocks
+# {{{ helper: dependencies mode
+local option_deps_mode='--deps-mode=[How to handle dependencies]:MODE:__luarocks_deps_mode'
+__luarocks_deps_mode(){
+ local modes=(
+ 'all:use all trees from the rocks_trees list for finding dependencies'
+ 'one:use only the current tree (possibly set with --tree)'
+ 'order:use trees based on order (use the current tree and all trees below it on the rocks_trees list)'
+ 'none:ignore dependencies altogether'
+ )
+ _describe 'dependencies mode' modes
+}
+# }}}
+# {{{ helper: versions of an external rock
+__luarocks_rock_version(){
+ for i in {2..${#build_command_options[@]}}; do
+ if [[ ! -z "${words[$i]}" && ! "${words[$i]}" =~ '^-' && ! -f "${words[$i]}" ]]; then
+ # TODO: complete with optional versions
+ _message -e "version for rock ${words[$i]}"
+ return
+ fi
+ done
+}
+# }}}
+# {{{ helper: list of libraries that C files need to link to
+_luarocks_write_rockspec_lib(){
+}
+# }}}
+# {{{ helper: lua versions
+# TODO
+__luarocks_lua_version(){
+ _values -s ,
+}
+# }}}
+# {{{ helper: rockspec file / rockpack (.src.rock file) / external according to demand
+__luarocks_rock(){
+ local -a arguments=()
+ for arg in "$@"; do
+ case $arg in
+ (file)
+ arguments+=(':rock file:{_files -g "*.rockspec"}')
+ ;;
+ (external)
+ arguments+=(':external rock:')
+ ;;
+ esac
+ done
+ _alternative ${arguments[@]}
+}
+# }}}
+
# {{{ `build` command
# arguments:
# - must: .rockspec file / external rock
@@ -9,21 +59,11 @@ local make_command_options=(
'--keep[Do not remove previously installed versions of the rock after building a new one]'
'--branch=[Override the `source.branch` field in the loaded rockspec]:NAME:{_message "branch name"}'
)
-local option_deps_mode='--deps-mode=[How to handle dependencies. Four modes are supported:MODE:__luarocks_deps_mode'
local build_command_options=(
"${make_command_options[@]}"
'--only-deps[Installs only the dependencies of the rock]'
$option_deps_mode
)
-__luarocks_deps_mode(){
- local modes=(
- 'all:use all trees from the rocks_trees list for finding dependencies'
- 'one:use only the current tree (possibly set with --tree)'
- 'order:use trees based on order (use the current tree and all trees below it on the rocks_trees list)'
- 'none:ignore dependencies altogether'
- )
- _describe 'dependencies mode' modes
-}
_luarocks_build(){
}
# }}}
@@ -217,11 +257,6 @@ local write_rockspec_command_options=(
'--tag=[Tag to use. Will attempt to extract version number from it]:TAG:__git_tag'
'--lib=[A comma-separated list of libraries that C files need to link to]:_luarocks_write_rockspec_lib'
)
-_luarocks_write_rockspec_lib(){
-}
-# TODO
-__luarocks_version(){
- _values -s ,
_luarocks_write_rockspec(){
}
# }}}
--
2.17.0
^ permalink raw reply [flat|nested] 28+ messages in thread
* [PATCH 09/25] Make *all* helpers functions begin with __luarocks.
2018-05-26 15:06 [PATCH 00/25] *** Add completion for luarocks *** doron.behar
` (7 preceding siblings ...)
2018-05-26 15:06 ` [PATCH 08/25] Add helpers section doron.behar
@ 2018-05-26 15:06 ` doron.behar
2018-05-26 15:06 ` [PATCH 10/25] Write all simple sub commands completions doron.behar
` (16 subsequent siblings)
25 siblings, 0 replies; 28+ messages in thread
From: doron.behar @ 2018-05-26 15:06 UTC (permalink / raw)
To: zsh-workers
From: Doron Behar <doron.behar@gmail.com>
---
Completion/Unix/Command/_luarocks | 57 ++++++++++++++++---------------
1 file changed, 29 insertions(+), 28 deletions(-)
diff --git a/Completion/Unix/Command/_luarocks b/Completion/Unix/Command/_luarocks
index acbc16cb4..de296a084 100644
--- a/Completion/Unix/Command/_luarocks
+++ b/Completion/Unix/Command/_luarocks
@@ -1,5 +1,31 @@
#compdef luarocks
+# {{{ helper: luarocks commands
+__luarocks_command(){
+ local -a commands=(
+ build:'Build/compile a rock'
+ config:'Query information about the LuaRocks configuration'
+ doc:'Show documentation for an installed rock'
+ download:'Download a specific rock file from a rocks server'
+ help:'Help on commands'
+ install:'Install a rock'
+ lint:'Check syntax of a rockspec'
+ list:'List currently installed rocks'
+ make:'Compile package in current directory using a rockspec'
+ new_version:'Auto-write a rockspec for a new version of a rock'
+ pack:'Create a rock, packing sources or binaries'
+ path:'Return the currently configured package path'
+ purge:'Remove all installed rocks from a tree'
+ remove:'Uninstall a rock'
+ search:'Query the LuaRocks servers'
+ show:'Show information about an installed rock'
+ unpack:'Unpack the contents of a rock'
+ upload:'Upload a rockspec to the public rocks repository'
+ write_rockspec:'Write a template for a rockspec file'
+ )
+ _describe -t commands 'command' commands "$@"
+}
+# }}}
# {{{ helper: dependencies mode
local option_deps_mode='--deps-mode=[How to handle dependencies]:MODE:__luarocks_deps_mode'
__luarocks_deps_mode(){
@@ -24,7 +50,7 @@ __luarocks_rock_version(){
}
# }}}
# {{{ helper: list of libraries that C files need to link to
-_luarocks_write_rockspec_lib(){
+__luarocks_c_libs(){
}
# }}}
# {{{ helper: lua versions
@@ -255,38 +281,13 @@ local write_rockspec_command_options=(
'--lua-version=[Supported Lua versions]:LUA_VER:__luarocks_version'
'--rockspec-format=[Rockspec format version, such as "1.0" or "1.1"]:VER: '
'--tag=[Tag to use. Will attempt to extract version number from it]:TAG:__git_tag'
- '--lib=[A comma-separated list of libraries that C files need to link to]:_luarocks_write_rockspec_lib'
+ '--lib=[A comma-separated list of libraries that C files need to link to]:__luarocks_c_libs'
)
_luarocks_write_rockspec(){
}
# }}}
# The real thing
-_luarocks_command(){
- local -a commands=(
- build:'Build/compile a rock'
- config:'Query information about the LuaRocks configuration'
- doc:'Show documentation for an installed rock'
- download:'Download a specific rock file from a rocks server'
- help:'Help on commands'
- install:'Install a rock'
- lint:'Check syntax of a rockspec'
- list:'List currently installed rocks'
- make:'Compile package in current directory using a rockspec'
- new_version:'Auto-write a rockspec for a new version of a rock'
- pack:'Create a rock, packing sources or binaries'
- path:'Return the currently configured package path'
- purge:'Remove all installed rocks from a tree'
- remove:'Uninstall a rock'
- search:'Query the LuaRocks servers'
- show:'Show information about an installed rock'
- unpack:'Unpack the contents of a rock'
- upload:'Upload a rockspec to the public rocks repository'
- write_rockspec:'Write a template for a rockspec file'
- )
- _describe -t commands 'command' commands "$@"
-}
-
_arguments -C \
'(--server --only-server)--server=[Fetch rocks/rockspecs from this server]:HOST:_hosts' \
'(--server --only-server)--only-server=[Fetch rocks/rockspecs from this server only]:HOST:_hosts' \
@@ -295,7 +296,7 @@ _arguments -C \
'--local[Use the tree in the user'"'"'s home directory]' \
'--verbose[Display verbose output of commands executed]' \
'--timeout=[Timeout on network operations]:SECONDS:{_message "timeout (seconds)"}' \
- '1: :_luarocks_command' \
+ '1: :__luarocks_command' \
'*::arg:->args'
case "$state" in
--
2.17.0
^ permalink raw reply [flat|nested] 28+ messages in thread
* [PATCH 10/25] Write all simple sub commands completions.
2018-05-26 15:06 [PATCH 00/25] *** Add completion for luarocks *** doron.behar
` (8 preceding siblings ...)
2018-05-26 15:06 ` [PATCH 09/25] Make *all* helpers functions begin with __luarocks doron.behar
@ 2018-05-26 15:06 ` doron.behar
2018-05-26 15:06 ` [PATCH 11/25] General internal conventions sync doron.behar
` (15 subsequent siblings)
25 siblings, 0 replies; 28+ messages in thread
From: doron.behar @ 2018-05-26 15:06 UTC (permalink / raw)
To: zsh-workers
From: Doron Behar <doron.behar@gmail.com>
Most importantly, write (using `_cache_` functions) helpers that
complete installed rocks with their descriptions generated with
`luarocks show <>`.
---
Completion/Unix/Command/_luarocks | 125 ++++++++++++++++++++++++++++--
1 file changed, 119 insertions(+), 6 deletions(-)
diff --git a/Completion/Unix/Command/_luarocks b/Completion/Unix/Command/_luarocks
index de296a084..4f3271360 100644
--- a/Completion/Unix/Command/_luarocks
+++ b/Completion/Unix/Command/_luarocks
@@ -59,20 +59,102 @@ __luarocks_lua_version(){
_values -s ,
}
# }}}
-# {{{ helper: rockspec file / rockpack (.src.rock file) / external according to demand
+# {{{ helper: installed rocks cache policy
+___luarocks_installed_rocks_cache_policy(){
+ # the number of seconds since 1970-01-01 the manifest file was modified
+ local manifest_last_date_modified="$(date -r ~/.luarocks/lib/luarocks/rocks-5.3/manifest +%s 2>/dev/null)"
+ # the number of seconds since 1970-01-01 the cache file was modified
+ local cache_last_date_modified="$(date -r $1 +%s 2>/dev/null)"
+ if [[ ! -z ${cache_last_date_modified} && ! -z ${manifest_last_date_modified} ]]; then
+ # if the manifest file is newer then the cache:
+ if [ ${manifest_last_date_modified} -ge ${cache_last_date_modified} ]; then
+ (( 1 ))
+ else
+ (( 0 ))
+ fi
+ fi
+}
+# }}}
+# {{{ helper: installed rocks
+__luarocks_installed_rocks(){
+ local update_policy ret=1
+ zstyle -s ":completion:${curcontext}:" cache-policy update_policy
+ if [[ -z "$update_policy" ]]; then
+ zstyle ":completion:${curcontext}:" cache-policy ___luarocks_installed_rocks_cache_policy
+ fi
+ if _cache_invalid luarocks_installed_list; then
+ rocks_list=($(luarocks list --porcelain))
+ _store_cache luarocks_installed_list rocks_list
+ else
+ _retrieve_cache luarocks_installed_list
+ fi
+ if _cache_invalid luarocks_installed_names; then
+ rocks_names=()
+ for i in {1.."${#rocks_list[@]}"..4}; do
+ rocks_names+=("${rocks_list[$i]}")
+ done
+ _store_cache luarocks_installed_names rocks_names
+ else
+ _retrieve_cache luarocks_installed_names
+ fi
+ if _cache_invalid luarocks_installed_versions; then
+ rocks_versions=()
+ for i in {2.."${#rocks_list[@]}"..4}; do
+ rocks_versions+=("${rocks_list[$i]}")
+ done
+ _store_cache luarocks_installed_versions rocks_versions
+ else
+ _retrieve_cache luarocks_installed_versions
+ fi
+ if _cache_invalid luarocks_installed_descriptions; then
+ rocks_descriptions=()
+ for i in {1.."${#rocks_names[@]}"}; do
+ name_version_description="$(luarocks show ${rocks_names[$i]} | head -2 | tail -1)"
+ total_length=${#name_version_description}
+ garbage_length="$((${#rocks_names[$i]} + ${#rocks_versions[$i]} + 5))"
+ description="${name_version_description[${garbage_length},${total_length}]}"
+ rocks_descriptions+=("${description}")
+ done
+ _store_cache luarocks_installed_descriptions rocks_descriptions
+ else
+ _retrieve_cache luarocks_installed_descriptions
+ fi
+ if _cache_invalid luarocks_installed_names_and_descriptions; then
+ rocks_names_and_descriptions=()
+ for i in {1.."${#rocks_names[@]}"}; do
+ name_and_description=${rocks_names[$i]}:${rocks_descriptions[$i]}
+ rocks_names_and_descriptions+=(${name_and_description})
+ done
+ else
+ _store_cache luarocks_installed_names_and_descriptions rocks_names_and_descriptions
+ fi
+ _describe 'installed rocks' rocks_names_and_descriptions
+}
+# }}}
+# {{{ helper: rocks wrapper
+# Used to complete one or more of the followings:
+# - .rockspec file
+# - .src.rock file
+# - external rock
__luarocks_rock(){
- local -a arguments=()
+ local -a alts=()
for arg in "$@"; do
case $arg in
- (file)
- arguments+=(':rock file:{_files -g "*.rockspec"}')
+ (rockspec)
+ alts+=(':rock file:{_files -g "*.rockspec"}')
+ ;;
+ (rockpack)
+ alts+=(':rock file:{_files -g "*.src.rock"}')
;;
(external)
- arguments+=(':external rock:')
+ alts+=(':external rock:')
+ ;;
+ (installed)
+ alts+=(':local rock:__luarocks_installed_rocks')
;;
esac
done
- _alternative ${arguments[@]}
+ _alternative ${alts[@]}
}
# }}}
@@ -91,6 +173,10 @@ local build_command_options=(
$option_deps_mode
)
_luarocks_build(){
+ _arguments -A "-*" \
+ "${build_command_options[@]}" \
+ '1: :{__luarocks_rock "rockspec" "external"}' \
+ '2:: :__luarocks_rock_version'
}
# }}}
# {{{ `config` command
@@ -127,12 +213,17 @@ local download_command_options=(
'--arch=[Download rock for a specific architecture]:ARCH:'
)
_luarocks_download(){
+ _arguments -A "-*" \
+ "${download_command_options[@]}" \
+ '1: :{__luarocks_rock "external"}' \
+ '2:: :__luarocks_rock_version'
}
# }}}
# {{{ `help` command
# arguments:
# must: luarocks sub command
_luarocks_help(){
+ _arguments '1: :__luarocks_command'
}
# }}}
# {{{ `install` command
@@ -141,12 +232,14 @@ _luarocks_help(){
# - optional: version
# NOTE: it receives the same argument as the build command and it accepts the same options as well
_luarocks_install(){
+ _luarocks_build
}
# }}}
# {{{ `lint` command
# arguments:
# must: rockspec file (first and last)
_luarocks_lint(){
+ _arguments '1:ROCKSPEC_FILE:{__luarocks_rock "rockspec"}'
}
# }}}
# {{{ `list` command
@@ -156,6 +249,7 @@ local list_command_options=(
'--porcelain[Produce machine-friendly output]'
)
_luarocks_list(){
+ _arguments "${list_command_options[@]}"
}
# }}}
# {{{ `make` command
@@ -163,6 +257,7 @@ _luarocks_list(){
# - optional: rockspec file
# NOTE: it's options were already described above.
_luarocks_make(){
+ _arguments '1:: :{__luarocks_rock "rockspec"}'
}
# }}}
# {{{ `new_version` command
@@ -181,6 +276,7 @@ _luarocks_new_version(){
# - must: .rockspec file / external rock
# - optional: version
_luarocks_pack(){
+ _luarocks_build
}
# }}}
# {{{ `path` command
@@ -193,6 +289,7 @@ local path_command_options=(
'--lr-bin[Exports the system path (not formatted as shell command)]'
)
_luarocks_path(){
+ _arguments "${path_command_options[@]}"
}
# }}}
# {{{ `purge` command
@@ -217,6 +314,10 @@ local remove_command_options=(
$option_force_fast
)
_luarocks_remove(){
+ _arguments -A "-*" \
+ "${remove_command_options[@]}" \
+ '1: :{__luarocks_rock "installed"}' \
+ '2:: :__luarocks_rock_version'
}
# }}}
# {{{ `search` command
@@ -228,6 +329,9 @@ local search_command_options=(
'--all[List all contents of the server that are suitable to this platform, do not filter by name]'
)
_luarocks_search(){
+ _arguments \
+ "${search_command_options[@]}" \
+ '*:SEARCH QUERY:'
}
# }}}
# {{{ `show` command
@@ -243,6 +347,9 @@ local show_command_options=(
'--rock-dir[data directory of the installed rock]'
)
_luarocks_show(){
+ _arguments \
+ "${show_command_options[@]}" \
+ '1: :{__luarocks_rock "installed"}'
}
# }}}
# {{{ `unpack` command
@@ -253,6 +360,9 @@ local unpack_command_options=(
'--force[Unpack files even if the output directory already exists]'
)
_luarocks_unpack(){
+ _arguments \
+ "${unpack_command_options[@]}" \
+ '1: :{__luarocks_rock "rockpack" "external"}'
}
# }}}
# {{{ `upload` command
@@ -264,6 +374,9 @@ local upload_command_options=(
'--force[Replace existing rockspec if the same revision of a module already exists]'
)
_luarocks_upload(){
+ _arguments \
+ "${upload_command_options[@]}" \
+ '1: :{__luarocks_rock "rockspec"}'
}
# }}}
# {{{ `write_rockspec` command
--
2.17.0
^ permalink raw reply [flat|nested] 28+ messages in thread
* [PATCH 11/25] General internal conventions sync.
2018-05-26 15:06 [PATCH 00/25] *** Add completion for luarocks *** doron.behar
` (9 preceding siblings ...)
2018-05-26 15:06 ` [PATCH 10/25] Write all simple sub commands completions doron.behar
@ 2018-05-26 15:06 ` doron.behar
2018-05-26 15:06 ` [PATCH 12/25] Finish helper `__luarocks_lua_versions` doron.behar
` (14 subsequent siblings)
25 siblings, 0 replies; 28+ messages in thread
From: doron.behar @ 2018-05-26 15:06 UTC (permalink / raw)
To: zsh-workers
From: Doron Behar <doron.behar@gmail.com>
---
Completion/Unix/Command/_luarocks | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/Completion/Unix/Command/_luarocks b/Completion/Unix/Command/_luarocks
index 4f3271360..c79d8cd20 100644
--- a/Completion/Unix/Command/_luarocks
+++ b/Completion/Unix/Command/_luarocks
@@ -228,7 +228,7 @@ _luarocks_help(){
# }}}
# {{{ `install` command
# arguments:
-# - must: .rockspec file, or external rock
+# - must: .rockspec file / external rock
# - optional: version
# NOTE: it receives the same argument as the build command and it accepts the same options as well
_luarocks_install(){
@@ -237,9 +237,9 @@ _luarocks_install(){
# }}}
# {{{ `lint` command
# arguments:
-# must: rockspec file (first and last)
+# - must: rockspec file (first and last)
_luarocks_lint(){
- _arguments '1:ROCKSPEC_FILE:{__luarocks_rock "rockspec"}'
+ _arguments '1::{__luarocks_rock "rockspec"}'
}
# }}}
# {{{ `list` command
@@ -354,7 +354,7 @@ _luarocks_show(){
# }}}
# {{{ `unpack` command
# arguments:
-# - must: rock package file / an external rock
+# - must: rockpack file / external rock
# - optional: version (only when chossing external rock)
local unpack_command_options=(
'--force[Unpack files even if the output directory already exists]'
@@ -367,7 +367,7 @@ _luarocks_unpack(){
# }}}
# {{{ `upload` command
# arguments:
-# - must: rockspec file with .src.rock extension
+# - must: rockspec file
local upload_command_options=(
'--skip-pack[Do not pack and send source rock]'
'--api-key=[Give it an API key]:KEY:{_message "api key"}'
--
2.17.0
^ permalink raw reply [flat|nested] 28+ messages in thread
* [PATCH 12/25] Finish helper `__luarocks_lua_versions`.
2018-05-26 15:06 [PATCH 00/25] *** Add completion for luarocks *** doron.behar
` (10 preceding siblings ...)
2018-05-26 15:06 ` [PATCH 11/25] General internal conventions sync doron.behar
@ 2018-05-26 15:06 ` doron.behar
2018-05-26 15:06 ` [PATCH 13/25] General cleanup doron.behar
` (13 subsequent siblings)
25 siblings, 0 replies; 28+ messages in thread
From: doron.behar @ 2018-05-26 15:06 UTC (permalink / raw)
To: zsh-workers
From: Doron Behar <doron.behar@gmail.com>
---
Completion/Unix/Command/_luarocks | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/Completion/Unix/Command/_luarocks b/Completion/Unix/Command/_luarocks
index c79d8cd20..c1a47773b 100644
--- a/Completion/Unix/Command/_luarocks
+++ b/Completion/Unix/Command/_luarocks
@@ -54,9 +54,8 @@ __luarocks_c_libs(){
}
# }}}
# {{{ helper: lua versions
-# TODO
-__luarocks_lua_version(){
- _values -s ,
+__luarocks_lua_versions(){
+ _values -s , 5.3 5.2 5.1
}
# }}}
# {{{ helper: installed rocks cache policy
@@ -391,7 +390,7 @@ local write_rockspec_command_options=(
'--summary=[A short one-line description summary]:SUMMARY_TEXT:{_message -e "write a short summary of the rock"}'
'--detailed=[A longer description string]:DETAILED_TEXT:{_message -e "write a detailed description of the rock"}'
'--homepage=[Project homepage]:URL:_luarocks_write_rockspec_homepage'
- '--lua-version=[Supported Lua versions]:LUA_VER:__luarocks_version'
+ '--lua-version=[Supported Lua versions]:LUA_VER:__luarocks_lua_versions'
'--rockspec-format=[Rockspec format version, such as "1.0" or "1.1"]:VER: '
'--tag=[Tag to use. Will attempt to extract version number from it]:TAG:__git_tag'
'--lib=[A comma-separated list of libraries that C files need to link to]:__luarocks_c_libs'
--
2.17.0
^ permalink raw reply [flat|nested] 28+ messages in thread
* [PATCH 13/25] General cleanup.
2018-05-26 15:06 [PATCH 00/25] *** Add completion for luarocks *** doron.behar
` (11 preceding siblings ...)
2018-05-26 15:06 ` [PATCH 12/25] Finish helper `__luarocks_lua_versions` doron.behar
@ 2018-05-26 15:06 ` doron.behar
2018-05-26 15:06 ` [PATCH 14/25] Finish `_luarocks_doc` and `_luarocks_config` doron.behar
` (12 subsequent siblings)
25 siblings, 0 replies; 28+ messages in thread
From: doron.behar @ 2018-05-26 15:06 UTC (permalink / raw)
To: zsh-workers
From: Doron Behar <doron.behar@gmail.com>
---
Completion/Unix/Command/_luarocks | 13 ++++---------
1 file changed, 4 insertions(+), 9 deletions(-)
diff --git a/Completion/Unix/Command/_luarocks b/Completion/Unix/Command/_luarocks
index c1a47773b..d73a84d2a 100644
--- a/Completion/Unix/Command/_luarocks
+++ b/Completion/Unix/Command/_luarocks
@@ -38,21 +38,16 @@ __luarocks_deps_mode(){
_describe 'dependencies mode' modes
}
# }}}
-# {{{ helper: versions of an external rock
+# {{{ helper: versions of an external rock or nothing for rockspec file
__luarocks_rock_version(){
for i in {2..${#build_command_options[@]}}; do
if [[ ! -z "${words[$i]}" && ! "${words[$i]}" =~ '^-' && ! -f "${words[$i]}" ]]; then
- # TODO: complete with optional versions
_message -e "version for rock ${words[$i]}"
return
fi
done
}
# }}}
-# {{{ helper: list of libraries that C files need to link to
-__luarocks_c_libs(){
-}
-# }}}
# {{{ helper: lua versions
__luarocks_lua_versions(){
_values -s , 5.3 5.2 5.1
@@ -76,7 +71,7 @@ ___luarocks_installed_rocks_cache_policy(){
# }}}
# {{{ helper: installed rocks
__luarocks_installed_rocks(){
- local update_policy ret=1
+ local update_policy
zstyle -s ":completion:${curcontext}:" cache-policy update_policy
if [[ -z "$update_policy" ]]; then
zstyle ":completion:${curcontext}:" cache-policy ___luarocks_installed_rocks_cache_policy
@@ -180,7 +175,7 @@ _luarocks_build(){
# }}}
# {{{ `config` command
# arguments:
-# - must: VAR=VALUE
+# - must: option
local config_command_options=(
'--lua-incdir[Path to Lua header files]'
'--lua-libdir[Path to Lua library files]'
@@ -393,7 +388,7 @@ local write_rockspec_command_options=(
'--lua-version=[Supported Lua versions]:LUA_VER:__luarocks_lua_versions'
'--rockspec-format=[Rockspec format version, such as "1.0" or "1.1"]:VER: '
'--tag=[Tag to use. Will attempt to extract version number from it]:TAG:__git_tag'
- '--lib=[A comma-separated list of libraries that C files need to link to]:__luarocks_c_libs'
+ '--lib=[A comma-separated list of libraries that C files need to link to]:'
)
_luarocks_write_rockspec(){
}
--
2.17.0
^ permalink raw reply [flat|nested] 28+ messages in thread
* [PATCH 14/25] Finish `_luarocks_doc` and `_luarocks_config`.
2018-05-26 15:06 [PATCH 00/25] *** Add completion for luarocks *** doron.behar
` (12 preceding siblings ...)
2018-05-26 15:06 ` [PATCH 13/25] General cleanup doron.behar
@ 2018-05-26 15:06 ` doron.behar
2018-05-26 15:06 ` [PATCH 15/25] Expand __luarocks_rock_version so it accpets args doron.behar
` (11 subsequent siblings)
25 siblings, 0 replies; 28+ messages in thread
From: doron.behar @ 2018-05-26 15:06 UTC (permalink / raw)
To: zsh-workers
From: Doron Behar <doron.behar@gmail.com>
---
Completion/Unix/Command/_luarocks | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/Completion/Unix/Command/_luarocks b/Completion/Unix/Command/_luarocks
index d73a84d2a..aec6ba815 100644
--- a/Completion/Unix/Command/_luarocks
+++ b/Completion/Unix/Command/_luarocks
@@ -185,16 +185,20 @@ local config_command_options=(
'--rock-trees[Rocks trees in useFirst the user tree, then the system tree]'
)
_luarocks_config(){
+ _arguments "${config_command_options[@]}"
}
# }}}
# {{{ `doc` command
# arguments:
-# - TODO
+# - must: installed rock
local doc_command_options=(
'--home[Open the home page of project]'
'--list[List documentation files only]'
)
_luarocks_doc(){
+ _arguments \
+ "${doc_command_options[@]}" \
+ '1: :{__luarocks_rock "installed"}'
}
# }}}
# {{{ `download` command
--
2.17.0
^ permalink raw reply [flat|nested] 28+ messages in thread
* [PATCH 15/25] Expand __luarocks_rock_version so it accpets args.
2018-05-26 15:06 [PATCH 00/25] *** Add completion for luarocks *** doron.behar
` (13 preceding siblings ...)
2018-05-26 15:06 ` [PATCH 14/25] Finish `_luarocks_doc` and `_luarocks_config` doron.behar
@ 2018-05-26 15:06 ` doron.behar
2018-05-26 15:06 ` [PATCH 16/25] Finish completions for purge and new_version doron.behar
` (10 subsequent siblings)
25 siblings, 0 replies; 28+ messages in thread
From: doron.behar @ 2018-05-26 15:06 UTC (permalink / raw)
To: zsh-workers
From: Doron Behar <doron.behar@gmail.com>
Write `_luarocks_write_rockspec`.
---
Completion/Unix/Command/_luarocks | 46 +++++++++++++++++++++++++------
1 file changed, 38 insertions(+), 8 deletions(-)
diff --git a/Completion/Unix/Command/_luarocks b/Completion/Unix/Command/_luarocks
index aec6ba815..db27a76d5 100644
--- a/Completion/Unix/Command/_luarocks
+++ b/Completion/Unix/Command/_luarocks
@@ -40,11 +40,36 @@ __luarocks_deps_mode(){
# }}}
# {{{ helper: versions of an external rock or nothing for rockspec file
__luarocks_rock_version(){
- for i in {2..${#build_command_options[@]}}; do
- if [[ ! -z "${words[$i]}" && ! "${words[$i]}" =~ '^-' && ! -f "${words[$i]}" ]]; then
- _message -e "version for rock ${words[$i]}"
- return
+ local i=2
+ while [[ -n "${words[$i]}" ]]; do
+ if [[ ! "${words[$i]}" =~ '^-' ]]; then
+ case "$1" in
+ "external_or_local")
+ if [[ ! -f "${words[$i]}" ]]; then
+ _message -e "version for external rock ${words[$i]}"
+ return
+ else
+ _message -e "version for local rock ${words[$i]}"
+ fi
+ ;;
+ "installed")
+ # TODO: actually complete versions of installed rocks using the cache
+ _message -e "version for installed rock ${words[$i]}"
+ return
+ ;;
+ "new_version")
+ if [[ -f "${words[$i]}" ]]; then
+ _message -e "new version for rock ${words[$i]}"
+ return
+ fi
+ ;;
+ "new_rock")
+ _message -e "version for new rock ${words[$i]}"
+ return
+ ;;
+ esac
fi
+ i=$(( i + 1 ))
done
}
# }}}
@@ -170,7 +195,7 @@ _luarocks_build(){
_arguments -A "-*" \
"${build_command_options[@]}" \
'1: :{__luarocks_rock "rockspec" "external"}' \
- '2:: :__luarocks_rock_version'
+ '2:: :{__luarocks_rock_version "external_or_local"}'
}
# }}}
# {{{ `config` command
@@ -214,7 +239,7 @@ _luarocks_download(){
_arguments -A "-*" \
"${download_command_options[@]}" \
'1: :{__luarocks_rock "external"}' \
- '2:: :__luarocks_rock_version'
+ '2:: :{__luarocks_rock_version "external_or_local"}'
}
# }}}
# {{{ `help` command
@@ -315,7 +340,7 @@ _luarocks_remove(){
_arguments -A "-*" \
"${remove_command_options[@]}" \
'1: :{__luarocks_rock "installed"}' \
- '2:: :__luarocks_rock_version'
+ '2:: :{__luarocks_rock_version "installed"}'
}
# }}}
# {{{ `search` command
@@ -388,13 +413,18 @@ local write_rockspec_command_options=(
'--license=[A license string, ]:LICENSE:{_message -e "write a license string such as "MIT/X11" or "GNU GPL v3"}'
'--summary=[A short one-line description summary]:SUMMARY_TEXT:{_message -e "write a short summary of the rock"}'
'--detailed=[A longer description string]:DETAILED_TEXT:{_message -e "write a detailed description of the rock"}'
- '--homepage=[Project homepage]:URL:_luarocks_write_rockspec_homepage'
+ '--homepage=[Project homepage]:URL:_urls'
'--lua-version=[Supported Lua versions]:LUA_VER:__luarocks_lua_versions'
'--rockspec-format=[Rockspec format version, such as "1.0" or "1.1"]:VER: '
'--tag=[Tag to use. Will attempt to extract version number from it]:TAG:__git_tag'
'--lib=[A comma-separated list of libraries that C files need to link to]:'
)
_luarocks_write_rockspec(){
+ _arguments -A "-*" \
+ "${write_rockspec_command_options[@]}" \
+ '1:: :{_message "new rock name"}' \
+ '2:: :{__luarocks_rock_version "new_rock"}' \
+ '3:: :_urls'
}
# }}}
--
2.17.0
^ permalink raw reply [flat|nested] 28+ messages in thread
* [PATCH 16/25] Finish completions for purge and new_version.
2018-05-26 15:06 [PATCH 00/25] *** Add completion for luarocks *** doron.behar
` (14 preceding siblings ...)
2018-05-26 15:06 ` [PATCH 15/25] Expand __luarocks_rock_version so it accpets args doron.behar
@ 2018-05-26 15:06 ` doron.behar
2018-05-26 15:06 ` [PATCH 17/25] Write a better comment for last TODO doron.behar
` (9 subsequent siblings)
25 siblings, 0 replies; 28+ messages in thread
From: doron.behar @ 2018-05-26 15:06 UTC (permalink / raw)
To: zsh-workers
From: Doron Behar <doron.behar@gmail.com>
---
Completion/Unix/Command/_luarocks | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/Completion/Unix/Command/_luarocks b/Completion/Unix/Command/_luarocks
index db27a76d5..c2ecde869 100644
--- a/Completion/Unix/Command/_luarocks
+++ b/Completion/Unix/Command/_luarocks
@@ -292,6 +292,11 @@ local new_version_command_options=(
'--tag=[if no version is specified, this option'"'"'s argument is used instead]:TAG:__git_tag'
)
_luarocks_new_version(){
+ _arguments -A "-*" \
+ "${new_version_command_options[@]}" \
+ '1:: :{__luarocks_rock "external" "rockspec"}' \
+ '2:: :{__luarocks_rock_version "external_or_local"}' \
+ '3:: :_urls'
}
# }}}
# {{{ `pack` command
@@ -324,6 +329,7 @@ local purge_command_options=(
$option_force
)
_luarocks_purge(){
+ _arguments "${purge_command_options[@]}"
}
# }}}
# {{{ `remove` command
--
2.17.0
^ permalink raw reply [flat|nested] 28+ messages in thread
* [PATCH 17/25] Write a better comment for last TODO.
2018-05-26 15:06 [PATCH 00/25] *** Add completion for luarocks *** doron.behar
` (15 preceding siblings ...)
2018-05-26 15:06 ` [PATCH 16/25] Finish completions for purge and new_version doron.behar
@ 2018-05-26 15:06 ` doron.behar
2018-05-26 15:06 ` [PATCH 18/25] Make cache policy function safer doron.behar
` (8 subsequent siblings)
25 siblings, 0 replies; 28+ messages in thread
From: doron.behar @ 2018-05-26 15:06 UTC (permalink / raw)
To: zsh-workers
From: Doron Behar <doron.behar@gmail.com>
I don't know how to finish it.
---
Completion/Unix/Command/_luarocks | 2 ++
1 file changed, 2 insertions(+)
diff --git a/Completion/Unix/Command/_luarocks b/Completion/Unix/Command/_luarocks
index c2ecde869..d7355c1ba 100644
--- a/Completion/Unix/Command/_luarocks
+++ b/Completion/Unix/Command/_luarocks
@@ -54,6 +54,8 @@ __luarocks_rock_version(){
;;
"installed")
# TODO: actually complete versions of installed rocks using the cache
+ # How does luarocks handles multiple versions of the same package?
+ # If anybody knows, please write something beautiful here
_message -e "version for installed rock ${words[$i]}"
return
;;
--
2.17.0
^ permalink raw reply [flat|nested] 28+ messages in thread
* [PATCH 18/25] Make cache policy function safer.
2018-05-26 15:06 [PATCH 00/25] *** Add completion for luarocks *** doron.behar
` (16 preceding siblings ...)
2018-05-26 15:06 ` [PATCH 17/25] Write a better comment for last TODO doron.behar
@ 2018-05-26 15:06 ` doron.behar
2018-05-26 15:06 ` [PATCH 19/25] Fix git tag completion by autoloading _git doron.behar
` (7 subsequent siblings)
25 siblings, 0 replies; 28+ messages in thread
From: doron.behar @ 2018-05-26 15:06 UTC (permalink / raw)
To: zsh-workers
From: Doron Behar <doron.behar@gmail.com>
Add TODO for using zstyle for manifest files location when checking when
they were last modified.
---
Completion/Unix/Command/_luarocks | 3 +++
1 file changed, 3 insertions(+)
diff --git a/Completion/Unix/Command/_luarocks b/Completion/Unix/Command/_luarocks
index d7355c1ba..05a1e1d38 100644
--- a/Completion/Unix/Command/_luarocks
+++ b/Completion/Unix/Command/_luarocks
@@ -82,6 +82,7 @@ __luarocks_lua_versions(){
# }}}
# {{{ helper: installed rocks cache policy
___luarocks_installed_rocks_cache_policy(){
+ # TODO enable the user to configure manifests file that will be checked here with zstyle
# the number of seconds since 1970-01-01 the manifest file was modified
local manifest_last_date_modified="$(date -r ~/.luarocks/lib/luarocks/rocks-5.3/manifest +%s 2>/dev/null)"
# the number of seconds since 1970-01-01 the cache file was modified
@@ -93,6 +94,8 @@ ___luarocks_installed_rocks_cache_policy(){
else
(( 0 ))
fi
+ else
+ (( 1 ))
fi
}
# }}}
--
2.17.0
^ permalink raw reply [flat|nested] 28+ messages in thread
* [PATCH 19/25] Fix git tag completion by autoloading _git
2018-05-26 15:06 [PATCH 00/25] *** Add completion for luarocks *** doron.behar
` (17 preceding siblings ...)
2018-05-26 15:06 ` [PATCH 18/25] Make cache policy function safer doron.behar
@ 2018-05-26 15:06 ` doron.behar
2018-05-26 15:06 ` [PATCH 20/25] Use a generic sub command completer doron.behar
` (6 subsequent siblings)
25 siblings, 0 replies; 28+ messages in thread
From: doron.behar @ 2018-05-26 15:06 UTC (permalink / raw)
To: zsh-workers
From: Doron Behar <doron.behar@gmail.com>
---
Completion/Unix/Command/_luarocks | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/Completion/Unix/Command/_luarocks b/Completion/Unix/Command/_luarocks
index 05a1e1d38..68f38523e 100644
--- a/Completion/Unix/Command/_luarocks
+++ b/Completion/Unix/Command/_luarocks
@@ -181,6 +181,17 @@ __luarocks_rock(){
_alternative ${alts[@]}
}
# }}}
+# {{{ helper: git tags
+__luarocks_git_tags(){
+ autoload +X _git
+ local _git_def="$(whence -v _git)"
+ . ${_git_def##* }
+ type __git_tags &> /dev/null
+ if [[ $? != 1 ]]; then
+ __git_tags
+ fi
+}
+# }}}
# {{{ `build` command
# arguments:
@@ -294,7 +305,7 @@ _luarocks_make(){
# - optional: version (unless a --tag was given)
# - optional: URL
local new_version_command_options=(
- '--tag=[if no version is specified, this option'"'"'s argument is used instead]:TAG:__git_tag'
+ '--tag=[if no version is specified, this option'"'"'s argument is used instead]:TAG:__luarocks_git_tags'
)
_luarocks_new_version(){
_arguments -A "-*" \
--
2.17.0
^ permalink raw reply [flat|nested] 28+ messages in thread
* [PATCH 20/25] Use a generic sub command completer.
2018-05-26 15:06 [PATCH 00/25] *** Add completion for luarocks *** doron.behar
` (18 preceding siblings ...)
2018-05-26 15:06 ` [PATCH 19/25] Fix git tag completion by autoloading _git doron.behar
@ 2018-05-26 15:06 ` doron.behar
2018-05-26 15:06 ` [PATCH 21/25] Use 2 spaces instead of tabs doron.behar
` (5 subsequent siblings)
25 siblings, 0 replies; 28+ messages in thread
From: doron.behar @ 2018-05-26 15:06 UTC (permalink / raw)
To: zsh-workers
From: Doron Behar <doron.behar@gmail.com>
---
Completion/Unix/Command/_luarocks | 65 +-----
src/_pip | 326 ++++++++++++++++++++++++++++++
2 files changed, 331 insertions(+), 60 deletions(-)
create mode 100644 src/_pip
diff --git a/Completion/Unix/Command/_luarocks b/Completion/Unix/Command/_luarocks
index 68f38523e..24a62b085 100644
--- a/Completion/Unix/Command/_luarocks
+++ b/Completion/Unix/Command/_luarocks
@@ -465,64 +465,9 @@ _arguments -C \
case "$state" in
(args)
curcontext="${curcontext%:*:*}:luarocks_${words[1]}:"
- case $words[1] in
- (build)
- _luarocks_build
- ;;
- (config)
- _luarocks_config
- ;;
- (doc)
- _luarocks_doc
- ;;
- (download)
- _luarocks_download
- ;;
- (help)
- _luarocks_help
- ;;
- (install)
- _luarocks_install
- ;;
- (lint)
- _luarocks_lint
- ;;
- (list)
- _luarocks_list
- ;;
- (make)
- _luarocks_make
- ;;
- (new_version)
- _luarocks_new_version
- ;;
- (pack)
- _luarocks_pack
- ;;
- (path)
- _luarocks_path
- ;;
- (purge)
- _luarocks_purge
- ;;
- (remove)
- _luarocks_remove
- ;;
- (search)
- _luarocks_search
- ;;
- (show)
- _luarocks_show
- ;;
- (unpack)
- _luarocks_unpack
- ;;
- (upload)
- _luarocks_upload
- ;;
- (write_rockspec)
- _luarocks_write_rockspec
- ;;
- esac
- ;;
+ # check if a command with a defined completion was typed
+ type _luarocks_${words[1]} &> /dev/null
+ if [[ $? != 1 ]]; then
+ _luarocks_${words[1]}
+ fi
esac
diff --git a/src/_pip b/src/_pip
new file mode 100644
index 000000000..cab7fda31
--- /dev/null
+++ b/src/_pip
@@ -0,0 +1,326 @@
+#compdef pip
+
+# {{{ common options
+local common_options_help=(
+ '(- :)'{-h,--help}'[show help]'
+)
+local common_options_pre=(
+ '--pre[Include pre-release and development versions]'
+)
+local common_options_install=(
+ {\*-c,\*--constraint}'[Constrain versions using the given constraints file]:FILE:_files'
+ '(- :)'{-e,--editable}'[Install a project in editable mode (i.e. setuptools "develop mode") from a local project path or a VCS url]:PACKAGE:{__pip_package "url" "file"}'
+ {\*-r,\*--requirement}'[Install from the given requirements file]:FILE:_files'
+ {-b,--build}'[Directory to unpack packages into and build in]:DIRECTORY:_files -/'
+ "--no-deps[Don't install package dependencies]"
+ "${common_options_pre[@]}"
+ '*--global-option=[Extra global options to be supplied to the setup.py call before the install command]:OPTION:_setup.py'
+ '*--no-binary[Do not use binary packages]:FORMAT_CONTROL:__pip_no_binary_control'
+ '*--only-binary[Do not use binary packages]:FORMAT_CONTROL:__pip_only_binary_control'
+ "--no-clean[Don't clean up build directories]"
+ '--require-hashes[Require a hash to check each requirement against, for repeatable installs]'
+)
+local common_options_wheel=(
+ "${common_options_install[@]}"
+ '--src[Directory to check out editable projects into]:DIRECTORY:_files -/'
+ '--ignore-requires-python[Ignore the Requires-Python information]'
+)
+local common_options_index=(
+ '(--no-index)'{-i,--index-url}'[Base URL of Python Package Index (default https://pypi.python.org/simple)]:URL:_urls'
+ '(--no-index)*--extra-index-url[Extra URLs of package indexes to use in addition to --index-url]:URL:_urls'
+ '(-i --index-url)--no-index[Ignore package index (only looking at --find-links URLs instead)]'
+ {-f,--find-links}'[If a url or path to an html file, then parse for links to archives]:URL:__pip_find_links'
+ '--process-dependency-links[Enable the processing of dependency links]'
+)
+local common_options_user=(
+ '--user\[Only output packages installed in user-site\]'
+)
+local common_options_local=(
+ {-l,--local}'[If in a virtualenv that has global access, do not output globally-installed packages]'
+)
+# }}}
+# {{{ helper: installed packages cache policy
+__pip_install_packages_cache_policy(){
+ # TODO: workout a way that will let users configure via zstyle locations of site-packages
+ # the number of seconds since 1970-01-01 the site-packages directories were changed
+ local site_packages_user_dir_last_date_modified="$(date -r ~/.local/lib/python3.6/site-packages +%s 2>/dev/null)"
+ local site_packages_system_dir_last_date_modified="$(date -r /usr/lib/python3.6/site-packages +%s 2>/dev/null)"
+ # the number of seconds since 1970-01-01 the cache file was modified
+ local cache_last_date_modified="$(date -r $1 +%s 2>/dev/null)"
+ if [[ ! -z "${cache_last_date_modified}" ]] && [[ ! -z "${site_packages_user_dir_last_date_modified}" || ! -z "${site_packages_system_dir_last_date_modified}" ]]; then
+ # if the manifest file is newer then the cache:
+ if [[ ${site_packages_user_dir_last_date_modified} -ge ${cache_last_date_modified} ]] || [[ ${site_packages_system_dir_last_date_modified} -ge ${cache_last_date_modified} ]]; then
+ (( 1 ))
+ else
+ (( 0 ))
+ fi
+ else
+ (( 1 ))
+ fi
+}
+# }}}
+# {{{ helper: installed packages (using cache)
+__pip_installed() {
+ local update_policy
+ zstyle -s ":completion:${curcontext}:" cache-policy update_policy
+ if [[ -z "$update_policy" ]]; then
+ zstyle ":completion:${curcontext}:" cache-policy __pip_install_packages_cache_policy
+ fi
+ if _cache_invalid pip_installed_packages; then
+ installed_packages=($(pip list --format freeze | sed -n -e 's/\([-a-z_]\+\)==.*/\1/p'))
+ _store_cache pip_installed_packages installed_packages
+ else
+ _retrieve_cache pip_installed_packages
+ fi
+ _values "installed packages" "${installed_packages[@]}"
+}
+# }}}
+# {{{ helper: available commands
+local commands=(
+ 'install:install packages'
+ 'download:download packages'
+ 'uninstall:uninstall packages'
+ 'freeze:output all currently installed packages (exact versions) to stdout'
+ 'list:list installed packages'
+ 'show:show information about installed packages'
+ 'search:search PyPI'
+ 'wheel:build individual wheel archives for your requirements and dependencies'
+ 'hash:compute a hash of a local package archive'
+ 'help:show available commands'
+)
+__pip_commands(){
+ _describe "pip command" commands
+}
+# }}}
+# {{{ helper: installable packages wrapper
+__pip_package(){
+ local -a alts
+ for arg in "$@"; do
+ case $arg in
+ "url")
+ alts+=(':URL of package:_urls')
+ ;;
+ "file")
+ alts+=(':package repo or archive:_files')
+ ;;
+ esac
+ done
+ _alternative "${alts[@]}"
+}
+# }}}
+# {{{ helper: upgrade strategy
+__pip_upgrade_strategy(){
+ local strategies=(
+ "eager:dependencies are upgraded whether currently installed version satisfies the requirements or not"
+ "only-if-needed:are upgraded only when they do not satisfy the requirements of the upgraded package(s)"
+ )
+ _describe "strategy" strategies
+}
+# }}}
+# {{{ helper: binary control
+__pip_no_binary_control(){
+ local options=(
+ 'all:"disable all binary packages"'
+ 'none:"enable all binary packages"'
+ )
+ _alternative ": :((${options[@]}))" ": :_message 'packages to install or use:'"
+}
+__pip_only_binary_control(){
+ local options=(
+ 'all:"enable all binary packages"'
+ 'none:"disable all binary packages"'
+ )
+ _alternative ": :((${options[@]}))" ": :{_message 'packages to install or use:'}"
+}
+# }}}
+# {{{ helper: look for html file or url with links to packages or find packages in a directory
+__pip_find_links(){
+ _alternative ': :_urls' ': :_files -g ".html"' ': :_files -/'
+}
+# }}}
+# {{{ helper: urls or files to install
+__pip_install_packages(){
+ _alternative ': :_urls' ': :_files'
+}
+# }}}
+# {{{ command install
+local command_install_options=(
+ "${common_options_help[@]}"
+ "${common_options_wheel[@]}"
+ "${common_options_index[@]}"
+ {-t,--target}'[Install packages into DIRECTORY]:DIRECTORY:_files -/'
+ {-d,--download}"[Download packages into <dir> instead of installing them, regardless of what's already installed]:DIRECTORY:_files -/"
+ {-U,--upgrade}'[Upgrade all specified packages to the newest available version]'
+ '--upgrade-strategy[Determines how dependency upgrading should be handled]:STRATEGY:__pip_upgrade_strategy'
+ '--force-reinstall[When upgrading, reinstall all packages even if they are already up-to-date]'
+ {-I,--ignore-installed}'[Ignore the installed packages (reinstalling instead)]'
+ # TODO: autoload _setup.py to complete options for it
+ '*--install-option=[Extra arguments to be supplied to the setup.py install command]:OPTION:_setup.py'
+ '--user[Install to the Python user install directory for your platform]'
+ "--egg[Install packages as eggs, not 'flat', like pip normally does]"
+ '--root[Install everything relative to this alternate root directory]:DIRECTORY:_files -/'
+ '--prefix[Installation prefix where lib, bin and other top-level folders are place]:DIRECTORY:_files -/'
+ '--compile[Compile py files to pyc]'
+ '--no-compile[Do not compile py files to pyc]'
+ '--no-use-wheel[DEPRECATED in favour of --no-binary]'
+)
+_pip_install(){
+ _arguments \
+ "${command_install_options[@]}" \
+ '*:PACKAGE:__pip_install_packages'
+}
+# }}}
+# {{{ command download
+local command_download_options=(
+ "${common_options_help[@]}"
+ "${common_options_install[@]}"
+ "${common_options_index[@]}"
+ '--src[Directory to check out editable projects into]:DIRECTORY:_files -/'
+ {-d,--dest}'[Download packages into DIRECTORY]:DIRECTORY:_files -/'
+ '--platform[Only download wheels compatible with PLATFORM]:PLATFORM:'
+ '--python-version[Only download wheels compatible with Python interpreter version VERSION]:VERSION:'
+ '--implementation[Only download wheels compatible with Python implementation IMPLEMENTATION]:IMPLEMENTATION:'
+ '--abi[Only download wheels compatible with Python abi ABI]:ABI:'
+)
+_pip_download(){
+ _arguments \
+ "${command_download_options[@]}" \
+ '*:PACKAGE:__pip_install_packages'
+}
+# }}}
+# {{{ command uninstall
+local command_uninstall_options=(
+ "${common_options_help[@]}"
+ {\*-r,\*--requirement}'[Uninstall all the packages listed in the given requirements file]:FILE:_files'
+ {-y,--yes}"[Don't ask for confirmation of uninstall deletions]"
+)
+_pip_uninstall(){
+ _arguments \
+ "${command_uninstall_options[@]}" \
+ '*: :__pip_installed'
+}
+# }}}
+# {{{ command freeze
+local command_freeze_options=(
+ "${common_options_help[@]}"
+ "${common_options_local[@]}"
+ "${common_options_user[@]}"
+ {\*-r,\*--requirement}'[Use the order in the given requirements file and its comments when generating output]:FILE:_files'
+ {-f,--find-links}'[URL for finding packages, which will be added to the output]:URL:_urls'
+ '--all[Do not skip these packages in the output: pip, setuptools, distribute, wheel]'
+
+)
+_pip_freeze(){
+ _arguments \
+ "${command_freeze_options[@]}"
+}
+# }}}
+# {{{ command list
+local command_list_options=(
+ "${common_options_help[@]}"
+ "${common_options_local[@]}"
+ "${common_options_user[@]}"
+ "${common_options_pre[@]}"
+ {-o,--outdated}'[List outdated packages]'
+ {-u,--uptodate}'[List uptodate packages]'
+ {-e,--editable}'[List editable projects]'
+ '--format[Select the output format among]:FORMAT:(legacy columns freeze json)'
+ '--not-required[List packages that are not dependencies of installed packages]'
+ "${common_options_index[@]}"
+)
+_pip_list(){
+ _arguments \
+ "${command_list_options[@]}" \
+ '1: :'
+}
+# }}}
+# {{{ command show
+local command_show_options=(
+ "${common_options_help[@]}"
+ {-f,--files}'[Show the full list of installed files for each package]'
+)
+_pip_show(){
+ _arguments \
+ "${command_show_options[@]}" \
+ '*: :__pip_installed'
+}
+# }}}
+# {{{ command search
+local command_search_options=(
+ "${common_options_help[@]}"
+ {-i,--index}'[Base URL of Python Package Index (default https://pypi.python.org/pypi)]:URL:_urls'
+)
+_pip_search(){
+ _arguments \
+ "${command_search_options[@]}" \
+ '*:QUERY:'
+}
+# }}}
+# {{{ command wheel
+local command_wheel_options=(
+ "${common_options_help[@]}"
+ "${common_options_wheel[@]}"
+ "${common_options_index[@]}"
+ '(--no-wheel-dir)'{-w,--wheel-dir}'[Build wheels into DIRECTORY (default is current working directory)]:DIRECTORY:_files -/'
+ '(-w --wheel-dir)--no-wheel-dir[Do not Find and prefer wheel archives when searching indexes and find-links locations]'
+)
+_pip_wheel(){
+ _arguments \
+ "${command_wheel_options[@]}" \
+ '*:PACKAGE:__pip_install_packages'
+}
+# }}}
+# {{{ command hash
+local command_hash_options=(
+ "${common_options_help[@]}"
+ {-a,--algorithm}'[The hash algorithm to use]:ALGORITHM:(sha256 sha384 sha512)'
+)
+_pip_hash(){
+ _arguments \
+ "${command_hash_options[@]}" \
+ '1:PACKAGE_ARCHIVE:_files'
+}
+# }}}
+# {{{ command help
+local command_help_options=(
+ "${common_options_help[@]}"
+)
+_pip_help(){
+ _arguments \
+ "${command_help_options[@]}" \
+ '1:COMMAND:__pip_commands'
+}
+# }}}
+
+# The real thing
+_arguments \
+ "${common_options_help[@]}" \
+ '--isolated[run pip in isolated mode, ignores environment variables and user configuration]' \
+ {-v,--verbose}'[give more output]' \
+ {-V,--version}'[show version number of program and exit]' \
+ {-q,--quiet}'[give less output]' \
+ '--log[log file location]' \
+ '--proxy=[proxy in form user:passwd@proxy.server:port]' \
+ '--retries=[max number of retries per connection (default 5 times)]' \
+ '--timeout=[socket timeout (default 15s)]' \
+ '--exists-action=[default action when a path already exists: (s)witch, (i)gnore, (w)ipe, (b)ackup]' \
+ '--trusted-host=[mark this host as trusted]' \
+ '--cert=[path to alternate CA bundle]' \
+ '--client-cert=[path to SSL client certificate]' \
+ '--cache-dir=[store the cache data in specified directory]' \
+ '--no-cache-dir[disable de cache]' \
+ '--disable-pip-version-check[do not check periodically for new pip version downloads]' \
+ {-E,--environment}'[virtualenv environment to run pip in (deprecated)]' \
+ {-s,--enable-site-packages}'[include site-packages in virtualenv (deprecated)]' \
+ '1: :__pip_commands' \
+ '*::arg:->args'
+
+case "$state" in
+ (args)
+ curcontext="${curcontext%:*:*}:pip_${words[1]}:"
+ # check if a command with a defined completion was typed
+ type _pip_${words[1]} &> /dev/null
+ if [[ $? != 1 ]]; then
+ _pip_${words[1]}
+ fi
+esac
--
2.17.0
^ permalink raw reply [flat|nested] 28+ messages in thread
* [PATCH 21/25] Use 2 spaces instead of tabs.
2018-05-26 15:06 [PATCH 00/25] *** Add completion for luarocks *** doron.behar
` (19 preceding siblings ...)
2018-05-26 15:06 ` [PATCH 20/25] Use a generic sub command completer doron.behar
@ 2018-05-26 15:06 ` doron.behar
2018-05-26 15:06 ` [PATCH 22/25] Use +functions[] for all helpers doron.behar
` (4 subsequent siblings)
25 siblings, 0 replies; 28+ messages in thread
From: doron.behar @ 2018-05-26 15:06 UTC (permalink / raw)
To: zsh-workers
From: Doron Behar <doron.behar@gmail.com>
---
Completion/Unix/Command/_luarocks | 542 +++++++++++++++---------------
src/_pip | 326 ------------------
2 files changed, 271 insertions(+), 597 deletions(-)
delete mode 100644 src/_pip
diff --git a/Completion/Unix/Command/_luarocks b/Completion/Unix/Command/_luarocks
index 24a62b085..1dda38cad 100644
--- a/Completion/Unix/Command/_luarocks
+++ b/Completion/Unix/Command/_luarocks
@@ -2,157 +2,157 @@
# {{{ helper: luarocks commands
__luarocks_command(){
- local -a commands=(
- build:'Build/compile a rock'
- config:'Query information about the LuaRocks configuration'
- doc:'Show documentation for an installed rock'
- download:'Download a specific rock file from a rocks server'
- help:'Help on commands'
- install:'Install a rock'
- lint:'Check syntax of a rockspec'
- list:'List currently installed rocks'
- make:'Compile package in current directory using a rockspec'
- new_version:'Auto-write a rockspec for a new version of a rock'
- pack:'Create a rock, packing sources or binaries'
- path:'Return the currently configured package path'
- purge:'Remove all installed rocks from a tree'
- remove:'Uninstall a rock'
- search:'Query the LuaRocks servers'
- show:'Show information about an installed rock'
- unpack:'Unpack the contents of a rock'
- upload:'Upload a rockspec to the public rocks repository'
- write_rockspec:'Write a template for a rockspec file'
- )
- _describe -t commands 'command' commands "$@"
+ local -a commands=(
+ build:'Build/compile a rock'
+ config:'Query information about the LuaRocks configuration'
+ doc:'Show documentation for an installed rock'
+ download:'Download a specific rock file from a rocks server'
+ help:'Help on commands'
+ install:'Install a rock'
+ lint:'Check syntax of a rockspec'
+ list:'List currently installed rocks'
+ make:'Compile package in current directory using a rockspec'
+ new_version:'Auto-write a rockspec for a new version of a rock'
+ pack:'Create a rock, packing sources or binaries'
+ path:'Return the currently configured package path'
+ purge:'Remove all installed rocks from a tree'
+ remove:'Uninstall a rock'
+ search:'Query the LuaRocks servers'
+ show:'Show information about an installed rock'
+ unpack:'Unpack the contents of a rock'
+ upload:'Upload a rockspec to the public rocks repository'
+ write_rockspec:'Write a template for a rockspec file'
+ )
+ _describe -t commands 'command' commands "$@"
}
# }}}
# {{{ helper: dependencies mode
local option_deps_mode='--deps-mode=[How to handle dependencies]:MODE:__luarocks_deps_mode'
__luarocks_deps_mode(){
- local modes=(
- 'all:use all trees from the rocks_trees list for finding dependencies'
- 'one:use only the current tree (possibly set with --tree)'
- 'order:use trees based on order (use the current tree and all trees below it on the rocks_trees list)'
- 'none:ignore dependencies altogether'
- )
- _describe 'dependencies mode' modes
+ local modes=(
+ 'all:use all trees from the rocks_trees list for finding dependencies'
+ 'one:use only the current tree (possibly set with --tree)'
+ 'order:use trees based on order (use the current tree and all trees below it on the rocks_trees list)'
+ 'none:ignore dependencies altogether'
+ )
+ _describe 'dependencies mode' modes
}
# }}}
# {{{ helper: versions of an external rock or nothing for rockspec file
__luarocks_rock_version(){
- local i=2
- while [[ -n "${words[$i]}" ]]; do
- if [[ ! "${words[$i]}" =~ '^-' ]]; then
- case "$1" in
- "external_or_local")
- if [[ ! -f "${words[$i]}" ]]; then
- _message -e "version for external rock ${words[$i]}"
- return
- else
- _message -e "version for local rock ${words[$i]}"
- fi
- ;;
- "installed")
- # TODO: actually complete versions of installed rocks using the cache
- # How does luarocks handles multiple versions of the same package?
- # If anybody knows, please write something beautiful here
- _message -e "version for installed rock ${words[$i]}"
- return
- ;;
- "new_version")
- if [[ -f "${words[$i]}" ]]; then
- _message -e "new version for rock ${words[$i]}"
- return
- fi
- ;;
- "new_rock")
- _message -e "version for new rock ${words[$i]}"
- return
- ;;
- esac
- fi
- i=$(( i + 1 ))
- done
+ local i=2
+ while [[ -n "${words[$i]}" ]]; do
+ if [[ ! "${words[$i]}" =~ '^-' ]]; then
+ case "$1" in
+ "external_or_local")
+ if [[ ! -f "${words[$i]}" ]]; then
+ _message -e "version for external rock ${words[$i]}"
+ return
+ else
+ _message -e "version for local rock ${words[$i]}"
+ fi
+ ;;
+ "installed")
+ # TODO: actually complete versions of installed rocks using the cache
+ # How does luarocks handles multiple versions of the same package?
+ # If anybody knows, please write something beautiful here
+ _message -e "version for installed rock ${words[$i]}"
+ return
+ ;;
+ "new_version")
+ if [[ -f "${words[$i]}" ]]; then
+ _message -e "new version for rock ${words[$i]}"
+ return
+ fi
+ ;;
+ "new_rock")
+ _message -e "version for new rock ${words[$i]}"
+ return
+ ;;
+ esac
+ fi
+ i=$(( i + 1 ))
+ done
}
# }}}
# {{{ helper: lua versions
__luarocks_lua_versions(){
- _values -s , 5.3 5.2 5.1
+ _values -s , 5.3 5.2 5.1
}
# }}}
# {{{ helper: installed rocks cache policy
___luarocks_installed_rocks_cache_policy(){
- # TODO enable the user to configure manifests file that will be checked here with zstyle
- # the number of seconds since 1970-01-01 the manifest file was modified
- local manifest_last_date_modified="$(date -r ~/.luarocks/lib/luarocks/rocks-5.3/manifest +%s 2>/dev/null)"
- # the number of seconds since 1970-01-01 the cache file was modified
- local cache_last_date_modified="$(date -r $1 +%s 2>/dev/null)"
- if [[ ! -z ${cache_last_date_modified} && ! -z ${manifest_last_date_modified} ]]; then
- # if the manifest file is newer then the cache:
- if [ ${manifest_last_date_modified} -ge ${cache_last_date_modified} ]; then
- (( 1 ))
- else
- (( 0 ))
- fi
- else
- (( 1 ))
- fi
+ # TODO enable the user to configure manifests file that will be checked here with zstyle
+ # the number of seconds since 1970-01-01 the manifest file was modified
+ local manifest_last_date_modified="$(date -r ~/.luarocks/lib/luarocks/rocks-5.3/manifest +%s 2>/dev/null)"
+ # the number of seconds since 1970-01-01 the cache file was modified
+ local cache_last_date_modified="$(date -r $1 +%s 2>/dev/null)"
+ if [[ ! -z ${cache_last_date_modified} && ! -z ${manifest_last_date_modified} ]]; then
+ # if the manifest file is newer then the cache:
+ if [ ${manifest_last_date_modified} -ge ${cache_last_date_modified} ]; then
+ (( 1 ))
+ else
+ (( 0 ))
+ fi
+ else
+ (( 1 ))
+ fi
}
# }}}
# {{{ helper: installed rocks
__luarocks_installed_rocks(){
- local update_policy
- zstyle -s ":completion:${curcontext}:" cache-policy update_policy
- if [[ -z "$update_policy" ]]; then
- zstyle ":completion:${curcontext}:" cache-policy ___luarocks_installed_rocks_cache_policy
- fi
- if _cache_invalid luarocks_installed_list; then
- rocks_list=($(luarocks list --porcelain))
- _store_cache luarocks_installed_list rocks_list
- else
- _retrieve_cache luarocks_installed_list
- fi
- if _cache_invalid luarocks_installed_names; then
- rocks_names=()
- for i in {1.."${#rocks_list[@]}"..4}; do
- rocks_names+=("${rocks_list[$i]}")
- done
- _store_cache luarocks_installed_names rocks_names
- else
- _retrieve_cache luarocks_installed_names
- fi
- if _cache_invalid luarocks_installed_versions; then
- rocks_versions=()
- for i in {2.."${#rocks_list[@]}"..4}; do
- rocks_versions+=("${rocks_list[$i]}")
- done
- _store_cache luarocks_installed_versions rocks_versions
- else
- _retrieve_cache luarocks_installed_versions
- fi
- if _cache_invalid luarocks_installed_descriptions; then
- rocks_descriptions=()
- for i in {1.."${#rocks_names[@]}"}; do
- name_version_description="$(luarocks show ${rocks_names[$i]} | head -2 | tail -1)"
- total_length=${#name_version_description}
- garbage_length="$((${#rocks_names[$i]} + ${#rocks_versions[$i]} + 5))"
- description="${name_version_description[${garbage_length},${total_length}]}"
- rocks_descriptions+=("${description}")
- done
- _store_cache luarocks_installed_descriptions rocks_descriptions
- else
- _retrieve_cache luarocks_installed_descriptions
- fi
- if _cache_invalid luarocks_installed_names_and_descriptions; then
- rocks_names_and_descriptions=()
- for i in {1.."${#rocks_names[@]}"}; do
- name_and_description=${rocks_names[$i]}:${rocks_descriptions[$i]}
- rocks_names_and_descriptions+=(${name_and_description})
- done
- else
- _store_cache luarocks_installed_names_and_descriptions rocks_names_and_descriptions
- fi
- _describe 'installed rocks' rocks_names_and_descriptions
+ local update_policy
+ zstyle -s ":completion:${curcontext}:" cache-policy update_policy
+ if [[ -z "$update_policy" ]]; then
+ zstyle ":completion:${curcontext}:" cache-policy ___luarocks_installed_rocks_cache_policy
+ fi
+ if _cache_invalid luarocks_installed_list; then
+ rocks_list=($(luarocks list --porcelain))
+ _store_cache luarocks_installed_list rocks_list
+ else
+ _retrieve_cache luarocks_installed_list
+ fi
+ if _cache_invalid luarocks_installed_names; then
+ rocks_names=()
+ for i in {1.."${#rocks_list[@]}"..4}; do
+ rocks_names+=("${rocks_list[$i]}")
+ done
+ _store_cache luarocks_installed_names rocks_names
+ else
+ _retrieve_cache luarocks_installed_names
+ fi
+ if _cache_invalid luarocks_installed_versions; then
+ rocks_versions=()
+ for i in {2.."${#rocks_list[@]}"..4}; do
+ rocks_versions+=("${rocks_list[$i]}")
+ done
+ _store_cache luarocks_installed_versions rocks_versions
+ else
+ _retrieve_cache luarocks_installed_versions
+ fi
+ if _cache_invalid luarocks_installed_descriptions; then
+ rocks_descriptions=()
+ for i in {1.."${#rocks_names[@]}"}; do
+ name_version_description="$(luarocks show ${rocks_names[$i]} | head -2 | tail -1)"
+ total_length=${#name_version_description}
+ garbage_length="$((${#rocks_names[$i]} + ${#rocks_versions[$i]} + 5))"
+ description="${name_version_description[${garbage_length},${total_length}]}"
+ rocks_descriptions+=("${description}")
+ done
+ _store_cache luarocks_installed_descriptions rocks_descriptions
+ else
+ _retrieve_cache luarocks_installed_descriptions
+ fi
+ if _cache_invalid luarocks_installed_names_and_descriptions; then
+ rocks_names_and_descriptions=()
+ for i in {1.."${#rocks_names[@]}"}; do
+ name_and_description=${rocks_names[$i]}:${rocks_descriptions[$i]}
+ rocks_names_and_descriptions+=(${name_and_description})
+ done
+ else
+ _store_cache luarocks_installed_names_and_descriptions rocks_names_and_descriptions
+ fi
+ _describe 'installed rocks' rocks_names_and_descriptions
}
# }}}
# {{{ helper: rocks wrapper
@@ -161,35 +161,35 @@ __luarocks_installed_rocks(){
# - .src.rock file
# - external rock
__luarocks_rock(){
- local -a alts=()
- for arg in "$@"; do
- case $arg in
- (rockspec)
- alts+=(':rock file:{_files -g "*.rockspec"}')
- ;;
- (rockpack)
- alts+=(':rock file:{_files -g "*.src.rock"}')
- ;;
- (external)
- alts+=(':external rock:')
- ;;
- (installed)
- alts+=(':local rock:__luarocks_installed_rocks')
- ;;
- esac
- done
- _alternative ${alts[@]}
+ local -a alts=()
+ for arg in "$@"; do
+ case $arg in
+ (rockspec)
+ alts+=(':rock file:{_files -g "*.rockspec"}')
+ ;;
+ (rockpack)
+ alts+=(':rock file:{_files -g "*.src.rock"}')
+ ;;
+ (external)
+ alts+=(':external rock:')
+ ;;
+ (installed)
+ alts+=(':local rock:__luarocks_installed_rocks')
+ ;;
+ esac
+ done
+ _alternative ${alts[@]}
}
# }}}
# {{{ helper: git tags
__luarocks_git_tags(){
- autoload +X _git
- local _git_def="$(whence -v _git)"
- . ${_git_def##* }
- type __git_tags &> /dev/null
- if [[ $? != 1 ]]; then
- __git_tags
- fi
+ autoload +X _git
+ local _git_def="$(whence -v _git)"
+ . ${_git_def##* }
+ type __git_tags &> /dev/null
+ if [[ $? != 1 ]]; then
+ __git_tags
+ fi
}
# }}}
@@ -198,71 +198,71 @@ __luarocks_git_tags(){
# - must: .rockspec file / external rock
# - optional: version (only when chossing external rock)
local make_command_options=(
- '--pack-binary-rock[Produce a .rock file with the contents of compilation inside the current directory instead of installing it]'
- '--keep[Do not remove previously installed versions of the rock after building a new one]'
- '--branch=[Override the `source.branch` field in the loaded rockspec]:NAME:{_message "branch name"}'
+ '--pack-binary-rock[Produce a .rock file with the contents of compilation inside the current directory instead of installing it]'
+ '--keep[Do not remove previously installed versions of the rock after building a new one]'
+ '--branch=[Override the `source.branch` field in the loaded rockspec]:NAME:{_message "branch name"}'
)
local build_command_options=(
- "${make_command_options[@]}"
- '--only-deps[Installs only the dependencies of the rock]'
- $option_deps_mode
+ "${make_command_options[@]}"
+ '--only-deps[Installs only the dependencies of the rock]'
+ $option_deps_mode
)
_luarocks_build(){
- _arguments -A "-*" \
- "${build_command_options[@]}" \
- '1: :{__luarocks_rock "rockspec" "external"}' \
- '2:: :{__luarocks_rock_version "external_or_local"}'
+ _arguments -A "-*" \
+ "${build_command_options[@]}" \
+ '1: :{__luarocks_rock "rockspec" "external"}' \
+ '2:: :{__luarocks_rock_version "external_or_local"}'
}
# }}}
# {{{ `config` command
# arguments:
# - must: option
local config_command_options=(
- '--lua-incdir[Path to Lua header files]'
- '--lua-libdir[Path to Lua library files]'
- '--lua-ver[Lua version (in major.minor format)]'
- '--system-config[Location of the system config file]'
- '--user-config[Location of the user config file]'
- '--rock-trees[Rocks trees in useFirst the user tree, then the system tree]'
+ '--lua-incdir[Path to Lua header files]'
+ '--lua-libdir[Path to Lua library files]'
+ '--lua-ver[Lua version (in major.minor format)]'
+ '--system-config[Location of the system config file]'
+ '--user-config[Location of the user config file]'
+ '--rock-trees[Rocks trees in useFirst the user tree, then the system tree]'
)
_luarocks_config(){
- _arguments "${config_command_options[@]}"
+ _arguments "${config_command_options[@]}"
}
# }}}
# {{{ `doc` command
# arguments:
# - must: installed rock
local doc_command_options=(
- '--home[Open the home page of project]'
- '--list[List documentation files only]'
+ '--home[Open the home page of project]'
+ '--list[List documentation files only]'
)
_luarocks_doc(){
- _arguments \
- "${doc_command_options[@]}" \
- '1: :{__luarocks_rock "installed"}'
+ _arguments \
+ "${doc_command_options[@]}" \
+ '1: :{__luarocks_rock "installed"}'
}
# }}}
# {{{ `download` command
# arguments:
# - must: external only rockspec
local download_command_options=(
- '--all[Download all files if there are multiple matches]'
- '--source[Download .src.rock if available]'
- '--rockspec[Download .rockspec if available]'
- '--arch=[Download rock for a specific architecture]:ARCH:'
+ '--all[Download all files if there are multiple matches]'
+ '--source[Download .src.rock if available]'
+ '--rockspec[Download .rockspec if available]'
+ '--arch=[Download rock for a specific architecture]:ARCH:'
)
_luarocks_download(){
- _arguments -A "-*" \
- "${download_command_options[@]}" \
- '1: :{__luarocks_rock "external"}' \
- '2:: :{__luarocks_rock_version "external_or_local"}'
+ _arguments -A "-*" \
+ "${download_command_options[@]}" \
+ '1: :{__luarocks_rock "external"}' \
+ '2:: :{__luarocks_rock_version "external_or_local"}'
}
# }}}
# {{{ `help` command
# arguments:
# must: luarocks sub command
_luarocks_help(){
- _arguments '1: :__luarocks_command'
+ _arguments '1: :__luarocks_command'
}
# }}}
# {{{ `install` command
@@ -271,24 +271,24 @@ _luarocks_help(){
# - optional: version
# NOTE: it receives the same argument as the build command and it accepts the same options as well
_luarocks_install(){
- _luarocks_build
+ _luarocks_build
}
# }}}
# {{{ `lint` command
# arguments:
# - must: rockspec file (first and last)
_luarocks_lint(){
- _arguments '1::{__luarocks_rock "rockspec"}'
+ _arguments '1::{__luarocks_rock "rockspec"}'
}
# }}}
# {{{ `list` command
# NOTE: receives only options
local list_command_options=(
- '--outdated[List only rocks for which there is a higher version available in the rocks server]'
- '--porcelain[Produce machine-friendly output]'
+ '--outdated[List only rocks for which there is a higher version available in the rocks server]'
+ '--porcelain[Produce machine-friendly output]'
)
_luarocks_list(){
- _arguments "${list_command_options[@]}"
+ _arguments "${list_command_options[@]}"
}
# }}}
# {{{ `make` command
@@ -296,7 +296,7 @@ _luarocks_list(){
# - optional: rockspec file
# NOTE: it's options were already described above.
_luarocks_make(){
- _arguments '1:: :{__luarocks_rock "rockspec"}'
+ _arguments '1:: :{__luarocks_rock "rockspec"}'
}
# }}}
# {{{ `new_version` command
@@ -305,14 +305,14 @@ _luarocks_make(){
# - optional: version (unless a --tag was given)
# - optional: URL
local new_version_command_options=(
- '--tag=[if no version is specified, this option'"'"'s argument is used instead]:TAG:__luarocks_git_tags'
+ '--tag=[if no version is specified, this option'"'"'s argument is used instead]:TAG:__luarocks_git_tags'
)
_luarocks_new_version(){
- _arguments -A "-*" \
- "${new_version_command_options[@]}" \
- '1:: :{__luarocks_rock "external" "rockspec"}' \
- '2:: :{__luarocks_rock_version "external_or_local"}' \
- '3:: :_urls'
+ _arguments -A "-*" \
+ "${new_version_command_options[@]}" \
+ '1:: :{__luarocks_rock "external" "rockspec"}' \
+ '2:: :{__luarocks_rock_version "external_or_local"}' \
+ '3:: :_urls'
}
# }}}
# {{{ `pack` command
@@ -320,20 +320,20 @@ _luarocks_new_version(){
# - must: .rockspec file / external rock
# - optional: version
_luarocks_pack(){
- _luarocks_build
+ _luarocks_build
}
# }}}
# {{{ `path` command
# NOTE: receives only options
local path_command_options=(
- '--bin[Adds the system path to the output]'
- '--append[Appends the paths to the existing paths]'
- '--lr-path[Exports the Lua path (not formatted as shell command)]'
- '--lr-cpath[Exports the Lua cpath (not formatted as shell command)]'
- '--lr-bin[Exports the system path (not formatted as shell command)]'
+ '--bin[Adds the system path to the output]'
+ '--append[Appends the paths to the existing paths]'
+ '--lr-path[Exports the Lua path (not formatted as shell command)]'
+ '--lr-cpath[Exports the Lua cpath (not formatted as shell command)]'
+ '--lr-bin[Exports the system path (not formatted as shell command)]'
)
_luarocks_path(){
- _arguments "${path_command_options[@]}"
+ _arguments "${path_command_options[@]}"
}
# }}}
# {{{ `purge` command
@@ -341,11 +341,11 @@ _luarocks_path(){
# NOTE: --force can be used only in conjunction with --old-versions
local option_force='--force[Force removing old versions when]'
local purge_command_options=(
- '--old-versions[Keep the highest-numbered version of each rock and remove the other ones]'
- $option_force
+ '--old-versions[Keep the highest-numbered version of each rock and remove the other ones]'
+ $option_force
)
_luarocks_purge(){
- _arguments "${purge_command_options[@]}"
+ _arguments "${purge_command_options[@]}"
}
# }}}
# {{{ `remove` command
@@ -354,47 +354,47 @@ _luarocks_purge(){
# - optional: version
local option_force_fast='--force-fast[works like --force but doesn'"'"'t reports forced removals]'
local remove_command_options=(
- $option_deps_mode
- $option_force
- $option_force_fast
+ $option_deps_mode
+ $option_force
+ $option_force_fast
)
_luarocks_remove(){
- _arguments -A "-*" \
- "${remove_command_options[@]}" \
- '1: :{__luarocks_rock "installed"}' \
- '2:: :{__luarocks_rock_version "installed"}'
+ _arguments -A "-*" \
+ "${remove_command_options[@]}" \
+ '1: :{__luarocks_rock "installed"}' \
+ '2:: :{__luarocks_rock_version "installed"}'
}
# }}}
# {{{ `search` command
# arguments:
# - must: string as a search query
local search_command_options=(
- '--source[Return only rockspecs and source rocks]'
- '--binary[Return only pure Lua and binary rocks (rocks that can be used with the "install" command without requiring a C toolchain)]'
- '--all[List all contents of the server that are suitable to this platform, do not filter by name]'
+ '--source[Return only rockspecs and source rocks]'
+ '--binary[Return only pure Lua and binary rocks (rocks that can be used with the "install" command without requiring a C toolchain)]'
+ '--all[List all contents of the server that are suitable to this platform, do not filter by name]'
)
_luarocks_search(){
- _arguments \
- "${search_command_options[@]}" \
- '*:SEARCH QUERY:'
+ _arguments \
+ "${search_command_options[@]}" \
+ '*:SEARCH QUERY:'
}
# }}}
# {{{ `show` command
# arguments:
# - must: installed rock
local show_command_options=(
- '--home[home page of project]'
- '--modules[all modules provided by this package as used by require()]'
- '--deps[packages this package depends on]'
- '--rockspec[the full path of the rockspec file]'
- '--mversion[the package version]'
- '--rock-tree[local tree where rock is installed]'
- '--rock-dir[data directory of the installed rock]'
+ '--home[home page of project]'
+ '--modules[all modules provided by this package as used by require()]'
+ '--deps[packages this package depends on]'
+ '--rockspec[the full path of the rockspec file]'
+ '--mversion[the package version]'
+ '--rock-tree[local tree where rock is installed]'
+ '--rock-dir[data directory of the installed rock]'
)
_luarocks_show(){
- _arguments \
- "${show_command_options[@]}" \
- '1: :{__luarocks_rock "installed"}'
+ _arguments \
+ "${show_command_options[@]}" \
+ '1: :{__luarocks_rock "installed"}'
}
# }}}
# {{{ `unpack` command
@@ -402,26 +402,26 @@ _luarocks_show(){
# - must: rockpack file / external rock
# - optional: version (only when chossing external rock)
local unpack_command_options=(
- '--force[Unpack files even if the output directory already exists]'
+ '--force[Unpack files even if the output directory already exists]'
)
_luarocks_unpack(){
- _arguments \
- "${unpack_command_options[@]}" \
- '1: :{__luarocks_rock "rockpack" "external"}'
+ _arguments \
+ "${unpack_command_options[@]}" \
+ '1: :{__luarocks_rock "rockpack" "external"}'
}
# }}}
# {{{ `upload` command
# arguments:
# - must: rockspec file
local upload_command_options=(
- '--skip-pack[Do not pack and send source rock]'
- '--api-key=[Give it an API key]:KEY:{_message "api key"}'
- '--force[Replace existing rockspec if the same revision of a module already exists]'
+ '--skip-pack[Do not pack and send source rock]'
+ '--api-key=[Give it an API key]:KEY:{_message "api key"}'
+ '--force[Replace existing rockspec if the same revision of a module already exists]'
)
_luarocks_upload(){
- _arguments \
- "${upload_command_options[@]}" \
- '1: :{__luarocks_rock "rockspec"}'
+ _arguments \
+ "${upload_command_options[@]}" \
+ '1: :{__luarocks_rock "rockspec"}'
}
# }}}
# {{{ `write_rockspec` command
@@ -431,43 +431,43 @@ _luarocks_upload(){
# - optional: URL / PATH
# receives as an argument a name and a version with optionally a URL/PATH
local write_rockspec_command_options=(
- '--output=[Write the rockspec with the given filename]:FILE:_files'
- '--license=[A license string, ]:LICENSE:{_message -e "write a license string such as "MIT/X11" or "GNU GPL v3"}'
- '--summary=[A short one-line description summary]:SUMMARY_TEXT:{_message -e "write a short summary of the rock"}'
- '--detailed=[A longer description string]:DETAILED_TEXT:{_message -e "write a detailed description of the rock"}'
- '--homepage=[Project homepage]:URL:_urls'
- '--lua-version=[Supported Lua versions]:LUA_VER:__luarocks_lua_versions'
- '--rockspec-format=[Rockspec format version, such as "1.0" or "1.1"]:VER: '
- '--tag=[Tag to use. Will attempt to extract version number from it]:TAG:__git_tag'
- '--lib=[A comma-separated list of libraries that C files need to link to]:'
+ '--output=[Write the rockspec with the given filename]:FILE:_files'
+ '--license=[A license string, ]:LICENSE:{_message -e "write a license string such as "MIT/X11" or "GNU GPL v3"}'
+ '--summary=[A short one-line description summary]:SUMMARY_TEXT:{_message -e "write a short summary of the rock"}'
+ '--detailed=[A longer description string]:DETAILED_TEXT:{_message -e "write a detailed description of the rock"}'
+ '--homepage=[Project homepage]:URL:_urls'
+ '--lua-version=[Supported Lua versions]:LUA_VER:__luarocks_lua_versions'
+ '--rockspec-format=[Rockspec format version, such as "1.0" or "1.1"]:VER: '
+ '--tag=[Tag to use. Will attempt to extract version number from it]:TAG:__git_tag'
+ '--lib=[A comma-separated list of libraries that C files need to link to]:'
)
_luarocks_write_rockspec(){
- _arguments -A "-*" \
- "${write_rockspec_command_options[@]}" \
- '1:: :{_message "new rock name"}' \
- '2:: :{__luarocks_rock_version "new_rock"}' \
- '3:: :_urls'
+ _arguments -A "-*" \
+ "${write_rockspec_command_options[@]}" \
+ '1:: :{_message "new rock name"}' \
+ '2:: :{__luarocks_rock_version "new_rock"}' \
+ '3:: :_urls'
}
# }}}
# The real thing
_arguments -C \
- '(--server --only-server)--server=[Fetch rocks/rockspecs from this server]:HOST:_hosts' \
- '(--server --only-server)--only-server=[Fetch rocks/rockspecs from this server only]:HOST:_hosts' \
- '--only-sources=[Restrict downloads to paths matching the given URL]:URL:_urls' \
- '--tree=[Which tree to operate on]:TREE:{_files -/}' \
- '--local[Use the tree in the user'"'"'s home directory]' \
- '--verbose[Display verbose output of commands executed]' \
- '--timeout=[Timeout on network operations]:SECONDS:{_message "timeout (seconds)"}' \
- '1: :__luarocks_command' \
- '*::arg:->args'
+ '(--server --only-server)--server=[Fetch rocks/rockspecs from this server]:HOST:_hosts' \
+ '(--server --only-server)--only-server=[Fetch rocks/rockspecs from this server only]:HOST:_hosts' \
+ '--only-sources=[Restrict downloads to paths matching the given URL]:URL:_urls' \
+ '--tree=[Which tree to operate on]:TREE:{_files -/}' \
+ '--local[Use the tree in the user'"'"'s home directory]' \
+ '--verbose[Display verbose output of commands executed]' \
+ '--timeout=[Timeout on network operations]:SECONDS:{_message "timeout (seconds)"}' \
+ '1: :__luarocks_command' \
+ '*::arg:->args'
case "$state" in
- (args)
- curcontext="${curcontext%:*:*}:luarocks_${words[1]}:"
- # check if a command with a defined completion was typed
- type _luarocks_${words[1]} &> /dev/null
- if [[ $? != 1 ]]; then
- _luarocks_${words[1]}
- fi
+ (args)
+ curcontext="${curcontext%:*:*}:luarocks_${words[1]}:"
+ # check if a command with a defined completion was typed
+ type _luarocks_${words[1]} &> /dev/null
+ if [[ $? != 1 ]]; then
+ _luarocks_${words[1]}
+ fi
esac
diff --git a/src/_pip b/src/_pip
deleted file mode 100644
index cab7fda31..000000000
--- a/src/_pip
+++ /dev/null
@@ -1,326 +0,0 @@
-#compdef pip
-
-# {{{ common options
-local common_options_help=(
- '(- :)'{-h,--help}'[show help]'
-)
-local common_options_pre=(
- '--pre[Include pre-release and development versions]'
-)
-local common_options_install=(
- {\*-c,\*--constraint}'[Constrain versions using the given constraints file]:FILE:_files'
- '(- :)'{-e,--editable}'[Install a project in editable mode (i.e. setuptools "develop mode") from a local project path or a VCS url]:PACKAGE:{__pip_package "url" "file"}'
- {\*-r,\*--requirement}'[Install from the given requirements file]:FILE:_files'
- {-b,--build}'[Directory to unpack packages into and build in]:DIRECTORY:_files -/'
- "--no-deps[Don't install package dependencies]"
- "${common_options_pre[@]}"
- '*--global-option=[Extra global options to be supplied to the setup.py call before the install command]:OPTION:_setup.py'
- '*--no-binary[Do not use binary packages]:FORMAT_CONTROL:__pip_no_binary_control'
- '*--only-binary[Do not use binary packages]:FORMAT_CONTROL:__pip_only_binary_control'
- "--no-clean[Don't clean up build directories]"
- '--require-hashes[Require a hash to check each requirement against, for repeatable installs]'
-)
-local common_options_wheel=(
- "${common_options_install[@]}"
- '--src[Directory to check out editable projects into]:DIRECTORY:_files -/'
- '--ignore-requires-python[Ignore the Requires-Python information]'
-)
-local common_options_index=(
- '(--no-index)'{-i,--index-url}'[Base URL of Python Package Index (default https://pypi.python.org/simple)]:URL:_urls'
- '(--no-index)*--extra-index-url[Extra URLs of package indexes to use in addition to --index-url]:URL:_urls'
- '(-i --index-url)--no-index[Ignore package index (only looking at --find-links URLs instead)]'
- {-f,--find-links}'[If a url or path to an html file, then parse for links to archives]:URL:__pip_find_links'
- '--process-dependency-links[Enable the processing of dependency links]'
-)
-local common_options_user=(
- '--user\[Only output packages installed in user-site\]'
-)
-local common_options_local=(
- {-l,--local}'[If in a virtualenv that has global access, do not output globally-installed packages]'
-)
-# }}}
-# {{{ helper: installed packages cache policy
-__pip_install_packages_cache_policy(){
- # TODO: workout a way that will let users configure via zstyle locations of site-packages
- # the number of seconds since 1970-01-01 the site-packages directories were changed
- local site_packages_user_dir_last_date_modified="$(date -r ~/.local/lib/python3.6/site-packages +%s 2>/dev/null)"
- local site_packages_system_dir_last_date_modified="$(date -r /usr/lib/python3.6/site-packages +%s 2>/dev/null)"
- # the number of seconds since 1970-01-01 the cache file was modified
- local cache_last_date_modified="$(date -r $1 +%s 2>/dev/null)"
- if [[ ! -z "${cache_last_date_modified}" ]] && [[ ! -z "${site_packages_user_dir_last_date_modified}" || ! -z "${site_packages_system_dir_last_date_modified}" ]]; then
- # if the manifest file is newer then the cache:
- if [[ ${site_packages_user_dir_last_date_modified} -ge ${cache_last_date_modified} ]] || [[ ${site_packages_system_dir_last_date_modified} -ge ${cache_last_date_modified} ]]; then
- (( 1 ))
- else
- (( 0 ))
- fi
- else
- (( 1 ))
- fi
-}
-# }}}
-# {{{ helper: installed packages (using cache)
-__pip_installed() {
- local update_policy
- zstyle -s ":completion:${curcontext}:" cache-policy update_policy
- if [[ -z "$update_policy" ]]; then
- zstyle ":completion:${curcontext}:" cache-policy __pip_install_packages_cache_policy
- fi
- if _cache_invalid pip_installed_packages; then
- installed_packages=($(pip list --format freeze | sed -n -e 's/\([-a-z_]\+\)==.*/\1/p'))
- _store_cache pip_installed_packages installed_packages
- else
- _retrieve_cache pip_installed_packages
- fi
- _values "installed packages" "${installed_packages[@]}"
-}
-# }}}
-# {{{ helper: available commands
-local commands=(
- 'install:install packages'
- 'download:download packages'
- 'uninstall:uninstall packages'
- 'freeze:output all currently installed packages (exact versions) to stdout'
- 'list:list installed packages'
- 'show:show information about installed packages'
- 'search:search PyPI'
- 'wheel:build individual wheel archives for your requirements and dependencies'
- 'hash:compute a hash of a local package archive'
- 'help:show available commands'
-)
-__pip_commands(){
- _describe "pip command" commands
-}
-# }}}
-# {{{ helper: installable packages wrapper
-__pip_package(){
- local -a alts
- for arg in "$@"; do
- case $arg in
- "url")
- alts+=(':URL of package:_urls')
- ;;
- "file")
- alts+=(':package repo or archive:_files')
- ;;
- esac
- done
- _alternative "${alts[@]}"
-}
-# }}}
-# {{{ helper: upgrade strategy
-__pip_upgrade_strategy(){
- local strategies=(
- "eager:dependencies are upgraded whether currently installed version satisfies the requirements or not"
- "only-if-needed:are upgraded only when they do not satisfy the requirements of the upgraded package(s)"
- )
- _describe "strategy" strategies
-}
-# }}}
-# {{{ helper: binary control
-__pip_no_binary_control(){
- local options=(
- 'all:"disable all binary packages"'
- 'none:"enable all binary packages"'
- )
- _alternative ": :((${options[@]}))" ": :_message 'packages to install or use:'"
-}
-__pip_only_binary_control(){
- local options=(
- 'all:"enable all binary packages"'
- 'none:"disable all binary packages"'
- )
- _alternative ": :((${options[@]}))" ": :{_message 'packages to install or use:'}"
-}
-# }}}
-# {{{ helper: look for html file or url with links to packages or find packages in a directory
-__pip_find_links(){
- _alternative ': :_urls' ': :_files -g ".html"' ': :_files -/'
-}
-# }}}
-# {{{ helper: urls or files to install
-__pip_install_packages(){
- _alternative ': :_urls' ': :_files'
-}
-# }}}
-# {{{ command install
-local command_install_options=(
- "${common_options_help[@]}"
- "${common_options_wheel[@]}"
- "${common_options_index[@]}"
- {-t,--target}'[Install packages into DIRECTORY]:DIRECTORY:_files -/'
- {-d,--download}"[Download packages into <dir> instead of installing them, regardless of what's already installed]:DIRECTORY:_files -/"
- {-U,--upgrade}'[Upgrade all specified packages to the newest available version]'
- '--upgrade-strategy[Determines how dependency upgrading should be handled]:STRATEGY:__pip_upgrade_strategy'
- '--force-reinstall[When upgrading, reinstall all packages even if they are already up-to-date]'
- {-I,--ignore-installed}'[Ignore the installed packages (reinstalling instead)]'
- # TODO: autoload _setup.py to complete options for it
- '*--install-option=[Extra arguments to be supplied to the setup.py install command]:OPTION:_setup.py'
- '--user[Install to the Python user install directory for your platform]'
- "--egg[Install packages as eggs, not 'flat', like pip normally does]"
- '--root[Install everything relative to this alternate root directory]:DIRECTORY:_files -/'
- '--prefix[Installation prefix where lib, bin and other top-level folders are place]:DIRECTORY:_files -/'
- '--compile[Compile py files to pyc]'
- '--no-compile[Do not compile py files to pyc]'
- '--no-use-wheel[DEPRECATED in favour of --no-binary]'
-)
-_pip_install(){
- _arguments \
- "${command_install_options[@]}" \
- '*:PACKAGE:__pip_install_packages'
-}
-# }}}
-# {{{ command download
-local command_download_options=(
- "${common_options_help[@]}"
- "${common_options_install[@]}"
- "${common_options_index[@]}"
- '--src[Directory to check out editable projects into]:DIRECTORY:_files -/'
- {-d,--dest}'[Download packages into DIRECTORY]:DIRECTORY:_files -/'
- '--platform[Only download wheels compatible with PLATFORM]:PLATFORM:'
- '--python-version[Only download wheels compatible with Python interpreter version VERSION]:VERSION:'
- '--implementation[Only download wheels compatible with Python implementation IMPLEMENTATION]:IMPLEMENTATION:'
- '--abi[Only download wheels compatible with Python abi ABI]:ABI:'
-)
-_pip_download(){
- _arguments \
- "${command_download_options[@]}" \
- '*:PACKAGE:__pip_install_packages'
-}
-# }}}
-# {{{ command uninstall
-local command_uninstall_options=(
- "${common_options_help[@]}"
- {\*-r,\*--requirement}'[Uninstall all the packages listed in the given requirements file]:FILE:_files'
- {-y,--yes}"[Don't ask for confirmation of uninstall deletions]"
-)
-_pip_uninstall(){
- _arguments \
- "${command_uninstall_options[@]}" \
- '*: :__pip_installed'
-}
-# }}}
-# {{{ command freeze
-local command_freeze_options=(
- "${common_options_help[@]}"
- "${common_options_local[@]}"
- "${common_options_user[@]}"
- {\*-r,\*--requirement}'[Use the order in the given requirements file and its comments when generating output]:FILE:_files'
- {-f,--find-links}'[URL for finding packages, which will be added to the output]:URL:_urls'
- '--all[Do not skip these packages in the output: pip, setuptools, distribute, wheel]'
-
-)
-_pip_freeze(){
- _arguments \
- "${command_freeze_options[@]}"
-}
-# }}}
-# {{{ command list
-local command_list_options=(
- "${common_options_help[@]}"
- "${common_options_local[@]}"
- "${common_options_user[@]}"
- "${common_options_pre[@]}"
- {-o,--outdated}'[List outdated packages]'
- {-u,--uptodate}'[List uptodate packages]'
- {-e,--editable}'[List editable projects]'
- '--format[Select the output format among]:FORMAT:(legacy columns freeze json)'
- '--not-required[List packages that are not dependencies of installed packages]'
- "${common_options_index[@]}"
-)
-_pip_list(){
- _arguments \
- "${command_list_options[@]}" \
- '1: :'
-}
-# }}}
-# {{{ command show
-local command_show_options=(
- "${common_options_help[@]}"
- {-f,--files}'[Show the full list of installed files for each package]'
-)
-_pip_show(){
- _arguments \
- "${command_show_options[@]}" \
- '*: :__pip_installed'
-}
-# }}}
-# {{{ command search
-local command_search_options=(
- "${common_options_help[@]}"
- {-i,--index}'[Base URL of Python Package Index (default https://pypi.python.org/pypi)]:URL:_urls'
-)
-_pip_search(){
- _arguments \
- "${command_search_options[@]}" \
- '*:QUERY:'
-}
-# }}}
-# {{{ command wheel
-local command_wheel_options=(
- "${common_options_help[@]}"
- "${common_options_wheel[@]}"
- "${common_options_index[@]}"
- '(--no-wheel-dir)'{-w,--wheel-dir}'[Build wheels into DIRECTORY (default is current working directory)]:DIRECTORY:_files -/'
- '(-w --wheel-dir)--no-wheel-dir[Do not Find and prefer wheel archives when searching indexes and find-links locations]'
-)
-_pip_wheel(){
- _arguments \
- "${command_wheel_options[@]}" \
- '*:PACKAGE:__pip_install_packages'
-}
-# }}}
-# {{{ command hash
-local command_hash_options=(
- "${common_options_help[@]}"
- {-a,--algorithm}'[The hash algorithm to use]:ALGORITHM:(sha256 sha384 sha512)'
-)
-_pip_hash(){
- _arguments \
- "${command_hash_options[@]}" \
- '1:PACKAGE_ARCHIVE:_files'
-}
-# }}}
-# {{{ command help
-local command_help_options=(
- "${common_options_help[@]}"
-)
-_pip_help(){
- _arguments \
- "${command_help_options[@]}" \
- '1:COMMAND:__pip_commands'
-}
-# }}}
-
-# The real thing
-_arguments \
- "${common_options_help[@]}" \
- '--isolated[run pip in isolated mode, ignores environment variables and user configuration]' \
- {-v,--verbose}'[give more output]' \
- {-V,--version}'[show version number of program and exit]' \
- {-q,--quiet}'[give less output]' \
- '--log[log file location]' \
- '--proxy=[proxy in form user:passwd@proxy.server:port]' \
- '--retries=[max number of retries per connection (default 5 times)]' \
- '--timeout=[socket timeout (default 15s)]' \
- '--exists-action=[default action when a path already exists: (s)witch, (i)gnore, (w)ipe, (b)ackup]' \
- '--trusted-host=[mark this host as trusted]' \
- '--cert=[path to alternate CA bundle]' \
- '--client-cert=[path to SSL client certificate]' \
- '--cache-dir=[store the cache data in specified directory]' \
- '--no-cache-dir[disable de cache]' \
- '--disable-pip-version-check[do not check periodically for new pip version downloads]' \
- {-E,--environment}'[virtualenv environment to run pip in (deprecated)]' \
- {-s,--enable-site-packages}'[include site-packages in virtualenv (deprecated)]' \
- '1: :__pip_commands' \
- '*::arg:->args'
-
-case "$state" in
- (args)
- curcontext="${curcontext%:*:*}:pip_${words[1]}:"
- # check if a command with a defined completion was typed
- type _pip_${words[1]} &> /dev/null
- if [[ $? != 1 ]]; then
- _pip_${words[1]}
- fi
-esac
--
2.17.0
^ permalink raw reply [flat|nested] 28+ messages in thread
* [PATCH 22/25] Use +functions[] for all helpers.
2018-05-26 15:06 [PATCH 00/25] *** Add completion for luarocks *** doron.behar
` (20 preceding siblings ...)
2018-05-26 15:06 ` [PATCH 21/25] Use 2 spaces instead of tabs doron.behar
@ 2018-05-26 15:06 ` doron.behar
2018-05-26 15:06 ` [PATCH 23/25] Improve `___luarocks_installed_rocks_cache_policy` doron.behar
` (3 subsequent siblings)
25 siblings, 0 replies; 28+ messages in thread
From: doron.behar @ 2018-05-26 15:06 UTC (permalink / raw)
To: zsh-workers
From: Doron Behar <doron.behar@gmail.com>
---
Completion/Unix/Command/_luarocks | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/Completion/Unix/Command/_luarocks b/Completion/Unix/Command/_luarocks
index 1dda38cad..cb42d1b36 100644
--- a/Completion/Unix/Command/_luarocks
+++ b/Completion/Unix/Command/_luarocks
@@ -1,6 +1,7 @@
#compdef luarocks
# {{{ helper: luarocks commands
+(( $+functions[__luarocks_command] )) ||
__luarocks_command(){
local -a commands=(
build:'Build/compile a rock'
@@ -28,6 +29,7 @@ __luarocks_command(){
# }}}
# {{{ helper: dependencies mode
local option_deps_mode='--deps-mode=[How to handle dependencies]:MODE:__luarocks_deps_mode'
+(( $+functions[__luarocks_deps_mode] )) ||
__luarocks_deps_mode(){
local modes=(
'all:use all trees from the rocks_trees list for finding dependencies'
@@ -39,6 +41,7 @@ __luarocks_deps_mode(){
}
# }}}
# {{{ helper: versions of an external rock or nothing for rockspec file
+(( $+functions[__luarocks_rock_version] )) ||
__luarocks_rock_version(){
local i=2
while [[ -n "${words[$i]}" ]]; do
@@ -76,11 +79,13 @@ __luarocks_rock_version(){
}
# }}}
# {{{ helper: lua versions
+(( $+functions[__luarocks_lua_versions] )) ||
__luarocks_lua_versions(){
_values -s , 5.3 5.2 5.1
}
# }}}
# {{{ helper: installed rocks cache policy
+(( $+functions[___luarocks_installed_rocks_cache_policy] )) ||
___luarocks_installed_rocks_cache_policy(){
# TODO enable the user to configure manifests file that will be checked here with zstyle
# the number of seconds since 1970-01-01 the manifest file was modified
@@ -100,6 +105,7 @@ ___luarocks_installed_rocks_cache_policy(){
}
# }}}
# {{{ helper: installed rocks
+(( $+functions[__luarocks_installed_rocks] )) ||
__luarocks_installed_rocks(){
local update_policy
zstyle -s ":completion:${curcontext}:" cache-policy update_policy
@@ -160,6 +166,7 @@ __luarocks_installed_rocks(){
# - .rockspec file
# - .src.rock file
# - external rock
+(( $+functions[__luarocks_rock] )) ||
__luarocks_rock(){
local -a alts=()
for arg in "$@"; do
@@ -182,6 +189,7 @@ __luarocks_rock(){
}
# }}}
# {{{ helper: git tags
+(( $+functions[__luarocks_git_tags] )) ||
__luarocks_git_tags(){
autoload +X _git
local _git_def="$(whence -v _git)"
@@ -207,6 +215,7 @@ local build_command_options=(
'--only-deps[Installs only the dependencies of the rock]'
$option_deps_mode
)
+(( $+functions[_luarocks_build] )) ||
_luarocks_build(){
_arguments -A "-*" \
"${build_command_options[@]}" \
@@ -225,6 +234,7 @@ local config_command_options=(
'--user-config[Location of the user config file]'
'--rock-trees[Rocks trees in useFirst the user tree, then the system tree]'
)
+(( $+functions[_luarocks_config] )) ||
_luarocks_config(){
_arguments "${config_command_options[@]}"
}
@@ -236,6 +246,7 @@ local doc_command_options=(
'--home[Open the home page of project]'
'--list[List documentation files only]'
)
+(( $+functions[_luarocks_doc] )) ||
_luarocks_doc(){
_arguments \
"${doc_command_options[@]}" \
@@ -251,6 +262,7 @@ local download_command_options=(
'--rockspec[Download .rockspec if available]'
'--arch=[Download rock for a specific architecture]:ARCH:'
)
+(( $+functions[_luarocks_download] )) ||
_luarocks_download(){
_arguments -A "-*" \
"${download_command_options[@]}" \
@@ -261,6 +273,7 @@ _luarocks_download(){
# {{{ `help` command
# arguments:
# must: luarocks sub command
+(( $+functions[_luarocks_help] )) ||
_luarocks_help(){
_arguments '1: :__luarocks_command'
}
@@ -270,6 +283,7 @@ _luarocks_help(){
# - must: .rockspec file / external rock
# - optional: version
# NOTE: it receives the same argument as the build command and it accepts the same options as well
+(( $+functions[_luarocks_install] )) ||
_luarocks_install(){
_luarocks_build
}
@@ -277,6 +291,7 @@ _luarocks_install(){
# {{{ `lint` command
# arguments:
# - must: rockspec file (first and last)
+(( $+functions[_luarocks_lint] )) ||
_luarocks_lint(){
_arguments '1::{__luarocks_rock "rockspec"}'
}
@@ -287,6 +302,7 @@ local list_command_options=(
'--outdated[List only rocks for which there is a higher version available in the rocks server]'
'--porcelain[Produce machine-friendly output]'
)
+(( $+functions[_luarocks_list] )) ||
_luarocks_list(){
_arguments "${list_command_options[@]}"
}
@@ -295,6 +311,7 @@ _luarocks_list(){
# arguments:
# - optional: rockspec file
# NOTE: it's options were already described above.
+(( $+functions[_luarocks_make] )) ||
_luarocks_make(){
_arguments '1:: :{__luarocks_rock "rockspec"}'
}
@@ -307,6 +324,7 @@ _luarocks_make(){
local new_version_command_options=(
'--tag=[if no version is specified, this option'"'"'s argument is used instead]:TAG:__luarocks_git_tags'
)
+(( $+functions[_luarocks_new_version] )) ||
_luarocks_new_version(){
_arguments -A "-*" \
"${new_version_command_options[@]}" \
@@ -319,6 +337,7 @@ _luarocks_new_version(){
# arguments:
# - must: .rockspec file / external rock
# - optional: version
+(( $+functions[_luarocks_pack] )) ||
_luarocks_pack(){
_luarocks_build
}
@@ -332,6 +351,7 @@ local path_command_options=(
'--lr-cpath[Exports the Lua cpath (not formatted as shell command)]'
'--lr-bin[Exports the system path (not formatted as shell command)]'
)
+(( $+functions[_luarocks_path] )) ||
_luarocks_path(){
_arguments "${path_command_options[@]}"
}
@@ -344,6 +364,7 @@ local purge_command_options=(
'--old-versions[Keep the highest-numbered version of each rock and remove the other ones]'
$option_force
)
+(( $+functions[_luarocks_purge] )) ||
_luarocks_purge(){
_arguments "${purge_command_options[@]}"
}
@@ -358,6 +379,7 @@ local remove_command_options=(
$option_force
$option_force_fast
)
+(( $+functions[_luarocks_remove] )) ||
_luarocks_remove(){
_arguments -A "-*" \
"${remove_command_options[@]}" \
@@ -373,6 +395,7 @@ local search_command_options=(
'--binary[Return only pure Lua and binary rocks (rocks that can be used with the "install" command without requiring a C toolchain)]'
'--all[List all contents of the server that are suitable to this platform, do not filter by name]'
)
+(( $+functions[_luarocks_search] )) ||
_luarocks_search(){
_arguments \
"${search_command_options[@]}" \
@@ -391,6 +414,7 @@ local show_command_options=(
'--rock-tree[local tree where rock is installed]'
'--rock-dir[data directory of the installed rock]'
)
+(( $+functions[_luarocks_show] )) ||
_luarocks_show(){
_arguments \
"${show_command_options[@]}" \
@@ -404,6 +428,7 @@ _luarocks_show(){
local unpack_command_options=(
'--force[Unpack files even if the output directory already exists]'
)
+(( $+functions[_luarocks_unpack] )) ||
_luarocks_unpack(){
_arguments \
"${unpack_command_options[@]}" \
@@ -418,6 +443,7 @@ local upload_command_options=(
'--api-key=[Give it an API key]:KEY:{_message "api key"}'
'--force[Replace existing rockspec if the same revision of a module already exists]'
)
+(( $+functions[_luarocks_upload] )) ||
_luarocks_upload(){
_arguments \
"${upload_command_options[@]}" \
@@ -441,6 +467,7 @@ local write_rockspec_command_options=(
'--tag=[Tag to use. Will attempt to extract version number from it]:TAG:__git_tag'
'--lib=[A comma-separated list of libraries that C files need to link to]:'
)
+(( $+functions[_luarocks_write_rockspec] )) ||
_luarocks_write_rockspec(){
_arguments -A "-*" \
"${write_rockspec_command_options[@]}" \
--
2.17.0
^ permalink raw reply [flat|nested] 28+ messages in thread
* [PATCH 23/25] Improve `___luarocks_installed_rocks_cache_policy`.
2018-05-26 15:06 [PATCH 00/25] *** Add completion for luarocks *** doron.behar
` (21 preceding siblings ...)
2018-05-26 15:06 ` [PATCH 22/25] Use +functions[] for all helpers doron.behar
@ 2018-05-26 15:06 ` doron.behar
2018-05-26 15:06 ` [PATCH 24/25] Consider `--tree` when searching installed rocks doron.behar
` (2 subsequent siblings)
25 siblings, 0 replies; 28+ messages in thread
From: doron.behar @ 2018-05-26 15:06 UTC (permalink / raw)
To: zsh-workers
From: Doron Behar <doron.behar@gmail.com>
Handle multiple trees when evaluating installed rocks cache validity -
both system wide and user's.
---
Completion/Unix/Command/_luarocks | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/Completion/Unix/Command/_luarocks b/Completion/Unix/Command/_luarocks
index cb42d1b36..8de95c188 100644
--- a/Completion/Unix/Command/_luarocks
+++ b/Completion/Unix/Command/_luarocks
@@ -87,14 +87,14 @@ __luarocks_lua_versions(){
# {{{ helper: installed rocks cache policy
(( $+functions[___luarocks_installed_rocks_cache_policy] )) ||
___luarocks_installed_rocks_cache_policy(){
- # TODO enable the user to configure manifests file that will be checked here with zstyle
- # the number of seconds since 1970-01-01 the manifest file was modified
- local manifest_last_date_modified="$(date -r ~/.luarocks/lib/luarocks/rocks-5.3/manifest +%s 2>/dev/null)"
+ # the number of seconds since 1970-01-01 the manifest files were modified
+ local user_manifest_last_date_modified="$(date -r ${HOME}/.luarocks/lib/luarocks/rocks-5.3/manifest +%s 2>/dev/null)"
+ local system_manifest_last_date_modified="$(date -r /usr/lib/luarocks/rocks-5.3/manifest +%s 2>/dev/null)"
# the number of seconds since 1970-01-01 the cache file was modified
local cache_last_date_modified="$(date -r $1 +%s 2>/dev/null)"
- if [[ ! -z ${cache_last_date_modified} && ! -z ${manifest_last_date_modified} ]]; then
+ if [[ ! -z ${cache_last_date_modified} && ! -z ${user_manifest_last_date_modified} && ! -z ${system_manifest_last_date_modified} ]]; then
# if the manifest file is newer then the cache:
- if [ ${manifest_last_date_modified} -ge ${cache_last_date_modified} ]; then
+ if [ ${user_manifest_last_date_modified} -ge ${cache_last_date_modified} ] || [ ${system_manifest_last_date_modified} -ge ${cache_last_date_modified} ]; then
(( 1 ))
else
(( 0 ))
--
2.17.0
^ permalink raw reply [flat|nested] 28+ messages in thread
* [PATCH 24/25] Consider `--tree` when searching installed rocks.
2018-05-26 15:06 [PATCH 00/25] *** Add completion for luarocks *** doron.behar
` (22 preceding siblings ...)
2018-05-26 15:06 ` [PATCH 23/25] Improve `___luarocks_installed_rocks_cache_policy` doron.behar
@ 2018-05-26 15:06 ` doron.behar
2018-05-26 15:06 ` [PATCH 25/25] Consider `--tree` in versions completion doron.behar
2018-05-26 15:37 ` [PATCH 00/25] *** Add completion for luarocks *** Eitan Adler
25 siblings, 0 replies; 28+ messages in thread
From: doron.behar @ 2018-05-26 15:06 UTC (permalink / raw)
To: zsh-workers
From: Doron Behar <doron.behar@gmail.com>
---
Completion/Unix/Command/_luarocks | 126 +++++++++++++++++++++---------
1 file changed, 91 insertions(+), 35 deletions(-)
diff --git a/Completion/Unix/Command/_luarocks b/Completion/Unix/Command/_luarocks
index 8de95c188..17fa8248e 100644
--- a/Completion/Unix/Command/_luarocks
+++ b/Completion/Unix/Command/_luarocks
@@ -59,6 +59,7 @@ __luarocks_rock_version(){
# TODO: actually complete versions of installed rocks using the cache
# How does luarocks handles multiple versions of the same package?
# If anybody knows, please write something beautiful here
+ # TODO: get somehow from $@ the option given (if used) to --tree
_message -e "version for installed rock ${words[$i]}"
return
;;
@@ -107,56 +108,95 @@ ___luarocks_installed_rocks_cache_policy(){
# {{{ helper: installed rocks
(( $+functions[__luarocks_installed_rocks] )) ||
__luarocks_installed_rocks(){
- local update_policy
- zstyle -s ":completion:${curcontext}:" cache-policy update_policy
- if [[ -z "$update_policy" ]]; then
- zstyle ":completion:${curcontext}:" cache-policy ___luarocks_installed_rocks_cache_policy
- fi
- if _cache_invalid luarocks_installed_list; then
- rocks_list=($(luarocks list --porcelain))
- _store_cache luarocks_installed_list rocks_list
+ # This function optionally recieves one argument of the tree in which
+ # installed rocks are searched for. If this argument is used, the installed
+ # rocks which will be completed by this function will not use the cache which
+ # is valid only for installed rocks on default trees like /usr/lib/luarocks
+ # and ~/.luarocks
+ local tree="$1"
+ if [[ -z ${tree} ]]; then
+ local update_policy
+ zstyle -s ":completion:${curcontext}:" cache-policy update_policy
+ if [[ -z "$update_policy" ]]; then
+ zstyle ":completion:${curcontext}:" cache-policy ___luarocks_installed_rocks_cache_policy
+ fi
+ if _cache_invalid luarocks_installed_list; then
+ rocks_list=($(luarocks list --porcelain))
+ _store_cache luarocks_installed_list rocks_list
+ else
+ _retrieve_cache luarocks_installed_list
+ fi
+ if [[ -z ${rocks_list} ]]; then
+ _message -r "no installed rocks"
+ return
+ fi
+ if _cache_invalid luarocks_installed_names; then
+ rocks_names=()
+ for i in {1.."${#rocks_list[@]}"..4}; do
+ rocks_names+=("${rocks_list[$i]}")
+ done
+ _store_cache luarocks_installed_names rocks_names
+ else
+ _retrieve_cache luarocks_installed_names
+ fi
+ if _cache_invalid luarocks_installed_versions; then
+ rocks_versions=()
+ for i in {2.."${#rocks_list[@]}"..4}; do
+ rocks_versions+=("${rocks_list[$i]}")
+ done
+ _store_cache luarocks_installed_versions rocks_versions
+ else
+ _retrieve_cache luarocks_installed_versions
+ fi
+ if _cache_invalid luarocks_installed_descriptions; then
+ rocks_descriptions=()
+ for i in {1.."${#rocks_names[@]}"}; do
+ name_version_description="$(luarocks show ${rocks_names[$i]} 2>/dev/null | head -2 | tail -1)"
+ total_length=${#name_version_description}
+ garbage_length="$((${#rocks_names[$i]} + ${#rocks_versions[$i]} + 5))"
+ description="${name_version_description[${garbage_length},${total_length}]}"
+ rocks_descriptions+=("${description}")
+ done
+ _store_cache luarocks_installed_descriptions rocks_descriptions
+ else
+ _retrieve_cache luarocks_installed_descriptions
+ fi
+ if _cache_invalid luarocks_installed_names_and_descriptions; then
+ rocks_names_and_descriptions=()
+ for i in {1.."${#rocks_names[@]}"}; do
+ name_and_description=${rocks_names[$i]}:${rocks_descriptions[$i]}
+ rocks_names_and_descriptions+=(${name_and_description})
+ done
+ else
+ _store_cache luarocks_installed_names_and_descriptions rocks_names_and_descriptions
+ fi
else
- _retrieve_cache luarocks_installed_list
- fi
- if _cache_invalid luarocks_installed_names; then
+ rocks_list=($(luarocks --tree="${tree}" list --porcelain 2> /dev/null))
+ if [[ -z ${rocks_list} ]]; then
+ _message "no installed rocks in the specified tree"
+ return
+ fi
rocks_names=()
for i in {1.."${#rocks_list[@]}"..4}; do
rocks_names+=("${rocks_list[$i]}")
done
- _store_cache luarocks_installed_names rocks_names
- else
- _retrieve_cache luarocks_installed_names
- fi
- if _cache_invalid luarocks_installed_versions; then
rocks_versions=()
for i in {2.."${#rocks_list[@]}"..4}; do
rocks_versions+=("${rocks_list[$i]}")
done
- _store_cache luarocks_installed_versions rocks_versions
- else
- _retrieve_cache luarocks_installed_versions
- fi
- if _cache_invalid luarocks_installed_descriptions; then
rocks_descriptions=()
for i in {1.."${#rocks_names[@]}"}; do
- name_version_description="$(luarocks show ${rocks_names[$i]} | head -2 | tail -1)"
+ name_version_description="$(luarocks show ${rocks_names[$i]} 2> /dev/null | head -2 | tail -1)"
total_length=${#name_version_description}
garbage_length="$((${#rocks_names[$i]} + ${#rocks_versions[$i]} + 5))"
description="${name_version_description[${garbage_length},${total_length}]}"
rocks_descriptions+=("${description}")
done
- _store_cache luarocks_installed_descriptions rocks_descriptions
- else
- _retrieve_cache luarocks_installed_descriptions
- fi
- if _cache_invalid luarocks_installed_names_and_descriptions; then
rocks_names_and_descriptions=()
for i in {1.."${#rocks_names[@]}"}; do
name_and_description=${rocks_names[$i]}:${rocks_descriptions[$i]}
rocks_names_and_descriptions+=(${name_and_description})
done
- else
- _store_cache luarocks_installed_names_and_descriptions rocks_names_and_descriptions
fi
_describe 'installed rocks' rocks_names_and_descriptions
}
@@ -169,21 +209,37 @@ __luarocks_installed_rocks(){
(( $+functions[__luarocks_rock] )) ||
__luarocks_rock(){
local -a alts=()
- for arg in "$@"; do
- case $arg in
+ while [[ $# -gt 0 ]]; do
+ arg="$1"
+ case "$arg" in
(rockspec)
alts+=(':rock file:{_files -g "*.rockspec"}')
+ shift 1
+ continue
;;
(rockpack)
alts+=(':rock file:{_files -g "*.src.rock"}')
+ shift 1
+ continue
;;
(external)
alts+=(':external rock:')
+ shift 1
+ continue
;;
(installed)
- alts+=(':local rock:__luarocks_installed_rocks')
+ tree="$2"
+ alts+=(":local rock:{__luarocks_installed_rocks ${tree}}")
+ if [[ -z "${tree}" ]]; then
+ shift
+ else
+ shift 2
+ fi
+ continue
;;
esac
+ shift
+ continue
done
_alternative ${alts[@]}
}
@@ -250,7 +306,7 @@ local doc_command_options=(
_luarocks_doc(){
_arguments \
"${doc_command_options[@]}" \
- '1: :{__luarocks_rock "installed"}'
+ '1: :{__luarocks_rock "installed" '"${opt_args[--tree]}"'}'
}
# }}}
# {{{ `download` command
@@ -383,7 +439,7 @@ local remove_command_options=(
_luarocks_remove(){
_arguments -A "-*" \
"${remove_command_options[@]}" \
- '1: :{__luarocks_rock "installed"}' \
+ '1: :{__luarocks_rock "installed" '"${opt_args[--tree]}"'}' \
'2:: :{__luarocks_rock_version "installed"}'
}
# }}}
@@ -418,7 +474,7 @@ local show_command_options=(
_luarocks_show(){
_arguments \
"${show_command_options[@]}" \
- '1: :{__luarocks_rock "installed"}'
+ "1: :{__luarocks_rock 'installed' "${opt_args[--tree]}"}"
}
# }}}
# {{{ `unpack` command
--
2.17.0
^ permalink raw reply [flat|nested] 28+ messages in thread
* [PATCH 25/25] Consider `--tree` in versions completion.
2018-05-26 15:06 [PATCH 00/25] *** Add completion for luarocks *** doron.behar
` (23 preceding siblings ...)
2018-05-26 15:06 ` [PATCH 24/25] Consider `--tree` when searching installed rocks doron.behar
@ 2018-05-26 15:06 ` doron.behar
2018-05-26 15:37 ` [PATCH 00/25] *** Add completion for luarocks *** Eitan Adler
25 siblings, 0 replies; 28+ messages in thread
From: doron.behar @ 2018-05-26 15:06 UTC (permalink / raw)
To: zsh-workers
From: Doron Behar <doron.behar@gmail.com>
---
Completion/Unix/Command/_luarocks | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/Completion/Unix/Command/_luarocks b/Completion/Unix/Command/_luarocks
index 17fa8248e..a02bd06b5 100644
--- a/Completion/Unix/Command/_luarocks
+++ b/Completion/Unix/Command/_luarocks
@@ -59,8 +59,12 @@ __luarocks_rock_version(){
# TODO: actually complete versions of installed rocks using the cache
# How does luarocks handles multiple versions of the same package?
# If anybody knows, please write something beautiful here
- # TODO: get somehow from $@ the option given (if used) to --tree
- _message -e "version for installed rock ${words[$i]}"
+ tree="$2"
+ if [[ -z "${tree}" ]]; then
+ _message -e "version for installed rock ${words[$i]}"
+ else
+ _message -e "version for installed rock ${words[$i]} on tree ${tree}"
+ fi
return
;;
"new_version")
@@ -440,7 +444,7 @@ _luarocks_remove(){
_arguments -A "-*" \
"${remove_command_options[@]}" \
'1: :{__luarocks_rock "installed" '"${opt_args[--tree]}"'}' \
- '2:: :{__luarocks_rock_version "installed"}'
+ '2:: :{__luarocks_rock_version "installed" '"${opt_args[--tree]}"'}'
}
# }}}
# {{{ `search` command
--
2.17.0
^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 00/25] *** Add completion for luarocks ***
2018-05-26 15:06 [PATCH 00/25] *** Add completion for luarocks *** doron.behar
` (24 preceding siblings ...)
2018-05-26 15:06 ` [PATCH 25/25] Consider `--tree` in versions completion doron.behar
@ 2018-05-26 15:37 ` Eitan Adler
2018-05-26 16:09 ` Doron Behar
25 siblings, 1 reply; 28+ messages in thread
From: Eitan Adler @ 2018-05-26 15:37 UTC (permalink / raw)
To: doron.behar; +Cc: Zsh hackers list
On 26 May 2018 at 08:06, <doron.behar@gmail.com> wrote:
> From: Doron Behar <doron.behar@gmail.com>
>
> After https://github.com/luarocks/luarocks/issues/412, I think luarocks
> deserves a completion function. I hope I've put it in the right
> location.
Can you please resend as a single patch? I think you accidentally sent
your WIP patches so its hard to review.
--
Eitan Adler
^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 00/25] *** Add completion for luarocks ***
2018-05-26 15:37 ` [PATCH 00/25] *** Add completion for luarocks *** Eitan Adler
@ 2018-05-26 16:09 ` Doron Behar
0 siblings, 0 replies; 28+ messages in thread
From: Doron Behar @ 2018-05-26 16:09 UTC (permalink / raw)
To: Eitan Adler; +Cc: zsh-workers
Pardon me, I'm not very used to sending patches to mailing lists,
usually I use services like GitHub or GitLab. I'll squash the changes
and send a single patch like the patch I sent for gpg completion.
On Sat, May 26, 2018 at 08:37:00AM -0700, Eitan Adler wrote:
> On 26 May 2018 at 08:06, <doron.behar@gmail.com> wrote:
> > From: Doron Behar <doron.behar@gmail.com>
> >
> > After https://github.com/luarocks/luarocks/issues/412, I think luarocks
> > deserves a completion function. I hope I've put it in the right
> > location.
>
> Can you please resend as a single patch? I think you accidentally sent
> your WIP patches so its hard to review.
>
>
>
> --
> Eitan Adler
^ permalink raw reply [flat|nested] 28+ messages in thread