App-Term-Jump

 view release on metacpan or  search on metacpan

lib/App/Term/Jump.pm  view on Meta::CPAN


=item * \%options - options parsed from the command line

=item * \@command_line_arguments - arguments parsed from the command line

=back

I<Returns> - An aray refeence - empty or the result of a search
=cut

my ($options, $command_line_arguments) = @_ ;

my $results = [] ;

remove_all($options, $command_line_arguments) if($options->{remove_all}) ;
remove($options, $command_line_arguments) if($options->{remove}) ;

add($options, $command_line_arguments) if($options->{add}) ;

$results = complete($options, $command_line_arguments) if($options->{complete}) ;
$results = search($options, $command_line_arguments) if($options->{search}) ;

show_database($options) if($options->{show_database}) ;
show_configuration_files($options) if($options->{show_configuration_files}) ;
show_version() if($options->{version}) ;

return $results ;
}

#------------------------------------------------------------------------------------------------------------------------

sub parse_command_line
{

=head2 [p] parse_command_line(@command_line_argumens)

Parses the command line and loads the configuration file

I<Arguments> -

=over 2

=item * @command_line_arguments -  

=back

I<Returns> -

=over 2

=item * \%options - options parsed from the command line

=item * \@command_line_arguments - arguments parsed from the command line

=back

I<Exceptions> - invalid options 

=cut

local @ARGV = @_ ;

my %options = (ignore_path => []) ;

$options{db_location} = defined $ENV{APP_TERM_JUMP_DB} ? $ENV{APP_TERM_JUMP_DB} : home() . '/.jump_db' ;
$options{config_location} = defined $ENV{APP_TERM_JUMP_CONFIG} ? $ENV{APP_TERM_JUMP_CONFIG} : home() . '/.jump_config'  ;

%options = ( %options, %{ get_config($options{config_location}) } ) ;

die 'Error parsing options!' unless 
	GetOptions
                (
		'search' => \$options{search},
		'file=s' => \$options{file},

		'complete' => \$options{complete},

		'a|add' => \$options{add},
		'r|remove' => \$options{remove},
		'remove_all' => \$options{remove_all},

		's|show_database' => \$options{show_database},

		'show_configuration_files' => \$options{show_configuration_files},
		'v|V|version' => \$options{version},
                'h|help' => \$options{help}, 

		'ignore_path=s' => $options{ignore_path},

		'q|quote' => \$options{quote},
		'ignore_case' => \$options{ignore_case},
		'no_direct_path' => \$options{no_direct_path},
		'no_sub_cwd' => \$options{no_sub_cwd},
		'no_sub_db' => \$options{no_sub_db},

		'd|debug' => \$options{debug},
                ) ;
	
# broken bash completion gives use file regext with quotes from command line!
$options{file} = $1 if(defined $options{file} && $options{file} =~ /^(?:'|")(.*)(?:'|")$/) ;

# remove trailing slash, except for root
@ARGV = map {s[(.)/$][$1]; $_} @ARGV ;

return (\%options, \@ARGV) ;
}

#------------------------------------------------------------------------------------------------------------------------

sub get_config
{

=head2 [p] get_config($config_location)

Parses a file that contains the default configuration

I<Arguments> -

=over 2

=item * $config_location - a string - path to the configuraation file

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 3.020 seconds using v1.00-cache-2.02-grep-82fe00e-cpan-72ae3ad1e6da )