Liferay CLI
lfr
is an unofficial CLI tool written in Go that helps you create & manage Liferay projects.
Table of contents:
Motivation
I needed a subject to play with Go. Writing a CLI tool is fun - especially with Cobra - and I wanted to explore how to distribute it using GitHub Actions (and GoReleaser).
Also, I get sometimes frustrated by Blade and wanted to focus on providing:
- Better performances (cf. benchmarks)
- Better support for Maven
- Shorter commands
- More consistent commands names and ordering
- Details after any command execution
- Shell completion
I'm not the only one motivated to help Liferay developpers with new dev tools. If you're looking for something to help you with Client Extensions development, definitely checkout this tool: https://github.com/bnheise/ce-cli
Installation
For macOS or Linux, you can install it using Homebrew:
brew tap lgdd/homebrew-tap
brew install liferay-cli
Checkout the release page to download the binary for your distribution.
Completions
Usage:
lfr completion [bash|zsh|fish|powershell]
To load completions for Bash, Zsh, fish and PowerShell:
Bash:
source <(lfr completion bash)
# To load completions for each session, execute once:
# Linux:
lfr completion bash > /etc/bash_completion.d/lfr
# macOS:
lfr completion bash > /usr/local/etc/bash_completion.d/lfr
Zsh:
# If shell completion is not already enabled in your environment,
# you will need to enable it. You can execute the following once:
echo "autoload -U compinit; compinit" >> ~/.zshrc
# To load completions for each session, execute once:
lfr completion zsh > "${fpath[1]}/_lfr"
# You will need to start a new shell for this setup to take effect.
fish:
lfr completion fish | source
# To load completions for each session, execute once:
lfr completion fish > ~/.config/fish/completions/lfr.fish
PowerShell:
PS> lfr completion powershell | Out-String | Invoke-Expression
# To load completions for every new session, run:
PS> lfr completion powershell > lfr.ps1
# and source this file from your PowerShell profile.
Usage
diagnose
Run a diagnosis to verify your environment for Liferay development:
lfr diag
Aliases:
diagnose, diag
The output of this command will list your installations of Java, Blade and Docker. It will also display how much space are being used by cached bundles and docker images.
Example:
create
workspace
lfr create workspace liferay-workspace
Aliases:
workspace, ws
Flags:
-b, --build string build tool (gradle or maven) (default "gradle")
-h, --help help for workspace
-i, --init executes Liferay bundle initialization (i.e. download & unzip in the workspace)
-v, --version string Liferay major version (7.x) (default "7.4")
client-extension
Client extensions extend Liferay (7.4 U45+/GA45+) without using OSGi modules.
lfr create client-extension
Aliases:
client-extension, cx
Flags:
-h, --help help for client-extension
Since client extensions are available as samples in liferay-portal repo, it will checkout the subdirectory containing them under $HOME/.lfr/liferay-portal
.
api
Creates a minimal OSGi module, with an Export-Package
directive:
lfr create api my-api
Flags:
-h, --help help for api
Global Flags:
--no-color disable colors for output messages
-p, --package string base package name (default "org.acme")
service-builder
lfr create service-builder my-service-builder
Aliases:
service-builder, sb
Flags:
-h, --help help for service-builder
Global Flags:
--no-color disable colors for output messages
-p, --package string base package name (default "org.acme")
rest-builder
lfr create rest-builder my-rest-service
Aliases:
rest-builder, rb
Flags:
-g, --generate executes code generation
-h, --help help for rest-builder
Global Flags:
--no-color disable colors for output messages
-p, --package string base package name (default "org.acme")
mvc-portlet
lfr create mvc-portlet my-portlet
Aliases:
mvc-portlet, mvc
Flags:
-h, --help help for mvc-portlet
Global Flags:
--no-color disable colors for output messages
-p, --package string base package name (default "org.acme")
spring-mvc-portlet
lfr create spring-mvc-portlet my-spring-mvc
Aliases:
spring-mvc-portlet, spring
Flags:
-h, --help help for spring-mvc-portlet
-t, --template string template engine (thymeleaf or jsp) (default "thymeleaf")
Global Flags:
--no-color disable colors for output messages
-p, --package string base package name (default "org.acme")
docker
Creates Dockerfile (multi-stag or not) and docker-compose samples:
lfr create docker
Flags:
-h, --help help for docker
-j, --java int Java version (8 or 11) (default 11)
-m, --multi-stage use multi-stage build
Global Flags:
--no-color disable colors for output messages
-p, --package string base package name (default "org.acme")
exec
Execute Gradle or Maven task(s):
# Gradle
lfr exec build
# Maven
lfr exec clean install
Aliases:
exec, x
Flags:
-h, --help help for exec
Global Flags:
--no-color disable colors for output messages
build
Shortcut to build your Liferay bundle:
lfr build
Aliases:
build, b
Flags:
-h, --help help for build
Global Flags:
--no-color disable colors for output messages
deploy
Shortcut to deploy your modules using Gradle or Maven:
lfr deploy
Aliases:
deploy, d
Flags:
-h, --help help for deploy
Global Flags:
--no-color disable colors for output messages
init
Shortcut to initialize your Liferay bundle:
lfr init
Aliases:
init, i
Flags:
-h, --help help for init
Global Flags:
--no-color disable colors for output messages
start
Start the Liferay Tomcat bundle initialized in your workspace:
lfr start
It creates a file named .liferay-pid
which is used by lfr status
display if Tomcat is running or not (or it can be used to kill it if necessary).
Flags:
-h, --help help for start
Global Flags:
--no-color disable colors for output messages
stop
Stop the Liferay Tomcat bundle initialized in your workspace:
lfr start
Flags:
-h, --help help for start
Global Flags:
--no-color disable colors for output messages
status
Display the status (running or stopped) of Liferay Tomcat from your workspace:
lfr status
Flags:
-h, --help help for start
Global Flags:
--no-color disable colors for output messages
logs
Display and follow the logs from the running Liferay bundle:
lfr logs -f
Aliases:
logs, l
Flags:
-f, --follow --follow
-h, --help help for logs
Global Flags:
--no-color disable colors for output messages
shell
Connect and get Liferay Gogo Shell:
lfr sh
Aliases:
shell, sh
Flags:
-h, --help help for shell
--host string --host localhost (default "localhost")
-p, --port int --port 11311 (default 11311)
Global Flags:
--no-color disable colors for output message
The keyword exit
can be safely used with this shell as it will disconnect instead of stopping the OSGi container. Ctrl+C
also disconnect from the shell.
Known issue: The "shell" command is very slow to connect
Benchmarks
Using Hyperfine.
Create Workspace
Command |
Mean [s] |
Min [s] |
Max [s] |
Relative |
blade init -v 7.4 liferay-workspace |
1.837 ± 0.300 |
1.665 |
2.668 |
19.94 ± 5.69 |
lfr create ws liferay-workspace |
0.092 ± 0.022 |
0.076 |
0.178 |
1.00 |
Create MVC Portlet
Command |
Mean [s] |
Min [s] |
Max [s] |
Relative |
blade create -t mvc-portlet my-mvc-portlet |
1.608 ± 0.021 |
1.570 |
1.647 |
59.70 ± 112.37 |
lfr create mvc my-mvc-portlet |
0.027 ± 0.051 |
0.015 |
0.345 |
1.00 |
Create Service Builder
Command |
Mean [s] |
Min [s] |
Max [s] |
Relative |
blade create -t service-builder my-service-builder |
1.628 ± 0.057 |
1.573 |
1.772 |
82.00 ± 134.01 |
lfr create sb my-service-builder |
0.020 ± 0.032 |
0.014 |
0.332 |
1.00 |
License
MIT