Net-Fastly

 view release on metacpan or  search on metacpan

bin/fastly  view on Meta::CPAN


use strict;
use warnings;
use Net::Fastly;
use File::Basename;
use Data::Dumper;
use POSIX qw(strftime);
use YAML;

BEGIN {
    eval {
      require Term::ShellUI;
      Term::ShellUI->import();
      require Term::ANSIColor;
      Term::ANSIColor->import(qw(:constants));
  
    };

    die "You must install Term::ShellUI and Term::ANSIColorin order to run the Fastly shell\n" if $@;
}

=head1 NAME

fastly - a command line shell for interacting with the Fastly infrastructure

=head1 USAGE

    fastly [option[s]] 

=head1 CONFIGURATION

You can either have a config file in either ~/.fastly or /etc/fastly with

    user     = <login>
    password = <password>
    
B<NOTE:> For the time being you must use username and password, not API key. This may change in the future.

Alternatively you can pass in any of those options on the command line

    fastly --user=<login> --password=<password>
    
=head1 PROXYING

There are three ways to proxy:

The first method is to put a proxy option in your .fastly file (or pass it in on)

    proxy = http://localhost:8080
    
The second is to pass it in on the command line

    fastly --user <login> --password <password> --proxy http://localhost:8080

Lastly, the third method is to set your C<https_proxy> environment variable. So, in Bash

    % export https_proxy=http://localhost:8080

or in CSH or TCSH

    % setenv https_proxy=http://localhost:8080    

=head1 DESCRIPTION
    

=cut

my %opts   = Net::Fastly::get_options($ENV{HOME}."/.fastly", "/etc/fastly");
my $fastly = Net::Fastly->new(%opts);

my $customer = $fastly->current_customer;



my $term = Term::ShellUI->new(app => "fastly", keep_quotes => 0,  history_file => $ENV{HOME}."/.fastly_history", prompt => "fastly> ");
          
#$term->{debug_complete}=5;
 
print 'Using '.$term->{term}->ReadLine."\n";
# precache the list of services

my $basecommands = { 
    "help" => {
        desc => "Print helpful information",
        args => sub { shift->help_args(undef, @_); },
        method => sub { shift->help_call(undef, @_); }
    },
    "quit" => { 
        desc => "Quit", 
        maxargs => 0,
        method => sub { shift->exit_requested(1) },
        exclude_from_history => 1,
    },
    "who" => {
        desc => "Print who is logged in",
        proc => \&who,
    }, 
    "show" => {
        desc => "Display objects",
        cmds => {
            service => {
                desc => "Show a service",
                doc => "Lists services",
                minargs => 1,
                maxargs => 3,
                args => [\&list_service_complete, sub { ['version'] }, \&list_version],
                proc => \&show_service,
            },
            services => {
                desc => "List services",
                proc => \&show_services,
            },
            versions => {
                desc    => "Show all the versions for a service",
                cmds    => {
                    service => {
                        desc    => "The service name",
                        minargs => 1,
                        maxargs => 1,
                        args    => [\&list_service_complete ],
                        proc    => \&show_versions,



( run in 2.423 seconds using v1.01-cache-2.11-cpan-2398b32b56e )