Fix openvpn3 completion

And apply formatting
This commit is contained in:
Shohei YOSHIDA 2026-03-08 21:54:02 +09:00
parent 6a6e4a9d5f
commit 2bcf6ca857
No known key found for this signature in database
GPG Key ID: C9A1BB11BB940CF2
1 changed files with 165 additions and 160 deletions

View File

@ -49,198 +49,203 @@ local sessions_names=$(openvpn3 sessions-list | grep 'Session name:' | awk '{pri
local configs_names=$(openvpn3 configs-list | awk 'count&&!--count; /\/net\/openvpn\//{count=2}' | awk '{print $1}' | xargs) local configs_names=$(openvpn3 configs-list | awk 'count&&!--count; /\/net\/openvpn\//{count=2}' | awk '{print $1}' | xargs)
local configs_paths=$(openvpn3 configs-list | grep '/net/openvpn/v3/configuration/' | xargs) local configs_paths=$(openvpn3 configs-list | grep '/net/openvpn/v3/configuration/' | xargs)
_openvpn3_config-acl(){ _openvpn3_config-acl() {
_arguments \ _arguments \
{-s,--show}"[Show the current access control lists]" \ {-s,--show}"[Show the current access control lists]" \
{-o,--path}"[OBJ-PATH Path to the configuration in the configuration manager]: :($configs_paths)" \ {-o,--path}"[OBJ-PATH Path to the configuration in the configuration manager]: :($configs_paths)" \
{-h,--help}"[This help screen]" \ {-h,--help}"[This help screen]" \
{-c,--config}"[CONFIG-NAME Alternative to --path, where configuration profile name is used instead]: :($configs_names)" \ {-c,--config}"[CONFIG-NAME Alternative to --path, where configuration profile name is used instead]: :($configs_names)" \
{-S,--seal}"[Make the configuration profile permanently read-only]" \ {-S,--seal}"[Make the configuration profile permanently read-only]" \
{-R,--revoke}"[<UID | username> Revoke this user access from this configuration profile]" \ {-R,--revoke}"[<UID | username> Revoke this user access from this configuration profile]" \
{-G,--grant}"[<UID | username> Grant this user access to this configuration profile]" \ {-G,--grant}"[<UID | username> Grant this user access to this configuration profile]" \
"--public-access[<true|false> Set/unset the public access flag]" \ "--public-access[<true|false> Set/unset the public access flag]" \
"--lock-down[<true|false> Set/unset the lock-down flag.Will disable config retrieval for users]: :(true false)" \ "--lock-down[<true|false> Set/unset the lock-down flag.Will disable config retrieval for users]: :(true false)" \
"--config-path[OBJ-PATH Alias for --path]: :($configs_paths)" \ "--config-path[OBJ-PATH Alias for --path]: :($configs_paths)"
} }
_openvpn3_config-import(){ _openvpn3_config-import() {
_arguments \ _arguments \
{-p,--persistent}"[Make the configuration profile persistent through service restarts]" \ {-p,--persistent}"[Make the configuration profile persistent through service restarts]" \
{-n,--name}"[NAME Provide a different name for the configuration (default: CFG-FILE)]" \ {-n,--name}"[NAME Provide a different name for the configuration (default: CFG-FILE)]" \
{-h,--help}"[This help screen]" \ {-h,--help}"[This help screen]" \
{-c,--config}"[CFG-FILE Configuration file to import]: :_files" \ {-c,--config}"[CFG-FILE Configuration file to import]: :_files"
} }
_openvpn3_config-manage(){ _openvpn3_config-manage() {
_arguments \ _arguments \
{-s,--show}"[Show current configuration options]" \ {-s,--show}"[Show current configuration options]" \
{-r,--rename}"[NEW-CONFIG-NAME Renames the configuration]" \ {-r,--rename}"[NEW-CONFIG-NAME Renames the configuration]" \
{-o,--path}"[CONFIG-PATH Path to the configuration in the configuration manager]: :($configs_paths)" \ {-o,--path}"[CONFIG-PATH Path to the configuration in the configuration manager]: :($configs_paths)" \
{-h,--help}"[This help screen]" \ {-h,--help}"[This help screen]" \
{-c,--config}"[CONFIG-NAME Alternative to --path, where configuration profile name is used instead]: :($configs_names)" \ {-c,--config}"[CONFIG-NAME Alternative to --path, where configuration profile name is used instead]: :($configs_names)" \
"--unset-override[<name> Removes the <name> override]" \ "--unset-override[<name> Removes the <name> override]" \
"--tls-version-min[<tls_1_0|tls_1_1|tls_1_2|tls_1_3> Sets the minimal TLS version for the control channel]: :(tls_1_0 tls_1_1 tls_1_2 tls_1_3)" \ "--tls-version-min[<tls_1_0|tls_1_1|tls_1_2|tls_1_3> Sets the minimal TLS version for the control channel]: :(tls_1_0 tls_1_1 tls_1_2 tls_1_3)" \
"--tls-cert-profile[<legacy preferred suiteb> Sets the control channel tls profile]: :(legacy preferred suiteb)" \ "--tls-cert-profile[<legacy preferred suiteb> Sets the control channel tls profile]: :(legacy preferred suiteb)" \
"--server-override[<value> Replace the remote, connecting to this server instead the server specified in the configuration]" \ "--server-override[<value> Replace the remote, connecting to this server instead the server specified in the configuration]" \
"--proxy-username[<value> HTTP Proxy username to authenticate as]" \ "--proxy-username[<value> HTTP Proxy username to authenticate as]" \
"--proxy-port[<value> HTTP Proxy port to connect on]" \ "--proxy-port[<value> HTTP Proxy port to connect on]" \
"--proxy-password[<value> HTTP Proxy password to use for authentication]" \ "--proxy-password[<value> HTTP Proxy password to use for authentication]" \
"--proxy-host[<value> HTTP Proxy to connect via, overrides configuration file http-proxy]" \ "--proxy-host[<value> HTTP Proxy to connect via, overrides configuration file http-proxy]" \
"--proxy-auth-cleartext[<true|false> Adds the boolean override proxy-auth-cleartext]: :(true false)" \ "--proxy-auth-cleartext[<true|false> Adds the boolean override proxy-auth-cleartext]: :(true false)" \
"--proto-override[<tcp|udp> Overrides the protocol being used]: :(tcp upd)" \ "--proto-override[<tcp|udp> Overrides the protocol being used]: :(tcp udp)" \
"--port-override[<value> Replace the remote port, connecting to this port instead of the configuration value]" \ "--port-override[<value> Replace the remote port, connecting to this port instead of the configuration value]" \
"--persist-tun[<true|false> Adds the boolean override persist-tun]: :(true false)" \ "--persist-tun[<true|false> Adds the boolean override persist-tun]: :(true false)" \
"--ipv6[<yes|no|default> Sets the IPv6 policy of the client]: :(yes no default)" \ "--ipv6[<yes|no|default> Sets the IPv6 policy of the client]: :(yes no default)" \
"--force-cipher-aes-cbc[<true|false> Adds the boolean override force-cipher-aes-cbc]: :(true false)" \ "--force-cipher-aes-cbc[<true|false> Adds the boolean override force-cipher-aes-cbc]: :(true false)" \
"--dns-sync-lookup[<true|false> Adds the boolean override dns-sync-lookup]: :(true false)" \ "--dns-sync-lookup[<true|false> Adds the boolean override dns-sync-lookup]: :(true false)" \
"--dns-setup-disabled[<true|false> Adds the boolean override dns-setup-disabled]: :(true false)" \ "--dns-setup-disabled[<true|false> Adds the boolean override dns-setup-disabled]: :(true false)" \
"--dns-fallback-google[<true|false> Adds the boolean override dns-fallback-google]: :(true false)" \ "--dns-fallback-google[<true|false> Adds the boolean override dns-fallback-google]: :(true false)" \
"--config-path[CONFIG-PATH Alias for --path]: :($configs_paths)" \ "--config-path[CONFIG-PATH Alias for --path]: :($configs_paths)" \
"--auth-fail-retry[<true|false> Adds the boolean override auth-fail-retry]: :(true false)" \ "--auth-fail-retry[<true|false> Adds the boolean override auth-fail-retry]: :(true false)" \
"--allow-compression[<no asym yes> Set compression mode]: :(no asym yes)" \ "--allow-compression[<no asym yes> Set compression mode]: :(no asym yes)" \
}
_openvpn3_config-remove() {
_arguments \
{-o,--path}"[OBJ-PATH Path to the configuration in the configuration manager]: :($configs_paths)" \
{-h,--help}"[This help screen]" \
{-c,--config}"[CONFIG-NAME Alternative to --path, where configuration profile name is used instead]: :($configs_names)" \
"--force[Force the deletion process without asking for confirmation]" \
"--config-path[OBJ-PATH Alias for --path]: :($configs_paths)"
} }
_openvpn3_config-remove(){ _openvpn3_config-show() {
_arguments \ _arguments \
{-o,--path}"[OBJ-PATH Path to the configuration in the configuration manager]: :($configs_paths)" \ {-o,--path}"[OBJ-PATH Path to the configuration in the configuration manager]: :($configs_paths)" \
{-h,--help}"[This help screen]" \ {-j,--json}"[Dump the configuration in JSON format]" \
{-c,--config}"[CONFIG-NAME Alternative to --path, where configuration profile name is used instead]: :($configs_names)" \ {-h,--help}"[This help screen]" \
"--force[Force the deletion process without asking for confirmation]" \ {-c,--config}"[CONFIG-NAME Alternative to --path, where configuration profile name is used instead]: :($configs_names)" \
"--config-path[OBJ-PATH Alias for --path]: :($configs_paths)" \ "--config-path[OBJ-PATH Alias for --path]: :($configs_paths)"
} }
_openvpn3_config-show(){ _openvpn3_configs-list() {
_arguments \ _arguments \
{-o,--path}"[OBJ-PATH Path to the configuration in the configuration manager]: :($configs_paths)" \ {-h,--help}"[This help screen]"
{-j,--json}"[Dump the configuration in JSON format]" \
{-h,--help}"[This help screen]" \
{-c,--config}"[CONFIG-NAME Alternative to --path, where configuration profile name is used instead]: :($configs_names)" \
"--config-path[OBJ-PATH Alias for --path]: :($configs_paths)" \
} }
_openvpn3_configs-list(){ _openvpn3_help() {
_arguments \ _arguments \
{-h,--help}"[This help screen]" \ {-h,--help}"[This help screen]"
} }
_openvpn3_help(){ _openvpn3_log() {
_arguments \ _arguments \
{-h,--help}"[This help screen]" \ {-h,--help}"[This help screen]" \
{-c,--config}"[CONFIG-NAME Alternative to --session-path, where configuration profile name is used instead]: :($sessions_configs_names $configs_names)" \
{-I,--interface}"[INTERFACE Alternative to --session-path, where tun interface name is used instead]: :($sessions_interfaces)" \
"--session-path[SESSION-PATH Receive log events for a specific session]: :($sessions_paths)" \
"--log-level[LOG-LEVEL Set the log verbosity level of messages to be shown (default: 4)]" \
"--config-events[Receive log events issued by the configuration manager]"
} }
_openvpn3_log(){ _openvpn3_session-acl() {
_arguments \ _arguments \
{-h,--help}"[This help screen]" \ {-s,--show}"[Show the current access control lists]" \
{-c,--config}"[CONFIG-NAME Alternative to --session-path, where configuration profile name is used instead]: :($sessions_configs_names $configs_names)" \ {-o,--path}"[SESSION-PATH Path to the session in the session manager]: :($sessions_paths)" \
{-I,--interface}"[INTERFACE Alternative to --session-path, where tun interface name is used instead]: :($sessions_interfaces)" \ {-h,--help}"[This help screen]" \
"--session-path[SESSION-PATH Receive log events for a specific session]: :($sessions_paths)" \ {-c,--config}"[CONFIG-NAME Alternative to --path, where configuration profile name is used instead]: :($sessions_configs_names)" \
"--log-level[LOG-LEVEL Set the log verbosity level of messages to be shown (default: 4)]" \ {-R,--revoke}"[<UID | username> Revoke this user access from this session]" \
"--config-events[Receive log events issued by the configuration manager]" \ {-I,--interface}"[INTERFACE Alternative to --path, where tun interface name is used instead]: :($sessions_interfaces)" \
{-G,--grant}"[<UID | username> Grant this user access to this session]" \
"--session-path[SESSION-PATH Alias for --path]: :($sessions_paths)" \
"--public-access[<true|false> Set/unset the public access flag]: :(true false)" \
"--allow-log-access[<true|false> Can users granted access also access the session log?]: :(true false)"
} }
_openvpn3__session-acl(){ _openvpn3_session-manage() {
_arguments \ _arguments \
{-s,--show}"[Show the current access control lists]" \ {-o,--path}"[SESSION-PATH Path to the session in the session manager]: :($sessions_paths)" \
{-o,--path}"[SESSION-PATH Path to the session in the session manager]: :($sessions_paths)" \ {-h,--help}"[This help screen]" \
{-h,--help}"[This help screen]" \ {-c,--config}"[CONFIG-NAME Alternative to --path, where configuration profile name is used instead]: :($sessions_configs_names)" \
{-c,--config}"[CONFIG-NAME Alternative to --path, where configuration profile name is used instead]: :($sessions_configs_names)" \ {-R,--resume}"[Resumes a paused VPN session]" \
{-R,--revoke}"[<UID | username> Revoke this user access from this session]" \ {-P,--pause}"[Pauses the VPN session]" \
{-I,--interface}"[INTERFACE Alternative to --path, where tun interface name is used instead]: :($sessions_interfaces)" \ {-I,--interface}"[INTERFACE Alternative to --path, where tun interface name is used instead]: :($sessions_interfaces)" \
{-G,--grant}"[<UID | username> Grant this user access to this session]" \ {-D,--disconnect}"[Disconnects a VPN session]" \
"--session-path[SESSION-PATH Alias for --path]: :($sessions_paths)" \ "--session-path[SESSION-PATH Alias for --path]: :($sessions_paths)" \
"--public-access[<true|false> Set/unset the public access flag]: :(true false)" \ "--restart[Disconnect and reconnect a running VPN session]" \
"--allow-log-access[<true|false> Can users granted access also access the session log?]: :(true false)" \ "--cleanup[Clean up stale sessions]"
} }
_openvpn3_session-manage(){ _openvpn3_session-start() {
_arguments \ _arguments \
{-o,--path}"[SESSION-PATH Path to the session in the session manager]: :($sessions_paths)" \ {-p,--config-path}"[CONFIG-PATH Configuration path to an already imported configuration]: :($configs_paths)" \
{-h,--help}"[This help screen]" \ {-h,--help}"[This help screen]" \
{-c,--config}"[CONFIG-NAME Alternative to --path, where configuration profile name is used instead]: :($sessions_configs_names)" \ {-c,--config}"[CONFIG-FILE Configuration file to start directly]: :_files" \
{-R,--resume}"[Resumes a paused VPN session]" \ "--persist-tun[Enforces persistent tun/seamless tunnel (requires --config)]"
{-P,--pause}"[Pauses the VPN session]" \
{-I,--interface}"[INTERFACE Alternative to --path, where tun interface name is used instead]: :($sessions_interfaces)" \
{-D,--disconnect}"[Disconnects a VPN session]" \
"--session-path[SESSION-PATH Alias for --path]: :($sessions_paths)" \
"--restart[Disconnect and reconnect a running VPN session]" \
"--cleanup[Clean up stale sessions]" \
} }
_openvpn3_session-start(){ _openvpn3_session-stats() {
_arguments \ _arguments \
{-p,--config-path}"[CONFIG-PATH Configuration path to an already imported configuration]: :($configs_paths)" \ {-o,--path}"[SESSION-PATH Path to the configuration in the configuration manager]: :($sessions_paths)" \
{-h,--help}"[This help screen]" \ {-j,--json}"[Dump the configuration in JSON format]" \
{-c,--config}"[CONFIG-FILE Configuration file to start directly]: :_files" \ {-h,--help}"[This help screen]" \
"--persist-tun[Enforces persistent tun/seamless tunnel (requires --config)]" \ {-c,--config}"[CONFIG-NAME Alternative to --path, where configuration profile name is used instead]: :($sessions_configs_names)" \
{-I,--interface}"[INTERFACE Alternative to --path, where tun interface name is used instead]: :($sessions_interfaces)" \
"--session-path[SESSION-PATH Alias for --path]: :($sessions_paths)"
} }
_openvpn3_session-stats(){ _openvpn3_sessions-list() {
_arguments \ _arguments \
{-o,--path}"[SESSION-PATH Path to the configuration in the configuration manager]: :($sessions_paths)" \ {-h,--help}"[This help screen]"
{-j,--json}"[Dump the configuration in JSON format]" \
{-h,--help}"[This help screen]" \
{-c,--config}"[CONFIG-NAME Alternative to --path, where configuration profile name is used instead]: :($sessions_configs_names)" \
{-I,--interface}"[INTERFACE Alternative to --path, where tun interface name is used instead]: :($sessions_interfaces)" \
"--session-path[SESSION-PATH Alias for --path]: :($sessions_paths)" \
} }
_openvpn3_sessions-list(){ _openvpn3_shell-completion() {
_arguments \ _arguments \
{-h,--help}"[This help screen]" \ {-h,--help}"[This help screen]" \
"--list-commands[List all available commands]" \
"--list-options[COMMAND List all available options for a specific command]: :($(openvpn3 shell-completion --list-commands))" \
"--arg-helper[OPTION Used together with --list-options, lists value hint to an option]"
} }
_openvpn3_shell-completion(){ _openvpn3_version() {
_arguments \ _arguments \
{-h,--help}"[This help screen]" \ {-h,--help}"[This help screen]"
"--list-commands[List all available commands]" \
"--list-options[COMMAND List all available options for a specific command]: :($(openvpn3 shell-completion --list-commands))" \
"--arg-helper[OPTION Used together with --list-options, lists value hint to an option]"
} }
_openvpn3_version(){ _openvpn3_command() {
_arguments \ local -a openvpn3_cmds=(
{-h,--help}"[This help screen]" \ "config-acl: Manage access control lists for configurations"
} "config-import: Import configuration profiles"
"config-manage: Manage configuration properties"
"config-remove: Remove an available configuration profile"
"config-show: Show/dump a configuration profile"
"configs-list: List all available configuration profiles"
"help: This help screen"
"log: Receive log events as they occur"
"session-acl: Manage access control lists for sessions"
"session-manage: Manage VPN sessions"
"session-start: Start a new VPN session"
"session-stats: Show session statistics"
"sessions-list: List available VPN sessions"
"shell-completion: Helper function to provide shell completion data"
"version: Show program version information"
)
if ((CURRENT == 1)); then
_openvpn3_command(){ _describe -t commands 'openvpn3 commands' openvpn3_cmds
local -a _openvpn3_cmds else
_openvpn3_cmds=( local curcontext="$curcontext"
"config-acl: Manage access control lists for configurations" \ cmd="${${_openvpn3_cmds[(r)$words[1]:*]%%:*}}"
"config-import: Import configuration profiles" \ if (($#cmd)); then
"config-manage: Manage configuration properties" \ if (( $+functions[_openvpn3_$cmd] )); then
"config-remove: Remove an available configuration profile" \ _openvpn3_$cmd
"config-show: Show/dump a configuration profile" \ else
"configs-list: List all available configuration profiles" \ _message "no options for $cmd"
"help: This help screen" \ fi
"log: Receive log events as they occur" \
"session-acl: Manage access control lists for sessions" \
"session-manage: Manage VPN sessions" \
"session-start: Start a new VPN session" \
"session-stats: Show session statistics" \
"sessions-list: List available VPN sessions" \
"shell-completion: Helper function to provide shell completion data" \
"version: Show program version information" \
)
if ((CURRENT == 1)); then
_describe -t commands 'openvpn3 commands' _openvpn3_cmds
else else
local curcontext="$curcontext" _message "no more options"
cmd="${${_openvpn3_cmds[(r)$words[1]:*]%%:*}}"
if (($#cmd)); then
if (( $+functions[_openvpn3_$cmd] )); then
_openvpn3_$cmd
else
_message "no options for $cmd"
fi
else
_message "no more options"
fi
fi fi
fi
} }
_arguments \ _arguments \
{-h,--help}"[that This help screen]" \ {-h,--help}"[that This help screen]" \
"*::openvpn3 commands:_openvpn3_command" \ "*::openvpn3 commands:_openvpn3_command" \
# Local Variables:
# mode: Shell-Script
# sh-indentation: 2
# indent-tabs-mode: nil
# sh-basic-offset: 2
# End:
# vim: ft=zsh sw=2 ts=2 et