# $Id$ # package main; use strict; use warnings; sub CommandHelp; sub help_Initialize($$) { my %hash = ( Fn => "CommandHelp", Hlp => "[],get help (this screen or module dependent docu)" ); $cmds{help} = \%hash; } sub CommandHelp { my ($cl, $mod) = @_; if($mod) { $mod = lc($mod); my %mods; my @modDir = ("FHEM"); foreach my $modDir (@modDir) { opendir(DH, $modDir) || die "Cant open $modDir: $!\n"; while(my $l = readdir DH) { next if($l !~ m/^\d\d_.*\.pm$/); my $of = $l; $l =~ s/.pm$//; $l =~ s/^[0-9][0-9]_//; $mods{lc($l)} = "$modDir/$of"; } } return "Module $mod not found" unless defined($mods{$mod}); my $output = ""; my $skip = 1; my ($err,@text) = FileRead({FileName => $mods{$mod}, ForceType => 'file'}); return $err if $err; foreach my $l (@text) { if($l =~ m/^=begin html$/) { $skip = 0; } elsif($l =~ m/^=end html$/) { $skip = 1; } elsif(!$skip) { $output .= $l; } } if( $cl && $cl->{TYPE} eq 'telnet' ) { $output =~ s/
/\n/g; $output =~ s//\n/g; $output =~ s/<\/a>//g; $output =~ s///g; $output =~ s/
    /\n/g; $output =~ s/<\/ul>/\n/g; $output =~ s/
  • /-/g; $output =~ s/<\/li>/\n/g; $output =~ s///g; $output =~ s/<\/code>//g; $output =~ s/<//g; $output =~ s/<[bui]>/\ /g; $output =~ s/<\/[bui]>/\ /g; $output =~ s/\ \ +/\ /g; $output =~ s/\t+/ /g; $output =~ s/\n\n/\n/g; return $output; } return "$output"; } else { my $str = "\n" . "Possible commands:\n\n" . "Command Parameter Description\n" . "-----------------------------------------------\n"; for my $cmd (sort keys %cmds) { next if(!$cmds{$cmd}{Hlp}); next if($cl && $cmds{$cmd}{ClientFilter} && $cl->{TYPE} !~ m/$cmds{$cmd}{ClientFilter}/); my @a = split(",", $cmds{$cmd}{Hlp}, 2); $str .= sprintf("%-9s %-25s %s\n", $cmd, $a[0], $a[1]); } return $str; } } 1; =pod =begin html

    help

      help [<moduleName>]

      • returns a list of available commands, when called without a moduleName
      • returns a module dependent helptext, same as in commandref
    =end html =cut