Refactoring port
- Reduce executing external commands - Reduce escape characters
This commit is contained in:
		
							parent
							
								
									c8c09241eb
								
							
						
					
					
						commit
						76dde7cb7b
					
				
							
								
								
									
										188
									
								
								src/_port
								
								
								
								
							
							
						
						
									
										188
									
								
								src/_port
								
								
								
								
							| 
						 | 
					@ -44,82 +44,11 @@
 | 
				
			||||||
# ------------------------------------------------------------------------------
 | 
					# ------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
_port() {
 | 
					_port() {
 | 
				
			||||||
  local -a  upgrade_options revupgrade_options select_options \
 | 
					  local -a  revupgrade_options select_options \
 | 
				
			||||||
              actions pseudo_common pseudo_advanced port_prefix
 | 
					              pseudo_common pseudo_advanced port_prefix
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  port_prefix=$(which port | sed 's|/bin/port||')
 | 
					  local port_path=$(which port)
 | 
				
			||||||
 | 
					  port_prefix=${port_path%/bin/port}
 | 
				
			||||||
  actions=(
 | 
					 | 
				
			||||||
    'activate\:Activate\ the\ given\ ports'
 | 
					 | 
				
			||||||
    'archive\:Archive\ the\ given\ ports,\ i.e.\ install\ the\ port\ image\ but\ do\ not\ activate'
 | 
					 | 
				
			||||||
    'archivefetch\:Fetch\ archive\ for\ the\ given\ ports'
 | 
					 | 
				
			||||||
    'build\:Build\ the\ given\ ports'
 | 
					 | 
				
			||||||
    'bump\:Update\ the\ outdated\ checksums\ of\ a\ Portfile'
 | 
					 | 
				
			||||||
    'cat\:Writes\ the\ Portfiles\ of\ the\ given\ ports\ to\ stdout'
 | 
					 | 
				
			||||||
    'checksum\:Compares\ the\ checksums\ for\ the\ downloaded\ files\ of\ the\ given\ ports'
 | 
					 | 
				
			||||||
    'clean\:Removes\ files\ associated\ with\ the\ given\ ports'
 | 
					 | 
				
			||||||
    'configure\:Configure\ the\ given\ ports'
 | 
					 | 
				
			||||||
    'contents\:\Returns\ a\ list\ of\ files\ installed\ by\ given\ ports'
 | 
					 | 
				
			||||||
    'deactivate\:Deactivates\ the\ given\ ports'
 | 
					 | 
				
			||||||
    'dependents\:Returns\ a\ list\ of\ installed\ dependents\ for\ each\ of\ the\ given\ ports'
 | 
					 | 
				
			||||||
    'deps\:Display\ a\ dependency\ listing\ for\ the\ given\ ports'
 | 
					 | 
				
			||||||
    'destroot\:Destroot\ the\ given\ ports'
 | 
					 | 
				
			||||||
    'diagnose\:Detects\ common\ issues'
 | 
					 | 
				
			||||||
    'dir\:Returns\ the\ directories\ of\ the\ given\ ports'
 | 
					 | 
				
			||||||
    'distcheck\:Checks\ if\ the\ given\ ports\ can\ be\ fetched\ from\ all\ of\ its\ master_sites'
 | 
					 | 
				
			||||||
    'distfiles\:Returns\ a\ list\ of\ distfiles\ for\ the\ given\ port'
 | 
					 | 
				
			||||||
    'dmg\:Creates\ a\ dmg\ for\ each\ of\ the\ given\ ports'
 | 
					 | 
				
			||||||
    'dpkg\:Creates\ a\ dpkg\ for\ each\ of\ the\ given\ ports'
 | 
					 | 
				
			||||||
    'echo\:Returns\ the\ list\ of\ ports\ the\ argument\ expands\ to'
 | 
					 | 
				
			||||||
    'edit\:Edit\ given\ ports'
 | 
					 | 
				
			||||||
    'extract\:Extract\ the\ downloaded\ files\ of\ the\ given\ ports'
 | 
					 | 
				
			||||||
    'fetch\:Downloaded\ distfiles\ for\ the\ given\ ports'
 | 
					 | 
				
			||||||
    'file\:Returns\ the\ path\ to\ the\ Portfile\ for\ each\ of\ the\ given\ ports'
 | 
					 | 
				
			||||||
    'gohome\:Opens\ the\ homepages\ of\ the\ given\ ports\ in\ your\ browser'
 | 
					 | 
				
			||||||
    'help\:Displays\ short\ help\ texts\ for\ the\ given\ actions'
 | 
					 | 
				
			||||||
    'info\:Returns\ information\ about\ the\ given\ ports '
 | 
					 | 
				
			||||||
    'install\:Installs\ the\ given\ ports'
 | 
					 | 
				
			||||||
    'installed\:List\ installed\ versions\ of\ the\ given\ port,\ or\ all\ installed\ ports\ if\ no\ port\ is\ given'
 | 
					 | 
				
			||||||
    'lint\:Checks\ if\ the\ Portfile\ is\ lint-free\ for\ each\ of\ the\ given\ ports'
 | 
					 | 
				
			||||||
    'list\:List\ the\ available\ version\ for\ each\ of\ the\ given\ ports'
 | 
					 | 
				
			||||||
    'livecheck\:Checks\ if\ a\ new\ version\ of\ the\ software\ is\ available'
 | 
					 | 
				
			||||||
    'load\:Interface\ to\ launchctl(1)\ for\ ports\ providing\ startup\ items'
 | 
					 | 
				
			||||||
    'location\:Returns\ the\ install\ location\ for\ each\ of\ the\ given\ ports'
 | 
					 | 
				
			||||||
    'log\:Shows\ main\ log\ for\ given\ ports'
 | 
					 | 
				
			||||||
    'logfile\:Returns\ the\ log\ file\ path\ for\ each\ of\ the\ given\ ports'
 | 
					 | 
				
			||||||
    'mdmg\:Creates\ a\ dmg\ containing\ an\ mpkg\ for\ each\ of\ the\ given\ ports\ and\ their\ dependencies'
 | 
					 | 
				
			||||||
    'mirror\:Fetches\ distfiles\ for\ the\ given\ ports'
 | 
					 | 
				
			||||||
    'mpkg\:Creates\ an\ mpkg\ for\ each\ of\ the\ given\ ports\ and\ their\ dependencies'
 | 
					 | 
				
			||||||
    'notes\:Displays\ informational\ notes\ for\ each\ of\ the\ given\ ports'
 | 
					 | 
				
			||||||
    'outdated\:Returns\ a\ list\ of\ outdated\ ports'
 | 
					 | 
				
			||||||
    'patch\:Applies\ patches\ to\ each\ of\ the\ given\ ports'
 | 
					 | 
				
			||||||
    'pkg\:Creates\ a\ pkg\ for\ each\ of\ the\ given\ ports'
 | 
					 | 
				
			||||||
    'platform\:Returns\ the\ current\ platform\ that\ port\ is\ running\ on'
 | 
					 | 
				
			||||||
    'provides\:Return\ which\ port\ provides\ each\ of\ the\ files\ given'
 | 
					 | 
				
			||||||
    'rdependents\:Recursive\ version\ of\ dependents'
 | 
					 | 
				
			||||||
    'rdeps\:Display\ a\ recursive\ dependency\ listing\ for\ the\ given\ ports'
 | 
					 | 
				
			||||||
    'reclaim\:Reclaims\ disk\ space'
 | 
					 | 
				
			||||||
    'rev-upgrade\:Scan\ for\ broken\ binaries\ in\ the\ installed\ ports\ and\ rebuild\ them\ as\ needed'
 | 
					 | 
				
			||||||
    'rpm\:Creates\ a\ rpm\ for\ each\ of\ the\ given\ ports'
 | 
					 | 
				
			||||||
    'search\:Search\ for\ a\ port'
 | 
					 | 
				
			||||||
    'select\:Select\ between\ multiple\ versions\ of\ a\ versioned\ port'
 | 
					 | 
				
			||||||
    'selfupdate\:Upgrade\ MacPorts\ itself\ and\ run\ the\ sync\ target'
 | 
					 | 
				
			||||||
    'setrequested\:Marks\ each\ of\ the\ given\ ports\ as\ requested'
 | 
					 | 
				
			||||||
    'space\:Show\ the\ disk\ space\ used\ by\ the\ given\ ports'
 | 
					 | 
				
			||||||
    'srpm\:Creates\ a\ srpm\ for\ each\ of\ the\ given\ ports'
 | 
					 | 
				
			||||||
    'sync\:Synchronize\ the\ set\ of\ Portfiles'
 | 
					 | 
				
			||||||
    'test\:Run\ tests\ on\ each\ of\ the\ given\ ports'
 | 
					 | 
				
			||||||
    'unarchive\:Unarchive\ the\ destroot\ of\ the\ given\ ports\ from\ installed\ images'
 | 
					 | 
				
			||||||
    'uninstall\:Uninstall\ the\ given\ ports'
 | 
					 | 
				
			||||||
    'unload\:Interface\ to\ launchctl(1)\ for\ ports\ providing\ startup\ items'
 | 
					 | 
				
			||||||
    'unsetrequested\:Marks\ each\ of\ the\ given\ ports\ as\ unrequested'
 | 
					 | 
				
			||||||
    'upgrade\:Upgrades\ the\ given\ ports\ to\ the\ latest\ version'
 | 
					 | 
				
			||||||
    'url\:Returns\ the\ URL\ for\ each\ of\ the\ given\ ports'
 | 
					 | 
				
			||||||
    'usage\:Returns\ basic\ usage\ of\ the\ port\ command'
 | 
					 | 
				
			||||||
    'variants\:Returns\ a\ list\ of\ variants\ provided\ by\ the\ given\ ports,\ with\ descriptions\ if\ present'
 | 
					 | 
				
			||||||
    'version\:Returns\ the\ version\ of\ MacPorts'
 | 
					 | 
				
			||||||
    'work\:Returns\ the\ path\ to\ the\ work\ directory\ for\ each\ of\ the\ given\ ports'
 | 
					 | 
				
			||||||
  )
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  pseudo_common=(all current active inactive actinact installed uninstalled outdated
 | 
					  pseudo_common=(all current active inactive actinact installed uninstalled outdated
 | 
				
			||||||
  obsolete requested unrequested leaves rleaves)
 | 
					  obsolete requested unrequested leaves rleaves)
 | 
				
			||||||
| 
						 | 
					@ -138,12 +67,6 @@ _port() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  revupgrade_options=('--id-loadcmd-check:Run more checks against a special loadcommand in Mach-O binaries')
 | 
					  revupgrade_options=('--id-loadcmd-check:Run more checks against a special loadcommand in Mach-O binaries')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  upgrade_options=(
 | 
					 | 
				
			||||||
    '--force\:Ignore\ circumstances\ that\ would\ normally\ cause\ ports\ to\ be\ skipped\ \(e.g.\ not\ outdated\).' \
 | 
					 | 
				
			||||||
    '--enforce-variants\:If\ the\ installed\ variants\ do\ not\ match\ those\ requested,\ upgrade\ even\ if\ the\ port\ is\ not\ outdated.' \
 | 
					 | 
				
			||||||
    '--no-replace\:Do\ not\ replace\ one\ port\ with\ another\ according\ to\ the\ replaced_by\ field.' \
 | 
					 | 
				
			||||||
  )
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  _arguments -s -C \
 | 
					  _arguments -s -C \
 | 
				
			||||||
    '-v[Verbose mode (generate verbose messages)]' \
 | 
					    '-v[Verbose mode (generate verbose messages)]' \
 | 
				
			||||||
    '-d[Debug mode (generate debugging messages, implies -v)]' \
 | 
					    '-d[Debug mode (generate debugging messages, implies -v)]' \
 | 
				
			||||||
| 
						 | 
					@ -162,11 +85,89 @@ _port() {
 | 
				
			||||||
    '-p[Despite any errors encountered, proceed to process multiple ports and commands.]' \
 | 
					    '-p[Despite any errors encountered, proceed to process multiple ports and commands.]' \
 | 
				
			||||||
    '-y[Perform a dry run.]' \
 | 
					    '-y[Perform a dry run.]' \
 | 
				
			||||||
    '-t[Enable trace mode debug facilities on platforms that support it (macOS).]' \
 | 
					    '-t[Enable trace mode debug facilities on platforms that support it (macOS).]' \
 | 
				
			||||||
    "1:Port actions:(($actions))" \
 | 
					    "1:Port actions:_port_actions" \
 | 
				
			||||||
    '::Per-action arguments:_port_dispatch' \
 | 
					    '::Per-action arguments:_port_dispatch' \
 | 
				
			||||||
    && return 0
 | 
					    && return 0
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					(( $+functions[_port_actions] )) ||
 | 
				
			||||||
 | 
					_port_actions() {
 | 
				
			||||||
 | 
					  local -a actions
 | 
				
			||||||
 | 
					  actions=(
 | 
				
			||||||
 | 
					    'activate:Activate the given ports'
 | 
				
			||||||
 | 
					    'archive:Archive the given ports, i.e. install the port image but do not activate'
 | 
				
			||||||
 | 
					    'archivefetch:Fetch archive for the given ports'
 | 
				
			||||||
 | 
					    'build:Build the given ports'
 | 
				
			||||||
 | 
					    'bump:Update the outdated checksums of a Portfile'
 | 
				
			||||||
 | 
					    'cat:Writes the Portfiles of the given ports to stdout'
 | 
				
			||||||
 | 
					    'checksum:Compares the checksums for the downloaded files of the given ports'
 | 
				
			||||||
 | 
					    'clean:Removes files associated with the given ports'
 | 
				
			||||||
 | 
					    'configure:Configure the given ports'
 | 
				
			||||||
 | 
					    'contents:Returns a list of files installed by given ports'
 | 
				
			||||||
 | 
					    'deactivate:Deactivates the given ports'
 | 
				
			||||||
 | 
					    'dependents:Returns a list of installed dependents for each of the given ports'
 | 
				
			||||||
 | 
					    'deps:Display a dependency listing for the given ports'
 | 
				
			||||||
 | 
					    'destroot:Destroot the given ports'
 | 
				
			||||||
 | 
					    'diagnose:Detects common issues'
 | 
				
			||||||
 | 
					    'dir:Returns the directories of the given ports'
 | 
				
			||||||
 | 
					    'distcheck:Checks if the given ports can be fetched from all of its master_sites'
 | 
				
			||||||
 | 
					    'distfiles:Returns a list of distfiles for the given port'
 | 
				
			||||||
 | 
					    'dmg:Creates a dmg for each of the given ports'
 | 
				
			||||||
 | 
					    'dpkg:Creates a dpkg for each of the given ports'
 | 
				
			||||||
 | 
					    'echo:Returns the list of ports the argument expands to'
 | 
				
			||||||
 | 
					    'edit:Edit given ports'
 | 
				
			||||||
 | 
					    'extract:Extract the downloaded files of the given ports'
 | 
				
			||||||
 | 
					    'fetch:Downloaded distfiles for the given ports'
 | 
				
			||||||
 | 
					    'file:Returns the path to the Portfile for each of the given ports'
 | 
				
			||||||
 | 
					    'gohome:Opens the homepages of the given ports in your browser'
 | 
				
			||||||
 | 
					    'help:Displays short help texts for the given actions'
 | 
				
			||||||
 | 
					    'info:Returns information about the given ports '
 | 
				
			||||||
 | 
					    'install:Installs the given ports'
 | 
				
			||||||
 | 
					    'installed:List installed versions of the given port, or all installed ports if no port is given'
 | 
				
			||||||
 | 
					    'lint:Checks if the Portfile is lint-free for each of the given ports'
 | 
				
			||||||
 | 
					    'list:List the available version for each of the given ports'
 | 
				
			||||||
 | 
					    'livecheck:Checks if a new version of the software is available'
 | 
				
			||||||
 | 
					    'load:Interface to launchctl(1) for ports providing startup items'
 | 
				
			||||||
 | 
					    'location:Returns the install location for each of the given ports'
 | 
				
			||||||
 | 
					    'log:Shows main log for given ports'
 | 
				
			||||||
 | 
					    'logfile:Returns the log file path for each of the given ports'
 | 
				
			||||||
 | 
					    'mdmg:Creates a dmg containing an mpkg for each of the given ports and their dependencies'
 | 
				
			||||||
 | 
					    'mirror:Fetches distfiles for the given ports'
 | 
				
			||||||
 | 
					    'mpkg:Creates an mpkg for each of the given ports and their dependencies'
 | 
				
			||||||
 | 
					    'notes:Displays informational notes for each of the given ports'
 | 
				
			||||||
 | 
					    'outdated:Returns a list of outdated ports'
 | 
				
			||||||
 | 
					    'patch:Applies patches to each of the given ports'
 | 
				
			||||||
 | 
					    'pkg:Creates a pkg for each of the given ports'
 | 
				
			||||||
 | 
					    'platform:Returns the current platform that port is running on'
 | 
				
			||||||
 | 
					    'provides:Return which port provides each of the files given'
 | 
				
			||||||
 | 
					    'rdependents:Recursive version of dependents'
 | 
				
			||||||
 | 
					    'rdeps:Display a recursive dependency listing for the given ports'
 | 
				
			||||||
 | 
					    'reclaim:Reclaims disk space'
 | 
				
			||||||
 | 
					    'rev-upgrade:Scan for broken binaries in the installed ports and rebuild them as needed'
 | 
				
			||||||
 | 
					    'rpm:Creates a rpm for each of the given ports'
 | 
				
			||||||
 | 
					    'search:Search for a port'
 | 
				
			||||||
 | 
					    'select:Select between multiple versions of a versioned port'
 | 
				
			||||||
 | 
					    'selfupdate:Upgrade MacPorts itself and run the sync target'
 | 
				
			||||||
 | 
					    'setrequested:Marks each of the given ports as requested'
 | 
				
			||||||
 | 
					    'space:Show the disk space used by the given ports'
 | 
				
			||||||
 | 
					    'srpm:Creates a srpm for each of the given ports'
 | 
				
			||||||
 | 
					    'sync:Synchronize the set of Portfiles'
 | 
				
			||||||
 | 
					    'test:Run tests on each of the given ports'
 | 
				
			||||||
 | 
					    'unarchive:Unarchive the destroot of the given ports from installed images'
 | 
				
			||||||
 | 
					    'uninstall:Uninstall the given ports'
 | 
				
			||||||
 | 
					    'unload:Interface to launchctl(1) for ports providing startup items'
 | 
				
			||||||
 | 
					    'unsetrequested:Marks each of the given ports as unrequested'
 | 
				
			||||||
 | 
					    'upgrade:Upgrades the given ports to the latest version'
 | 
				
			||||||
 | 
					    'url:Returns the URL for each of the given ports'
 | 
				
			||||||
 | 
					    'usage:Returns basic usage of the port command'
 | 
				
			||||||
 | 
					    'variants:Returns a list of variants provided by the given ports, with descriptions if present'
 | 
				
			||||||
 | 
					    'version:Returns the version of MacPorts'
 | 
				
			||||||
 | 
					    'work:Returns the path to the work directory for each of the given ports'
 | 
				
			||||||
 | 
					  )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  _describe -t actions 'actions' actions
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
_port_dispatch() {
 | 
					_port_dispatch() {
 | 
				
			||||||
  local cache_policy
 | 
					  local cache_policy
 | 
				
			||||||
  zstyle -s ":completion:${curcontext}:" cache-policy cache_policy
 | 
					  zstyle -s ":completion:${curcontext}:" cache-policy cache_policy
 | 
				
			||||||
| 
						 | 
					@ -180,7 +181,7 @@ _port_dispatch() {
 | 
				
			||||||
      _message 'pattern'
 | 
					      _message 'pattern'
 | 
				
			||||||
      ;;
 | 
					      ;;
 | 
				
			||||||
    help)
 | 
					    help)
 | 
				
			||||||
      _describe -t actions 'Port actions' actions
 | 
					      _port_actions
 | 
				
			||||||
      ;;
 | 
					      ;;
 | 
				
			||||||
    select)
 | 
					    select)
 | 
				
			||||||
      _call_function - _port_select
 | 
					      _call_function - _port_select
 | 
				
			||||||
| 
						 | 
					@ -203,7 +204,7 @@ _port_dispatch() {
 | 
				
			||||||
      local outdated_packages
 | 
					      local outdated_packages
 | 
				
			||||||
      outdated_packages=( $(_call_program path-outdated "port -q echo outdated") )
 | 
					      outdated_packages=( $(_call_program path-outdated "port -q echo outdated") )
 | 
				
			||||||
      _alternative -- \
 | 
					      _alternative -- \
 | 
				
			||||||
        "upgrade-options:Upgrade options:(($upgrade_options))" \
 | 
					        "upgrade-options:Upgrade options:_port_upgrade_options" \
 | 
				
			||||||
        "ports:Outdated ports:($outdated_packages)" \
 | 
					        "ports:Outdated ports:($outdated_packages)" \
 | 
				
			||||||
        "pseudo-common:Common Pseudo-portnames:($pseudo_common)" \
 | 
					        "pseudo-common:Common Pseudo-portnames:($pseudo_common)" \
 | 
				
			||||||
        "pseudo-advanced:Advanced Pseudo-portnames:($pseudo_advanced)"
 | 
					        "pseudo-advanced:Advanced Pseudo-portnames:($pseudo_advanced)"
 | 
				
			||||||
| 
						 | 
					@ -236,15 +237,24 @@ _port_dispatch() {
 | 
				
			||||||
  esac
 | 
					  esac
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					(( $+functions[_port_upgrade_options] )) ||
 | 
				
			||||||
 | 
					_port_upgrade_options() {
 | 
				
			||||||
 | 
					  local -a options
 | 
				
			||||||
 | 
					  options=(
 | 
				
			||||||
 | 
					    '--enforce-variants:Upgrade all given ports and their dependencies'
 | 
				
			||||||
 | 
					    '--force:Ignore circumstances that would normally cause ports to be skipped'
 | 
				
			||||||
 | 
					    '--no-replace:Do not automatically install ports that replace a new-obsolete port you have installed'
 | 
				
			||||||
 | 
					    '--no-rev-upgrade:Do not run rev-upgrade after upgrading'
 | 
				
			||||||
 | 
					  )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  _describe -t options 'options' options
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
_port_select() {
 | 
					_port_select() {
 | 
				
			||||||
  if (( CURRENT == 3 )); then
 | 
					  if (( CURRENT == 3 )); then
 | 
				
			||||||
    _describe 'Port select options' select_options
 | 
					    _describe 'Port select options' select_options
 | 
				
			||||||
  elif (( CURRENT == 4 )); then
 | 
					  elif (( CURRENT == 4 )); then
 | 
				
			||||||
    local select_group
 | 
					    local select_group=($port_prefix/etc/select/*(N:t))
 | 
				
			||||||
    select_group=()
 | 
					 | 
				
			||||||
    for f in $port_prefix/etc/select/*; do
 | 
					 | 
				
			||||||
      select_group+=$(basename $f)
 | 
					 | 
				
			||||||
    done
 | 
					 | 
				
			||||||
    _describe "Port select groups" select_group
 | 
					    _describe "Port select groups" select_group
 | 
				
			||||||
  elif [[ $CURRENT -eq 5 && $words[3] == '--set' ]]; then
 | 
					  elif [[ $CURRENT -eq 5 && $words[3] == '--set' ]]; then
 | 
				
			||||||
    local select_variants
 | 
					    local select_variants
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue