Skip to content

Commit

Permalink
feat: add trial command to get a DXP trial key
Browse files Browse the repository at this point in the history
  • Loading branch information
lgdd committed Feb 1, 2025
1 parent 314ec88 commit fecad66
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 3 deletions.
4 changes: 2 additions & 2 deletions docs/commands/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ permalink: /cmd/config

# lfr config
{: .d-inline-block }
New (v3.1.0)
{: .label .label-green .mb-5 }
v3.1.0+
{: .label .label-info .mb-5 }

Helper command to quickly set new values in your configuration as an alternative to edit the file under `$HOME/.lfr/config.toml` (see [Configuration](/configuration)).

Expand Down
30 changes: 30 additions & 0 deletions docs/commands/trial.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
layout: default
title: trial
parent: Commands
nav_order: 11
permalink: /cmd/trial
---

# lfr trial
{: .d-inline-block }
NEW (3.2.0)
{: .label .label-green .mb-5 }


It will fetch a DXP trial key from [this repo](https://github.com/lgdd/liferay-product-info/tree/main/dxp-trial) which automatically extract a DXP trial key from the latest Docker image of Liferay DXP.

The DXP trial key is then saved in the current directory of the command as a `trial.xml` file. If this file already exists, it won't override it.

## Usage:
```shell
lfr trial
lfr t
```

## Flags:
- `-h`, `--help`
- help for `lfr trial`
## Global Flags:
- `--no-color`
- disable colors for output messages
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ nav_order: 1

# lfr-cli
{: .d-inline-block }
v3.1.0
v3.2.0
{: .label .mb-5 }

`lfr` is an unofficial CLI tool written in Go that helps you create & manage Liferay projects.
Expand Down
2 changes: 2 additions & 0 deletions internal/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/lgdd/lfr-cli/internal/cmd/start"
"github.com/lgdd/lfr-cli/internal/cmd/status"
"github.com/lgdd/lfr-cli/internal/cmd/stop"
"github.com/lgdd/lfr-cli/internal/cmd/trial"
"github.com/lgdd/lfr-cli/internal/cmd/update"
"github.com/lgdd/lfr-cli/internal/cmd/version"
"github.com/lgdd/lfr-cli/internal/conf"
Expand All @@ -43,6 +44,7 @@ func init() {
root.AddCommand(update.Cmd)
root.AddCommand(diagnose.Cmd)
root.AddCommand(config.Cmd)
root.AddCommand(trial.Cmd)

conf.Init()
defaultNoColor := viper.GetBool(conf.OutputNoColor)
Expand Down
45 changes: 45 additions & 0 deletions internal/cmd/trial/trial.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package trial

import (
"io"
"net/http"
"os"

"github.com/lgdd/lfr-cli/internal/conf"
"github.com/lgdd/lfr-cli/pkg/util/logger"

"github.com/spf13/cobra"
)

var (
Cmd = &cobra.Command{
Use: "trial",
Aliases: []string{"t"},
Short: "Get a DXP trial key to be placed in the current directory",
Args: cobra.NoArgs,
Run: run,
}
Follow bool
)

func init() {
conf.Init()
}

func run(cmd *cobra.Command, args []string) {
resp, error := http.Get("https://raw.githubusercontent.com/lgdd/liferay-product-info/refs/heads/main/dxp-trial/trial.xml")

if error != nil {
logger.Fatal(error.Error())
}

defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
if _, error = os.Stat("trial.xml"); error == nil {
logger.PrintWarn("trial.xml already exists")
} else {
os.WriteFile("trial.xml", body, 0666)
logger.PrintSuccess("created ")
logger.Print("trial.xml")
}
}

0 comments on commit fecad66

Please sign in to comment.