+ no strict 'refs';
+ my $def = ${"${class}::cmddef"};
+
+ if (ref($def) eq 'ARRAY') {
+ print_simple_pod_manpage($podfn, @$def);
+ } else {
+ $cmddef = $def;
+
+ $cmddef->{help} = [ __PACKAGE__, 'help', ['cmd'] ];
+
+ print_pod_manpage($podfn);
+ }
+}
+
+sub run_cli {
+ my ($class, $pwcallback, $podfn, $preparefunc) = @_;
+
+ $ENV{'PATH'} = '/sbin:/bin:/usr/sbin:/usr/bin';
+
+ $exename = $class;
+ $exename =~ s/^.*:://;
+
+ initlog($exename);
+
+
+ if ($class !~ m/^PVE::Service::/) {
+ die "please run as root\n" if $> != 0;
+
+ PVE::INotify::inotify_init();
+
+ my $rpcenv = PVE::RPCEnvironment->init('cli');
+ $rpcenv->init_request();
+ $rpcenv->set_language($ENV{LANG});
+ $rpcenv->set_user('root@pam');
+ }
+
+ no strict 'refs';
+ my $def = ${"${class}::cmddef"};
+
+ if (ref($def) eq 'ARRAY') {
+ handle_simple_cmd($def, \@ARGV, $pwcallback, $podfn, $preparefunc);
+ } else {
+ $cmddef = $def;
+ my $cmd = shift @ARGV;
+ handle_cmd($cmddef, $exename, $cmd, \@ARGV, $pwcallback, $podfn, $preparefunc);
+ }
+
+ exit 0;