File: __check__

package info (click to toggle)
zplug 2.4.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,068 kB
  • sloc: sh: 1,504; awk: 235; makefile: 26
file content (107 lines) | stat: -rw-r--r-- 2,551 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env zsh
# Description:
#   Return true if all packages are installed, false otherwise

local     is_verbose=false is_debug=false
local     arg repo
local -aU repos not_installed_repos not_found_repos
local -A  tags
local -i  ret=0

while (( $# > 0 ))
do
    arg="$1"
    case "$arg" in
        --verbose)
            is_verbose=true
            ;;
        --debug)
            is_debug=true
            ;;
        -*|--*)
            __zplug::core::options::unknown "$arg"
            return $status
            ;;
        "")
            # Invalid
            return 1
            ;;
        */*)
            repos+=( "${arg:gs:@::}" )
            ;;
        *)
            return 1
            ;;
    esac
    shift
done

if (( $#repos == 0 )); then
    repos=( "${(k)zplugs[@]:gs:@::}" )
fi

for repo in "${repos[@]}"
do
    # Evaluate IF tag and bypass existence check if conditions are not met
    tags[if]="$(__zplug::core::core::run_interfaces 'if' "$repo")"
    if [[ -n $tags[if] ]]; then
        if ! eval "$tags[if]" 2> >(__zplug::log::capture::error) >/dev/null; then
            $is_verbose && __zplug::io::print::die "$fg[red]$repo$reset_color: (bypassed check)\n"
            continue
        fi
    fi

    tags[from]="$(__zplug::core::core::run_interfaces 'from' "$repo")"
    if [[ -z "$tags[from]" ]]; then
        not_installed_repos+=( "$repo" )
        continue
    fi

    if __zplug::core::sources::is_handler_defined "check" "$tags[from]"; then
        __zplug::core::sources::use_handler \
            "check" \
            "$tags[from]" \
            "$repo"

        if (( $status != 0 )); then
            if [[ $tags[from] == 'local' ]]; then
                # FIXME: use $_ZPLUG_STATUS_*
                not_found_repos+=( "$repo" )
            else
                not_installed_repos+=( "$repo" )
            fi
        fi
    fi
done

if (( $#not_found_repos > 0 )); then
    if $is_verbose; then
        __zplug::io::print::put \
            "- $fg[red]%s$reset_color: no such directory\n" \
            "${not_found_repos[@]}"
    fi

    ret=0
fi

# Initialize
if (( $#not_installed_repos > 0 )); then
    # Share not installed repos information
    # e.g. for __install__ command
    #reply=( "${not_installed_repos[@]}" )

    if $is_debug; then
        echo "$not_installed_repos[@]"
        return 0
    fi

    if $is_verbose; then
        __zplug::io::print::put \
            "- $fg[red]%s$reset_color: not installed\n" \
            "${not_installed_repos[@]}"
    fi

    ret=1
fi

return $ret