mirror of
https://github.com/duncs/clusterssh.git
synced 2025-04-22 01:12:24 +00:00
Bring option processing back into use
This commit is contained in:
parent
ec42a1481c
commit
3c3e145199
3 changed files with 68 additions and 82 deletions
|
@ -203,76 +203,6 @@ sub logmsg($@) {
|
|||
}
|
||||
}
|
||||
|
||||
# make sure our config is sane (i.e. binaries found) and get some extra bits
|
||||
sub check_config() {
|
||||
my %config;
|
||||
warn 'This section to be rewritten';
|
||||
|
||||
# check we have xterm on our path
|
||||
logmsg( 2, "Checking path to xterm" );
|
||||
$config{terminal} = find_binary( $config{terminal} );
|
||||
|
||||
# check we have comms method on our path
|
||||
logmsg( 2, "Checking path to $config{comms}" );
|
||||
$config{ $config{comms} } = find_binary( $config{ $config{comms} } );
|
||||
|
||||
# make sure comms in an accepted value
|
||||
die
|
||||
"FATAL: Only ssh, rsh, telnet, and console/conserver protocols are currently supported (comms=$config{comms})\n"
|
||||
if ( $config{comms} !~ /^(:?[rs]sh|telnet|console)$/ );
|
||||
|
||||
# Set any extra config options given on command line
|
||||
$config{title} = $options{title} if ( $options{title} );
|
||||
|
||||
$config{auto_quit} = "yes" if $options{autoquit};
|
||||
$config{auto_quit} = "no" if $options{'no-autoquit'};
|
||||
|
||||
# backwards compatibility & tidyup
|
||||
if ( $config{always_tile} ) {
|
||||
if ( !$config{window_tiling} ) {
|
||||
if ( $config{always_tile} eq "never" ) {
|
||||
$config{window_tiling} = "no";
|
||||
}
|
||||
else {
|
||||
$config{window_tiling} = "yes";
|
||||
}
|
||||
}
|
||||
delete( $config{always_tile} );
|
||||
}
|
||||
$config{window_tiling} = "yes" if $options{tile};
|
||||
$config{window_tiling} = "no" if $options{'no-tile'};
|
||||
|
||||
$config{user} = $options{username} if ( $options{username} );
|
||||
$config{port} = $options{port} if ( $options{port} );
|
||||
|
||||
$config{mstr} = $options{master} if ( $options{master} );
|
||||
|
||||
$config{terminal_args} = $options{'term-args'}
|
||||
if ( $options{'term-args'} );
|
||||
|
||||
if ( $config{terminal_args} =~ /-class (\w+)/ ) {
|
||||
$config{terminal_allow_send_events}
|
||||
= "-xrm '$1.VT100.allowSendEvents:true'";
|
||||
}
|
||||
|
||||
$config{internal_previous_state} = ""; # set to default
|
||||
|
||||
# option font overrides config file font setting
|
||||
$config{terminal_font} = $options{font} if ( $options{font} );
|
||||
|
||||
$config{extra_cluster_file} =~ s/\s+//g;
|
||||
|
||||
$config{ssh_args} = $options{options} if ( $options{options} );
|
||||
|
||||
$config{show_history} = 1 if $options{'show-history'};
|
||||
|
||||
$config{command} = $options{action} if ( $options{action} );
|
||||
|
||||
if ( $options{use_all_a_records} ) {
|
||||
$config{use_all_a_records} = !$config{use_all_a_records} || 0;
|
||||
}
|
||||
}
|
||||
|
||||
sub evaluate_commands {
|
||||
my ($self) = @_;
|
||||
my ( $return, $user, $port, $host );
|
||||
|
@ -1874,6 +1804,23 @@ sub run {
|
|||
$self->config->{auto_quit} = "no" if $options{'no-autoquit'};
|
||||
$self->config->{auto_close} = $options{autoclose} if $options{'autoclose'};
|
||||
|
||||
$self->config->{window_tiling} = "yes" if $options{tile};
|
||||
$self->config->{window_tiling} = "no" if $options{'no-tile'};
|
||||
|
||||
$self->config->{user} = $options{username} if ( $options{username} );
|
||||
$self->config->{port} = $options{port} if ( $options{port} );
|
||||
|
||||
$self->config->{show_history} = 1 if $options{'show-history'};
|
||||
$self->config->{ssh_args} = $options{options} if ( $options{options} );
|
||||
|
||||
$self->config->{terminal_font} = $options{font} if ( $options{font} );
|
||||
$self->config->{terminal_args} = $options{'term-args'}
|
||||
if ( $options{'term-args'} );
|
||||
if ( $self->config->{terminal_args} =~ /-class (\w+)/ ) {
|
||||
$self->config->{terminal_allow_send_events}
|
||||
= "-xrm '$1.VT100.allowSendEvents:true'";
|
||||
}
|
||||
|
||||
$self->config->dump() if ( $options{'output-config'} );
|
||||
|
||||
$self->evaluate_commands() if ( $options{evaluate} );
|
||||
|
@ -2003,8 +1950,6 @@ the code until this time.
|
|||
|
||||
=item change_main_window_title
|
||||
|
||||
=item check_config
|
||||
|
||||
=item close_inactive_sessions
|
||||
|
||||
=item config
|
||||
|
@ -2025,8 +1970,6 @@ the code until this time.
|
|||
|
||||
=item exit_prog
|
||||
|
||||
=item find_binary
|
||||
|
||||
=item get_clusters
|
||||
|
||||
=item get_font_size
|
||||
|
|
|
@ -97,6 +97,8 @@ sub new {
|
|||
$self->{ $self->{comms} } = $self->find_binary( $self->{comms} );
|
||||
}
|
||||
|
||||
$self->{terminal} = $self->find_binary( $self->{terminal} );
|
||||
|
||||
$self->{title} = uc($Script);
|
||||
|
||||
$clusters = App::ClusterSSH::Cluster->new();
|
||||
|
@ -186,7 +188,7 @@ sub parse_config_file {
|
|||
foreach my $cluster ( sort split / /, $read_config{clusters} ) {
|
||||
if ( $read_config{$cluster} ) {
|
||||
$clusters->register_tag( $cluster, $read_config{$cluster} );
|
||||
$old_clusters{$cluster}=$read_config{$cluster};
|
||||
$old_clusters{$cluster} = $read_config{$cluster};
|
||||
delete( $read_config{$cluster} );
|
||||
}
|
||||
}
|
||||
|
@ -280,12 +282,13 @@ sub write_user_config_file {
|
|||
);
|
||||
}
|
||||
|
||||
return $self if(!%old_clusters);
|
||||
return $self if ( !%old_clusters );
|
||||
|
||||
if( open( my $fh, ">", "$ENV{HOME}/.clusterssh/clusters" ) ) {
|
||||
print $fh '# '.$self->loc('Tag definitions moved from old .csshrc file'),$/;
|
||||
foreach ( sort( keys(%old_clusters))){
|
||||
print $fh $_, ' ', join(' ', $old_clusters{$_}),$/;
|
||||
if ( open( my $fh, ">", "$ENV{HOME}/.clusterssh/clusters" ) ) {
|
||||
print $fh '# '
|
||||
. $self->loc('Tag definitions moved from old .csshrc file'), $/;
|
||||
foreach ( sort( keys(%old_clusters) ) ) {
|
||||
print $fh $_, ' ', join( ' ', $old_clusters{$_} ), $/;
|
||||
}
|
||||
close($fh);
|
||||
}
|
||||
|
@ -306,6 +309,19 @@ sub find_binary {
|
|||
}
|
||||
|
||||
$self->debug( 2, "Looking for $binary" );
|
||||
|
||||
# if not found, strip the path and look again
|
||||
if ( $binary =~ m!^/! ) {
|
||||
if ( -f $binary ) {
|
||||
$self->debug( 2, "$binary already fully qualified" );
|
||||
return $binary;
|
||||
}
|
||||
else {
|
||||
$self->debug( 2, "$binary not found - re-searching" );
|
||||
$binary =~ s!^.*/!!;
|
||||
}
|
||||
}
|
||||
|
||||
my $path;
|
||||
if ( !-x $binary || substr( $binary, 0, 1 ) ne '/' ) {
|
||||
|
||||
|
|
31
t/15config.t
31
t/15config.t
|
@ -21,7 +21,7 @@ $config = App::ClusterSSH::Config->new();
|
|||
isa_ok( $config, 'App::ClusterSSH::Config' );
|
||||
|
||||
Readonly::Hash my %default_config => {
|
||||
terminal => "xterm",
|
||||
terminal => "/usr/bin/xterm",
|
||||
terminal_args => "",
|
||||
terminal_title_opt => "-T",
|
||||
terminal_colorize => 1,
|
||||
|
@ -229,6 +229,33 @@ is( $trap->stderr, q{}, 'Expecting no STDERR' );
|
|||
is_deeply( $config, \%expected, 'amended config is correct' );
|
||||
is( $path, which('ls'), 'Found correct path to "ls"' );
|
||||
|
||||
# check for a binary already found
|
||||
my $newpath;
|
||||
trap {
|
||||
$newpath = $config->find_binary($path);
|
||||
};
|
||||
is( $trap->leaveby, 'return', 'returned ok' );
|
||||
isa_ok( $config, "App::ClusterSSH::Config" );
|
||||
isa_ok( $config, "App::ClusterSSH::Config" );
|
||||
is( $trap->stdout, q{}, 'Expecting no STDOUT' );
|
||||
is( $trap->stderr, q{}, 'Expecting no STDERR' );
|
||||
is_deeply( $config, \%expected, 'amended config is correct' );
|
||||
is( $path, which('ls'), 'Found correct path to "ls"' );
|
||||
is( $path, $newpath, 'No change made from find_binary');
|
||||
|
||||
# give false path to force another search
|
||||
trap {
|
||||
$newpath = $config->find_binary('/does/not/exist/'.$path);
|
||||
};
|
||||
is( $trap->leaveby, 'return', 'returned ok' );
|
||||
isa_ok( $config, "App::ClusterSSH::Config" );
|
||||
isa_ok( $config, "App::ClusterSSH::Config" );
|
||||
is( $trap->stdout, q{}, 'Expecting no STDOUT' );
|
||||
is( $trap->stderr, q{}, 'Expecting no STDERR' );
|
||||
is_deeply( $config, \%expected, 'amended config is correct' );
|
||||
is( $path, which('ls'), 'Found correct path to "ls"' );
|
||||
is( $path, $newpath, 'No change made from find_binary');
|
||||
|
||||
note('Checks on loading configs');
|
||||
note('empty dir');
|
||||
$ENV{HOME} = tempdir( CLEANUP => 1 );
|
||||
|
@ -463,7 +490,7 @@ send_menu_xml_file=/home/dferguson/.csshrc_send_menu
|
|||
show_history=0
|
||||
ssh_args=
|
||||
telnet_args=
|
||||
terminal=xterm
|
||||
terminal=/usr/bin/xterm
|
||||
terminal_allow_send_events=-xrm '*.VT100.allowSendEvents:true'
|
||||
terminal_args=
|
||||
terminal_bg_style=dark
|
||||
|
|
Loading…
Add table
Reference in a new issue