aboutsummaryrefslogtreecommitdiff
blob: c3d91600880b58ed2bc99ee48e6fc6d0c4aff58f (plain)
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# -*-eselect-*-  vim: ft=eselect
# Copyright 2006-2020 Gentoo Authors
# Distributed under the terms of the GNU GPL version 2 or later

inherit config

DESCRIPTION="Query eselect modules"
MAINTAINER="eselect@gentoo.org"

DEFAULT_ACTION="list"

### list action

describe_list() {
	echo "List all available modules"
}

describe_list_options() {
	echo "--only-names : Output names of modules only"
}

# List all installed modules
do_list() {
	local only_names path file module name desc
	local -a extra_modules

	if [[ ${1#--} = only-names ]]; then
		only_names=1
		shift
	fi
	[[ $# -gt 0 ]] && die -q "Too many parameters"

	for path in "${ESELECT_MODULES_PATH[@]}" ; do
		[[ -d ${path} ]] || continue
		for file in "${path}"/*.eselect ; do
			[[ -f ${file} ]] || continue
			extra_modules=( "${extra_modules[@]}" "${file}" )
		done
	done

	if [[ -n ${only_names} ]]; then
		# This is mainly intended for bash completion
		echo "help"
		echo "usage"
		echo "version"
		for module in "${extra_modules[@]}" ; do
			name=${module##*/}
			echo "${name%%.eselect}"
		done
	else
		write_list_start "Built-in modules:"
		write_kv_list_entry "help"			"Display a help message"
		write_kv_list_entry "usage"			"Display a usage message"
		write_kv_list_entry "version"		"Display version information"

		if [[ ${#extra_modules[@]} -gt 0 ]] ; then
			echo
			write_list_start "Extra modules:"
			for module in "${extra_modules[@]}" ; do
				name=${module##*/}
				name=${name%%.eselect}
				desc=$(ESELECT_MODULE_NAME=${name} \
					load_config "${module}" DESCRIPTION)
				desc=${desc:-No description available}
				write_kv_list_entry "${name}" "${desc}"
			done
		fi
	fi
}

### has action

describe_has() {
	echo "Return true if the module is installed, and false otherwise"
}

describe_has_parameters() {
	echo "<module>"
}

do_has() {
	[[ -z $1 ]] && die -q "Required option (module name) missing"
	[[ $# -gt 1 ]] && die -q "Too many parameters"

	local modname=$1 modpath
	for modpath in "${ESELECT_MODULES_PATH[@]}" ; do
		[[ -f ${modpath}/${modname}.eselect ]] && return 0
	done
	return 1
}

### add action
# *** Commented out. Do we really want to have an eselect module that is
# *** installing other modules in a system directory? Also, this should
# *** go together with a "remove" action.

# describe_add() {
# 	echo "Install the given module file somewhere that eselect can find it."
# 	echo "By default, install to \$HOME/.eselect/modules/, unless running as "
# 	echo "root. Then, install to ${ESELECT_DATA_PATH}/modules/."
# }

# describe_add_parameters() {
# 	echo "<module_file>"
# }

# do_add() {
# 	local local_path="${ROOT}${HOME}/.eselect/modules/" module_file
# 	local force_default=0
#
# 	if [[ $1 = "--force-default-location" ]] ; then
# 		force_default=1
# 		shift
# 	fi
# 	module_file=$1
#
# 	[[ -z ${module_file} ]] && die -q "Required option (module file) missing"
#
# 	# TODO: Don't install the module "somewhere", depending on write access.
# 	# Add an option to control if it goes to the user's or to the system dir.
# 	if ! cp "${module_file}" "${ESELECT_DEFAULT_MODULES_PATH}" &> /dev/null ; then
# 		[[ ${force_default} == 1 ]] \
# 			&& die -q "Failed to install module file to default modules path"
#
# 		mkdir -p "${local_path}" \
# 			|| die -q "Failed to create module install directory"
# 		cp "${module_file}" "${local_path}" \
# 			|| die -q "Failed to install module file"
# 	fi
# }