App-Presto
view release on metacpan or search on metacpan
# save the last 5 history entries
http://my-server.com> save my-script 5
# save entries 3-7
http://my-server.com> save my-script 3..7
To replay scripts:
http://my-server.com> source my-script
# prompt before each command
http://my-server.com> source -i my-script
Variable interpolation
At times (especially when working with scripts) it might be handy to
use elements from a previous response to affect a subsequent request.
Anything inside a balanced $(...) will be interpolated for you. For
instance, a very contrived example:
# hypothetical authentication protocal that returns a token in the response headers
# store the value
http://my-server.com> stash auth-token $(HEADER[X-Auth-Token])
# use the value later
http://my-server.com> header X-Auth-Token $(STASH[auth-token])
Those variable substitutions can be used anywhere in a command. HEADER
and BODY always refer to the most recent request while the STASH is a
persisted for the life of the process.
One useful feature for scripting is to prompt for user input. You can
do this by using the PROMPT pseudo-variable. The first set of brackets
specify the prompt value. The second (optional) set of brackets specify
the initial value. An example:
# collect the username/password from the user
http://my-server.com> stash username $(PROMPT[username:])
http://my-server.com> stash password $(PROMPT[password:])
# use the stashed values
http://my-server.com> authorization $(STASH[username]) $(STASH[password])
http://my-server.com> GET /$(STASH[username])/profile
# or use a value that was prompted for directly (without stashing it)
http://my-server.com> GET /products 'created_on=$(PROMPT[Created on (YYYY-MM-DD):])'
# you can also specify initial values
http://my-server.com> GET /products 'status=$(PROMPT[Product status:][active])'
You may also specify a local file to use as an argument to a command.
An example:
http://my-server.com> POST /products $(FILE[my-product.xml])
README.mkdn view on Meta::CPAN
# save the last 5 history entries
http://my-server.com> save my-script 5
# save entries 3-7
http://my-server.com> save my-script 3..7
To replay scripts:
http://my-server.com> source my-script
# prompt before each command
http://my-server.com> source -i my-script
## Variable interpolation
At times (especially when working with scripts) it might be handy to
use elements from a previous response to affect a subsequent request.
Anything inside a balanced `$(...)` will be interpolated for you.
For instance, a very contrived example:
# hypothetical authentication protocal that returns a token in the response headers
README.mkdn view on Meta::CPAN
# store the value
http://my-server.com> stash auth-token $(HEADER[X-Auth-Token])
# use the value later
http://my-server.com> header X-Auth-Token $(STASH[auth-token])
Those variable substitutions can be used anywhere in a command. `HEADER`
and `BODY` always refer to the most recent request while the `STASH`
is a persisted for the life of the process.
One useful feature for scripting is to prompt for user input. You can do
this by using the `PROMPT` pseudo-variable. The first set of brackets
specify the prompt value. The second (optional) set of brackets specify
the initial value. An example:
# collect the username/password from the user
http://my-server.com> stash username $(PROMPT[username:])
http://my-server.com> stash password $(PROMPT[password:])
# use the stashed values
http://my-server.com> authorization $(STASH[username]) $(STASH[password])
http://my-server.com> GET /$(STASH[username])/profile
# or use a value that was prompted for directly (without stashing it)
http://my-server.com> GET /products 'created_on=$(PROMPT[Created on (YYYY-MM-DD):])'
# you can also specify initial values
http://my-server.com> GET /products 'status=$(PROMPT[Product status:][active])'
You may also specify a local file to use as an argument to a command. An example:
http://my-server.com> POST /products $(FILE[my-product.xml])
The file is assumed to be in the same encoding as the `binmode`
# save the last 5 history entries
http://my-server.com> save my-script 5
# save entries 3-7
http://my-server.com> save my-script 3..7
To replay scripts:
http://my-server.com> source my-script
# prompt before each command
http://my-server.com> source -i my-script
=head2 Variable interpolation
At times (especially when working with scripts) it might be handy to
use elements from a previous response to affect a subsequent request.
Anything inside a balanced C<$(...)> will be interpolated for you.
For instance, a very contrived example:
# hypothetical authentication protocal that returns a token in the response headers
# store the value
http://my-server.com> stash auth-token $(HEADER[X-Auth-Token])
# use the value later
http://my-server.com> header X-Auth-Token $(STASH[auth-token])
Those variable substitutions can be used anywhere in a command. C<HEADER>
and C<BODY> always refer to the most recent request while the C<STASH>
is a persisted for the life of the process.
One useful feature for scripting is to prompt for user input. You can do
this by using the C<PROMPT> pseudo-variable. The first set of brackets
specify the prompt value. The second (optional) set of brackets specify
the initial value. An example:
# collect the username/password from the user
http://my-server.com> stash username $(PROMPT[username:])
http://my-server.com> stash password $(PROMPT[password:])
# use the stashed values
http://my-server.com> authorization $(STASH[username]) $(STASH[password])
http://my-server.com> GET /$(STASH[username])/profile
# or use a value that was prompted for directly (without stashing it)
http://my-server.com> GET /products 'created_on=$(PROMPT[Created on (YYYY-MM-DD):])'
# you can also specify initial values
http://my-server.com> GET /products 'status=$(PROMPT[Product status:][active])'
You may also specify a local file to use as an argument to a command. An example:
http://my-server.com> POST /products $(FILE[my-product.xml])
The file is assumed to be in the same encoding as the C<binmode>
lib/App/Presto.pm view on Meta::CPAN
},
"history" => {
exclude_from_completion => 1,
exclude_from_history => 1,
desc => "Prints the command history",
args => "[-c] [-d] [number]",
method => sub { shift->history_call(@_) },
doc => "Specify a number to list the last N lines of history Pass -c to clear the command history, -d NUM to delete a single item\n",
},
},
prompt => sprintf( '%s> ', $self->endpoint ),
history_file => $self->config->file('history'),
);
$term->ornaments('md,me,,');
return $term;
}
has command_factory => (
is => 'lazy',
);
sub _build_command_factory { return App::Presto::CommandFactory->new }
lib/App/Presto/ArgProcessor.pm view on Meta::CPAN
my ($key, $dpath) = ($2, $3);
$replacement = $self->stash(substr($key,1,-1));
if($dpath){
$replacement = _apply_dpath($replacement, $dpath)
}
} elsif($param =~ m/^FILE($RE{balanced}{-parens => '[]'})($RE{balanced}{-parens => '[]'})?/){
my $file = substr($1, 1, -1);
my $encoding = $2 ? substr($2, 1, -1) : $self->config->get('binmode') || 'utf8';
$replacement = read_file( $file, { binmode => ":encoding($encoding)" } );
} elsif($param =~ m/^PROMPT($RE{balanced}{-parens => '[]'})($RE{balanced}{-parens => '[]'})?/){
my($prompt,$default) = ($1, $2);
$replacement = $self->term->readline( substr( $prompt, 1, -1 ) . ' ', ($default ? substr( $default, 1, -1 ) : () ) );
}
return defined $replacement ? $replacement : $orig;
}
sub _expand_response_param {
my $self = shift;
my $section = shift;
my $sub_section = shift;
my $client = $self->client;
if($section eq 'HEADER' && $sub_section =~ m/($RE{balanced}{-parens => '[]'})/){
( run in 1.230 second using v1.01-cache-2.11-cpan-6aa56a78535 )