22 stable releases (5 major)
6.0.0+20191206 | Oct 15, 2024 |
---|---|
5.0.4+20191206 | Mar 5, 2024 |
3.1.0+20191206 | Apr 26, 2022 |
3.0.0+20191206 | Mar 8, 2022 |
0.3.6+20160811 | Sep 11, 2016 |
#2726 in Web programming
165KB
2.5K
SLoC
The pagespeedonline2
command-line interface (CLI) allows to use most features of the Google pagespeedonline service from the comfort of your terminal.
By default all output is printed to standard out, but flags can be set to direct it into a file independent of your shell's capabilities. Errors will be printed to standard error, and cause the program's exit code to be non-zero.
If data-structures are requested, these will be returned as pretty-printed JSON, to be useful as input to other tools.
Everything else about the pagespeedonline API can be found at the official documentation site.
Installation and Source Code
Install the command-line interface with cargo using:
cargo install google-pagespeedonline2-cli
Find the source code on github.
Usage
This documentation was generated from the pagespeedonline API at revision 20191206. The CLI is at version 6.0.0.
pagespeedonline2 [options]
pagespeedapi
runpagespeed <url> [-p <v>]... [-o <out>]
pagespeedonline2 --help
Configuration:
--config-dir <folder>
A directory into which we will store our persistent data. Defaults to
a user-writable directory that we will create during the first invocation.
[default: ~/.google-service-cli]
Configuration
The program will store all persistent data in the ~/.google-service-cli
directory in JSON files prefixed with pagespeedonline2-
. You can change the directory used to store configuration with the --config-dir
flag on a per-invocation basis.
More information about the various kinds of persistent data are given in the following paragraphs.
Authentication
Most APIs require a user to authenticate any request. If this is the case, the scope determines the set of permissions granted. The granularity of these is usually no more than read-only or full-access.
If not set, the system will automatically select the smallest feasible scope, e.g. when invoking a
method that is read-only, it will ask only for a read-only scope.
You may use the --scope
flag to specify a scope directly.
All applicable scopes are documented in the respective method's CLI documentation.
The first time a scope is used, the user is asked for permission. Follow the instructions given by the CLI to grant permissions, or to decline.
If a scope was authenticated by the user, the respective information will be stored as JSON in the configuration
directory, e.g. ~/.google-service-cli/pagespeedonline2-token-<scope-hash>.json
. No manual management of these tokens
is necessary.
To revoke granted authentication, please refer to the official documentation.
Application Secrets
In order to allow any application to use Google services, it will need to be registered using the Google Developer Console. APIs the application may use are then enabled for it one by one. Most APIs can be used for free and have a daily quota.
To allow more comfortable usage of the CLI without forcing anyone to register an own application, the CLI comes with a default application secret that is configured accordingly. This also means that heavy usage all around the world may deplete the daily quota.
You can workaround this limitation by putting your own secrets file at this location:
~/.google-service-cli/pagespeedonline2-secret.json
, assuming that the required pagespeedonline API
was enabled for it. Such a secret file can be downloaded in the Google Developer Console at
APIs & auth -> Credentials -> Download JSON and used as is.
Learn more about how to setup Google projects and enable APIs using the official documentation.
Debugging
Even though the CLI does its best to provide usable error messages, sometimes it might be desirable to know what exactly led to a particular issue. This is done by allowing all client-server communication to be output to standard error as-is.
The --debug
flag will print errors using the Debug
representation to standard error.
You may consider redirecting standard error into a file for ease of use, e.g. pagespeedonline2 --debug <resource> <method> [options] 2>debug.txt
.
Dependencies
~22–34MB
~602K SLoC