-
-
Notifications
You must be signed in to change notification settings - Fork 117
/
Copy pathlist-commands.pl
executable file
·127 lines (116 loc) · 3.01 KB
/
list-commands.pl
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
#!/usr/local/bin/perl
=head1 list-commands.pl
Lists API scripts available
This command lists all API commands available, categorized by type and
with a brief summary of each. It is used to produce the output from the
Virtualmin C<--help> command. By default the output is in a human-readable format,
but you can switch to a more parsable format with the C<--multiline> flag.
=cut
package virtual_server;
if (!$module_name) {
$main::no_acl_check++;
$ENV{'WEBMIN_CONFIG'} ||= "/etc/webmin";
$ENV{'WEBMIN_VAR'} ||= "/var/webmin";
if ($0 =~ /^(.*)\/[^\/]+$/) {
chdir($pwd = $1);
}
else {
chop($pwd = `pwd`);
}
$0 = "$pwd/list-features.pl";
require './virtual-server-lib.pl';
$< == 0 || die "list-commands.pl must be run as root";
}
# Parse command-line args
my $short = 1;
&parse_common_cli_flags(\@ARGV);
while(@ARGV > 0) {
local $a = shift(@ARGV);
if ($a eq "--short") {
$short = 1;
}
elsif ($a eq "--long") {
$short = 0;
}
else {
&usage("Unknown parameter $a");
}
}
# Work out the max command length, for formatting
my $maxlen = 0;
foreach my $c (&list_api_categories()) {
my ($cname, @cglobs) = @$c;
foreach my $cmd (map { glob($_) } @cglobs) {
my $scmd = $cmd;
$scmd =~ s/\.pl$// if ($short);
$maxlen = length($scmd) if (length($scmd) > $maxlen);
}
}
# Go through the categories
my @skips = &list_api_skip_scripts();
my %cdescs = &list_api_category_descs();
my %done;
my $fmt = "\%-${maxlen}.${maxlen}s \%s\n";
foreach my $c (&list_api_categories()) {
my ($cname, @cglobs) = @$c;
@cglobs = map { my $g = $_; ($g, "pro/$g", map { "$root_directory/$_/$g" } @plugins) } @cglobs;
my @cmds = map { glob($_) } @cglobs;
# Print a line for each command
my $donehead = 0;
foreach my $cmd (@cmds) {
next if (-l $cmd);
next if (&indexof($cmd, @skips) >= 0);
my $spellcmd = $cmd;
$spellcmd =~ s/licence/license/g;
next if ($done{$spellcmd}++);
my $src = &read_file_contents($cmd);
next if ($src !~ /=head1\s+(.*)\n\n(.*)\n/);
my $desc = $2;
my $scmd = $cmd;
$scmd =~ s/^.*\///;
$scmd =~ s/\.pl$// if ($short);
if ($multiline) {
# Show a block for the command
print $scmd,"\n";
print " Description: $desc\n";
print " Category: $cname\n";
}
elsif ($nameonly) {
# Just command name
print $scmd,"\n";
}
else {
# Just one line, maybe wrapped
my $wrap;
while (length($desc) + $maxlen > 79) {
# Line is too long - wrap it by taking off
# a word
$desc =~ s/\s(\S+)$//;
$wrap = $1." ".$wrap;
}
$desc =~ s/\.\s*$//;
$wrap =~ s/\.\s*$//;
if (!$donehead) {
# Category header
print $cname,"\n";
print ("-" x length($cname));
print "\n";
$donehead = 1;
}
printf $fmt, $scmd, $desc;
printf $fmt, "", $wrap if ($wrap);
}
}
if ($donehead && !$multiline && !$nameonly) {
print "\n";
}
}
sub usage
{
print "$_[0]\n\n" if ($_[0]);
print "Lists available command-line API scripts.\n";
print "\n";
print "virtualmin list-commands [--short]\n";
print " [--multiline | --name-only]\n";
exit(1);
}