my $command = $ARGV[0];
-my $commands = {'destroy' => 1,
- 'create' => 1,
- 'sync' => 1,
- 'list' => 1,
- 'status' => 1,
- 'help' => 1,
- 'enable' => 1,
- 'disable' => 1,
- 'printpod' => 1,
-};
-
-if (!$command || !$commands->{$command}) {
- usage();
- die "\n";
-}
-
-my $help_sync = <<EOF;
-$PROGNAME sync -dest <string> -source <string> [OPTIONS]\n
-
- will sync one time
-
- -dest string
-
- the destination target is like [IP:]<Pool>[/Path]
-
- -limit integer
-
- max sync speed in kBytes/s, default unlimited
-
- -maxsnap integer
+my $cmd_help = {
+ destroy => qq{
+$PROGNAME destroy -source <string> [OPTIONS]
- how much snapshots will be kept before get erased, default 1
+ remove a sync Job from the scheduler
-name string
- name of the sync job, if not set it is default.
- It is only necessary if scheduler allready contains this source.
+ name of the sync job, if not set it is default
-source string
- the source can be an <VMID> or [IP:]<ZFSPool>[/Path]
-
- -verbose boolean
-
- print out the sync progress.
-EOF
-
-my $help_create = <<EOF;
+ the source can be an <VMID> or [IP:]<ZFSPool>[/Path]
+ },
+ create => qq{
$PROGNAME create -dest <string> -source <string> [OPTIONS]
Create a sync Job
-source string
the source can be an <VMID> or [IP:]<ZFSPool>[/Path]
-EOF
+ },
+ sync => qq{
+$PROGNAME sync -dest <string> -source <string> [OPTIONS]\n
-my $help_destroy = <<EOF;
-$PROGNAME destroy -source <string> [OPTIONS]
+ will sync one time
- remove a sync Job from the scheduler
+ -dest string
- -name string
+ the destination target is like [IP:]<Pool>[/Path]
- name of the sync job, if not set it is default
+ -limit integer
- -source string
+ max sync speed in kBytes/s, default unlimited
- the source can be an <VMID> or [IP:]<ZFSPool>[/Path]
-EOF
+ -maxsnap integer
-my $help_help = <<EOF;
-$PROGNAME help <cmd> [OPTIONS]
+ how much snapshots will be kept before get erased, default 1
- Get help about specified command.
+ -name string
- <cmd> string
+ name of the sync job, if not set it is default.
+ It is only necessary if scheduler allready contains this source.
- Command name
+ -source string
- -verbose boolean
+ the source can be an <VMID> or [IP:]<ZFSPool>[/Path]
- Verbose output format.
-EOF
+ -verbose boolean
-my $help_list = <<EOF;
+ print out the sync progress.
+ },
+ list => qq{
$PROGNAME list
Get a List of all scheduled Sync Jobs
-EOF
-
-my $help_status = <<EOF;
+ },
+ status => qq{
$PROGNAME status
Get the status of all scheduled Sync Jobs
-EOF
+ },
+ help => qq{
+$PROGNAME help <cmd> [OPTIONS]
+
+ Get help about specified command.
+
+ <cmd> string
-my $help_enable = <<EOF;
+ Command name
+
+ -verbose boolean
+
+ Verbose output format.
+ },
+ enable => qq{
$PROGNAME enable -source <string> [OPTIONS]
enable a syncjob and reset error
-source string
the source can be an <VMID> or [IP:]<ZFSPool>[/Path]
-EOF
-
-my $help_disable = <<EOF;
+ },
+ disable => qq{
$PROGNAME disable -source <string> [OPTIONS]
pause a sync job
-source string
the source can be an <VMID> or [IP:]<ZFSPool>[/Path]
-EOF
-
-sub help {
- my ($command) = @_;
-
- if ($command eq 'help') {
- die "$help_help\n";
-
- } elsif ($command eq 'sync') {
- die "$help_sync\n";
-
- } elsif ($command eq 'destroy') {
- die "$help_destroy\n";
-
- } elsif ($command eq 'create') {
- die "$help_create\n";
+ },
+ printpod => 'internal command',
- } elsif ($command eq 'list') {
- die "$help_list\n";
-
- } elsif ($command eq 'status') {
- die "$help_status\n";
-
- } elsif ($command eq 'enable') {
- die "$help_enable\n";
-
- } elsif ($command eq 'disable') {
- die "$help_disable\n";
-
- }
+};
+if (!$command) {
+ usage(); die "\n";
+} elsif (!$cmd_help->{$command}) {
+ print "ERROR: unknown command '$command'";
+ usage(1); die "\n";
}
my @arg = @ARGV;
my $param = parse_argv(@arg);
+sub check_params {
+ for (@_) {
+ die "$cmd_help->{$command}\n" if !$param->{$_};
+ }
+}
+
if ($command eq 'destroy') {
- die "$help_destroy\n" if !$param->{source};
+ check_params(qw(source));
check_target($param->{source});
destroy_job($param);
} elsif ($command eq 'sync') {
- die "$help_sync\n" if !$param->{source} || !$param->{dest};
+ check_params(qw(source dest));
check_target($param->{source});
check_target($param->{dest});
sync($param);
} elsif ($command eq 'create') {
- die "$help_create\n" if !$param->{source} || !$param->{dest};
+ check_params(qw(source dest));
check_target($param->{source});
check_target($param->{dest});
} elsif ($command eq 'help') {
my $help_command = $ARGV[1];
- if ($help_command && $commands->{$help_command}) {
- print help($help_command);
+ if ($help_command && $cmd_help->{$help_command}) {
+ die "$cmd_help->{$command}\n";
}
if ($param->{verbose}) {
}
} elsif ($command eq 'enable') {
- die "$help_enable\n" if !$param->{source};
+ check_params(qw(source));
check_target($param->{source});
enable_job($param);
} elsif ($command eq 'disable') {
- die "$help_disable\n" if !$param->{source};
+ check_params(qw(source));
check_target($param->{source});
disable_job($param);
}
sub print_pod {
+
+ my $synopsis = join("\n", sort values %$cmd_help);
+
print <<EOF;
=head1 NAME
pve-zsync <COMMAND> [ARGS] [OPTIONS]
-$help_help
-
-$help_create
-
-$help_destroy
-
-$help_disable
-
-$help_enable
-
-$help_list
-
-$help_status
-
-$help_sync
+$synopsis
=head1 DESCRIPTION