-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocman
executable file
·86 lines (74 loc) · 1.9 KB
/
docman
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
#!/bin/bash
# Distributed under the terms of the GNU General Public License v2
# Copyright 2005-2006 The RepoDoc Team
VERSION="0.1_beta4"
# -----
# SHOW_VERSION_USAGE Function. Private
# Show quick help about how to run repodoc
show_version_usage() {
cat << EOH
The Docman Tool version ${VERSION}
Distributed under the terms of the GPLv2
Copyright 2005-2007 The RepoDoc Team
Usage: docman [--help|-h] [--version|-v] [--list-commands|-l] COMMAND [PARAMS] FILES
EOH
}
#-----
# SHOW_COMMAND_HELP Function. Private
# Show full docman command list based on existant modules
# Params:
# - $1: full path to command module
show_command_help() {
local com=${1##*/}
source "${1}"
# Show command and description
printf " - %-*s " 10 "${com%.module}"
echo "${MOD_DESCRIPTION}"
}
#
# MAIN CODE
# Program starts here
#
# Knowing Script dir beware of symlink
[[ -L ${0} ]] && SCRIPT_DIR=$(readlink ${0}) || SCRIPT_DIR=${0}
SCRIPT_DIR="${SCRIPT_DIR%/*}"
# Paths
LIB_DIR="${SCRIPT_DIR}/lib"
MOD_DIR="${SCRIPT_DIR}/modules/docman"
EXTRA_DIR="${SCRIPT_DIR}/extras"
# Importing libs
source "${LIB_DIR}/libcore.sh"
# If no args, show usage
[[ $# -eq 0 ]] && { show_version_usage; exit 0; }
# Check version/help and specific options request
case $1 in
-v|--version)
echo "Docman ${VERSION}"
exit 0
;;
-h|--help)
show_version_usage
exit 0
;;
-l|--list-commands)
echo "Docman ${VERSION}. List of supported commands:"
# List all modules
for m in "${MOD_DIR}"/*.module ; do
show_command_help ${m}
done
exit 0
;;
esac
if [[ -f ${MOD_DIR}/${1}.module ]] ; then
# Module exists
source "${MOD_DIR}/${1}.module"
shift
# Check if it's a request for help
[[ ${1} == "--help" ]] || [[ ${1} == "-h" ]] && { mod_help; exit 0; }
# Run module
exec_module ${@}
else
# Module doesn't exist
echo "(EE) Command \"${1}\" does not exist on docman."
echo "(EE) If you want to see a full list of commands use docman --list-commands"
fi