]> git.proxmox.com Git - pve-client.git/blobdiff - PVE/APIClient/Commands/remote.pm
use new PVE::APIClient::Config class, register_standard_option 'pveclient-remote...
[pve-client.git] / PVE / APIClient / Commands / remote.pm
index 7b407390034a6467cbf0d4d73279aa1f737cfd3b..a6eb512bbadca232b6f4d274ac894df0b10c1fbb 100644 (file)
@@ -3,10 +3,37 @@ package PVE::APIClient::Commands::remote;
 use strict;
 use warnings;
 
+use PVE::JSONSchema qw(register_standard_option get_standard_option);
+use PVE::APIClient::Config;
+
 use PVE::CLIHandler;
 
 use base qw(PVE::CLIHandler);
 
+my $remote_name_regex = qr(\w+);
+
+my $complete_remote_name = sub {
+
+    my $conf = PVE::APIClient::Config::load_config();
+
+    my $res = [];
+
+    foreach my $k (keys %$conf) {
+       if ($k =~ m/^remote_($remote_name_regex)$/) {
+           push @$res, $1;
+       }
+    }
+
+    return $res;
+};
+
+register_standard_option('pveclient-remote-name', {
+    description => "The name of the remote.",
+    type => 'string',
+    pattern => $remote_name_regex,
+    completion => $complete_remote_name,
+});
+
 __PACKAGE__->register_method ({
     name => 'add',
     path => 'add',
@@ -15,16 +42,13 @@ __PACKAGE__->register_method ({
     parameters => {
        additionalProperties => 0,
        properties => {
-           name => {
-               description => "The name of the remote.",
-               type => 'string',
-           },
+           name => get_standard_option('pveclient-remote-name', { completion => sub {} }),
            host => {
                description => "The host, either host, host:port or https://host:port",
                type => 'string',
            },
            username => {
-               description => "The username.", 
+               description => "The username.",
                type => 'string',
                optional => 1,
            },
@@ -46,10 +70,7 @@ __PACKAGE__->register_method ({
     parameters => {
        additionalProperties => 0,
        properties => {
-           name => {
-               description => "The name of the remote.",
-               type => 'string',
-           },
+           name => get_standard_option('pveclient-remote-name'),
        },
     },
     returns => { type => 'null'},