| 1 | #!/usr/bin/perl | ||
| 2 | |||
| 3 | package OSGi::Osgish::Command::Server; | ||
| 4 | use strict; | ||
| 5 | use vars qw(@ISA); | ||
| 6 | use Term::ANSIColor qw(:constants); | ||
| 7 | |||
| 8 | @ISA = qw(OSGi::Osgish::Command); | ||
| 9 | |||
| 10 | |||
| 11 | =head1 NAME | ||
| 12 | |||
| 13 | OSGi::Osgish::Command::Server - Server related commands | ||
| 14 | |||
| 15 | =head1 DESCRIPTION | ||
| 16 | |||
| 17 | =head1 COMMANDS | ||
| 18 | |||
| 19 | =over | ||
| 20 | |||
| 21 | =cut | ||
| 22 | |||
| 23 | |||
| 24 | sub name { "server" } | ||
| 25 | |||
| 26 | |||
| 27 | sub top_commands { | ||
| 28 | my $self = shift; | ||
| 29 | return { | ||
| 30 | "servers" => { | ||
| 31 | desc => "Show all configured servers", | ||
| 32 | proc => $self->cmd_server_list, | ||
| 33 | doc => <<EOT | ||
| 34 | List all servers stored in the configuration | ||
| 35 | and those connected during this session | ||
| 36 | (indicated by a '*') | ||
| 37 | EOT | ||
| 38 | }, | ||
| 39 | "connect" => { | ||
| 40 | desc => "Connect to a server by its URL or symbolic name", | ||
| 41 | minargs => 1, maxargs => 2, | ||
| 42 | args => $self->complete->servers, | ||
| 43 | proc => $self->cmd_connect, | ||
| 44 | doc => <<EOT | ||
| 45 | |||
| 46 | connect <url or name> [<name>] | ||
| 47 | |||
| 48 | Connect to an agent. <url> is the URL under which the agent | ||
| 49 | is reachable. Alternatively a <name> as stored in the configuration | ||
| 50 | can be given. Is using the <url> form an additional <name> | ||
| 51 | can be given which will be used as name in the server list. | ||
| 52 | EOT | ||
| 53 | }, | ||
| 54 | }; | ||
| 55 | } | ||
| 56 | |||
| 57 | # Connect to a server | ||
| 58 | sub cmd_connect { | ||
| 59 | my $self = shift; | ||
| 60 | return sub { | ||
| 61 | my $arg = shift; | ||
| 62 | my $name = shift; | ||
| 63 | my $osgish = $self->osgish; | ||
| 64 | $osgish->servers->connect_to_server($arg,$name); | ||
| 65 | $osgish->commands->reset_stack; | ||
| 66 | my ($yellow,$reset) = $osgish->color("host",RESET); | ||
| 67 | print "Connected to " . $yellow . $osgish->server . $reset . " (" . $osgish->agent->url . ").\n"; | ||
| 68 | } | ||
| 69 | } | ||
| 70 | |||
| 71 | # Show all servers | ||
| 72 | sub cmd_server_list { | ||
| 73 | my $self = shift; | ||
| 74 | return sub { | ||
| 75 | my $osgish = $self->osgish; | ||
| 76 | my $server_list = $osgish->servers->list; | ||
| 77 | for my $s (@$server_list) { | ||
| 78 | my ($ms,$me) = $osgish->color("host",RESET); | ||
| 79 | my $sep = $s->{from_config} ? "-" : "*"; | ||
| 80 | printf " " . $ms . '%30.30s' . $me . ' %s %s' . "\n",$s->{name},$sep,$s->{url}; | ||
| 81 | } | ||
| 82 | } | ||
| 83 | } | ||
| 84 | |||
| 85 | =head1 LICENSE | ||
| 86 | |||
| 87 | This file is part of osgish. | ||
| 88 | |||
| 89 | Osgish is free software: you can redistribute it and/or modify | ||
| 90 | it under the terms of the GNU General Public License as published by | ||
| 91 | the Free Software Foundation, either version 2 of the License, or | ||
| 92 | (at your option) any later version. | ||
| 93 | |||
| 94 | osgish is distributed in the hope that it will be useful, | ||
| 95 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 96 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 97 | GNU General Public License for more details. | ||
| 98 | |||
| 99 | You should have received a copy of the GNU General Public License | ||
| 100 | along with osgish. If not, see <http://www.gnu.org/licenses/>. | ||
| 101 | |||
| 102 | A commercial license is available as well. Please contact roland@cpan.org for | ||
| 103 | further details. | ||
| 104 | |||
| 105 | =head1 PROFESSIONAL SERVICES | ||
| 106 | |||
| 107 | Just in case you need professional support for this module (or JMX or OSGi in | ||
| 108 | general), you might want to have a look at www.consol.com Contact | ||
| 109 | roland.huss@consol.de for further information (or use the contact form at | ||
| 110 | http://www.consol.com/contact/) | ||
| 111 | |||
| 112 | =head1 AUTHOR | ||
| 113 | |||
| 114 | roland@cpan.org | ||
| 115 | |||
| 116 | =cut | ||
| 117 | |||
| 118 | 1; | ||
| 119 |