OSDN Git Service

Complete carthage arguments
authormagicant <magicant@048f04df-13f5-43d7-8114-9f9ceecaec24>
Fri, 26 Aug 2016 13:01:02 +0000 (13:01 +0000)
committermagicant <magicant@048f04df-13f5-43d7-8114-9f9ceecaec24>
Fri, 26 Aug 2016 13:01:02 +0000 (13:01 +0000)
git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/yash/yash/trunk@3660 048f04df-13f5-43d7-8114-9f9ceecaec24

NEWS
NEWS.ja
share/completion/carthage [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 3e2e77f..588a4d2 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -11,7 +11,8 @@ History of Yash
 Yash 2.42
 
   +  '--pipefail' option.
-  +  New completion script for: dnf, git-rev-parse, tree, watch
+  +  New completion script for: carthage, dnf, git-rev-parse, tree,
+     watch
   +  Updated completion script for: cd, git, git-bisect, git-rev-list
      (Git 2.9.2).
   =  Yash now supports the 2013 edition of POSIX.1-2008.
diff --git a/NEWS.ja b/NEWS.ja
index 9d9c4f7..8907044 100644 (file)
--- a/NEWS.ja
+++ b/NEWS.ja
@@ -11,7 +11,7 @@ Yash 更新履歴
 Yash 2.42
 
   +  '--pipefail' オプション
-  +  補完スクリプトを追加: dnf, git-rev-parse, tree, watch
+  +  補完スクリプトを追加: carthage, dnf, git-rev-parse, tree, watch
   +  補完スクリプトを更新: cd, git, git-bisect, git-rev-list
      (Git 2.9.2).
   =  POSIX.1-2008 の 2013 年版に準拠
diff --git a/share/completion/carthage b/share/completion/carthage
new file mode 100644 (file)
index 0000000..45d33a2
--- /dev/null
@@ -0,0 +1,222 @@
+# (C) 2016 magicant
+
+# Completion script for the "carthage" command.
+# Supports Carthage 0.17.2.
+
+function completion/carthage {
+
+       typeset OPTIONS ARGOPT PREFIX
+       OPTIONS=()
+
+       case ${WORDS[#]} in
+               (1)
+                       command -f completion/carthage::completesubcmds
+                       ;;
+               (*)
+                       typeset subcmd="${WORDS[2]}"
+                       if command -vf "completion/carthage::$subcmd:arg" >/dev/null 2>&1; then
+                               WORDS=("${WORDS[2,-1]}")
+                               command -f "completion/carthage::$subcmd:arg"
+                       fi
+                       ;;
+       esac
+
+}
+
+function completion/carthage::getbuildoptions {
+       OPTIONS=("$OPTIONS" #>#
+       "--configuration:"
+       "--derived-data:"
+       "--platform:"
+       "--toolchain:"
+       "--verbose"
+       ) #<#
+}
+
+function completion/carthage::getcheckoutoptions {
+       OPTIONS=("$OPTIONS" #>#
+       "--no-use-binaries"
+       "--use-ssh"
+       "--use-submodules"
+       ) #<#
+}
+
+function completion/carthage::getcpoptions {
+       OPTIONS=("$OPTIONS" #>#
+       "--color:"
+       "--project-directory:"
+       ) #<#
+}
+
+function completion/carthage::completeoptarg
+       case $ARGOPT in
+               (-)
+                       command -f completion//completeoptions -e
+                       ;;
+               (--derived-data|--project-directory)
+                       complete -P "$PREFIX" -S / -T -d
+                       ;;
+               (--color)
+                       complete -P "$PREFIX" always auto never
+                       ;;
+               (--configuration)
+                       # TODO Complete configuration
+                       ;;
+               (--platform)
+                       typeset word="${TARGETWORD#"$PREFIX"}"
+                       word=${word##*,}
+                       PREFIX=${TARGETWORD%"$word"}
+                       complete -P "$PREFIX" all Mac iOS watchOS tvOS
+                       ;;
+               (--toolchain)
+                       # TODO Complete toolchain
+                       ;;
+       esac
+
+function completion/carthage::completesubcmds { #>>#
+       complete -P "${PREFIX-}" archive bootstrap build checkout fetch help \
+               outdated update version
+} #<<#
+
+function completion/carthage::completedependencies {
+       # This code can only complete dependencies that have already been
+       # checked out in Carthage/Checkouts. Maybe we could improve candidates
+       # by parsing Cartfile.
+       typeset IFS=/
+       complete -P "$PREFIX" -- $(
+               set -o glob -o nullglob
+               cd -P "./$(git rev-parse --show-cdup)Carthage/Checkouts" \
+                       2>/dev/null || exit
+               candidates=(*/)
+               candidates=("${candidates%/}")
+               printf %s "${candidates[*]}"
+       )
+}
+
+function completion/carthage::archive:arg {
+
+       OPTIONS=( #>#
+       "--output:"
+       ) #<#
+       command -f completion/carthage::getcpoptions
+
+       command -f completion//parseoptions -e
+       case $ARGOPT in
+               ('')
+                       # TODO complete framework
+                       ;;
+               (--output)
+                       complete -P "$PREFIX" -f
+                       ;;
+               (*)
+                       command -f completion/carthage::completeoptarg
+                       ;;
+       esac
+
+}
+
+function completion/carthage::bootstrap:arg {
+
+       OPTIONS=( #>#
+       "--no-build"
+       "--no-checkout"
+       ) #<#
+       command -f completion/carthage::getbuildoptions
+       command -f completion/carthage::getcheckoutoptions
+       command -f completion/carthage::getcpoptions
+
+       command -f completion//parseoptions -e
+       case $ARGOPT in
+               ('')
+                       command -f completion/carthage::completedependencies
+                       ;;
+               (*)
+                       command -f completion/carthage::completeoptarg
+                       ;;
+       esac
+
+}
+
+function completion/carthage::build:arg {
+
+       OPTIONS=( #>#
+       "--no-skip-current; build current project as well"
+       ) #<#
+       command -f completion/carthage::getbuildoptions
+       command -f completion/carthage::getcpoptions
+
+       command -f completion//parseoptions -e
+       case $ARGOPT in
+               ('')
+                       command -f completion/carthage::completedependencies
+                       ;;
+               (*)
+                       command -f completion/carthage::completeoptarg
+                       ;;
+       esac
+
+}
+
+function completion/carthage::checkout:arg {
+
+       OPTIONS=()
+       command -f completion/carthage::getcheckoutoptions
+       command -f completion/carthage::getcpoptions
+
+       command -f completion//parseoptions -e
+       case $ARGOPT in
+               ('')
+                       command -f completion/carthage::completedependencies
+                       ;;
+               (*)
+                       command -f completion/carthage::completeoptarg
+                       ;;
+       esac
+
+}
+
+function completion/carthage::fetch:arg {
+
+       OPTIONS=( #>#
+       "--color:"
+       ) #<#
+
+       command -f completion//parseoptions -e
+       case $ARGOPT in
+               ('')
+                       # TODO complete repository
+                       ;;
+               (*)
+                       command -f completion/carthage::completeoptarg
+                       ;;
+       esac
+
+}
+
+function completion/carthage::help:arg {
+       command -f completion/carthage::completesubcmds
+}
+
+function completion/carthage::outdated:arg {
+
+       OPTIONS=( #>#
+       "--use-ssh"
+       "--verbose"
+       ) #<#
+       command -f completion/carthage::getcpoptions
+
+       command -f completion//parseoptions -e
+       case $ARGOPT in
+               (*)
+                       command -f completion/carthage::completeoptarg
+                       ;;
+       esac
+
+}
+
+function completion/carthage::update:arg {
+       command -f completion/carthage::build:arg "$@"
+}
+
+
+# vim: set ft=sh ts=8 sts=8 sw=8 noet: