Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 62 additions & 16 deletions cmd/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@ package cmd
import (
"context"
"encoding/json"
"errors"
"fmt"
"strconv"

"github.com/charmbracelet/huh"
"github.com/uselagoon/lagoon-cli/internal/util"
"github.com/uselagoon/lagoon-cli/internal/wizard/project"

"strings"

"github.com/uselagoon/machinery/api/lagoon"
Expand Down Expand Up @@ -143,10 +148,24 @@ var addProjectCmd = &cobra.Command{
if err != nil {
return err
}

if err := requiredInputCheck("Project name", cmdProjectName, "git-url", gitUrl, "Production environment", productionEnvironment, "Deploytarget", strconv.Itoa(int(deploytarget))); err != nil {
interactive, err := cmd.Flags().GetBool("interactive")
if err != nil {
return err
}
genCmdEnabled, err := cmd.Flags().GetBool("generate-command")
if err != nil {
return err
}
if interactive && !experimentalEnabled {
return fmt.Errorf("--interactive requires experimental flag to be set in .lagoon.yml")
}
generatedCommand := ""

if !interactive {
if err := requiredInputCheck("Project name", cmdProjectName, "git-url", gitUrl, "Production environment", productionEnvironment, "Deploytarget", strconv.Itoa(int(deploytarget))); err != nil {
return err
}
}

current := lagoonCLIConfig.Current
token := lagoonCLIConfig.Lagoons[current].Token
Expand All @@ -157,19 +176,37 @@ var addProjectCmd = &cobra.Command{
&token,
debug)

projectInput := schema.AddProjectInput{
Name: cmdProjectName,
GitURL: gitUrl,
ProductionEnvironment: productionEnvironment,
StandbyProductionEnvironment: standbyProductionEnvironment,
Branches: branches,
PullRequests: pullrequests,
OpenshiftProjectPattern: deploytargetProjectPattern,
Openshift: deploytarget,
Subfolder: subfolder,
PrivateKey: privateKey,
BuildImage: buildImage,
RouterPattern: routerPattern,
projectInput := schema.AddProjectInput{}
if interactive {
config, err := project.RunCreateWizard(lc)
if err != nil {
if errors.Is(err, huh.ErrUserAborted) {
return nil
}
return err
}
projectInput = config.Input
if config.OrganizationDetails.Name != "" {
organizationName = config.OrganizationDetails.Name
}
generatedCommand = util.GenerateCLICommand(config)
}

if !interactive {
projectInput = schema.AddProjectInput{
Name: cmdProjectName,
GitURL: gitUrl,
ProductionEnvironment: productionEnvironment,
StandbyProductionEnvironment: standbyProductionEnvironment,
Branches: branches,
PullRequests: pullrequests,
OpenshiftProjectPattern: deploytargetProjectPattern,
Openshift: deploytarget,
Subfolder: subfolder,
PrivateKey: privateKey,
BuildImage: buildImage,
RouterPattern: routerPattern,
}
}
if orgOwnerProvided {
projectInput.AddOrgOwner = &orgOwner
Expand Down Expand Up @@ -210,12 +247,19 @@ var addProjectCmd = &cobra.Command{
Result: "success",
ResultData: map[string]interface{}{
"Project Name": project.Name,
"GitURL": gitUrl,
"GitURL": projectInput.GitURL,
},
}
if organizationName != "" {
resultData.ResultData["Organization"] = organizationName
}
if interactive && genCmdEnabled {
cmdPrefix := "lagoon add project"
if cmdLagoon != "" {
cmdPrefix = fmt.Sprintf("lagoon --lagoon %s add project", cmdLagoon)
}
resultData.ResultData["Generated Command"] = cmdPrefix + generatedCommand
}
r := output.RenderResult(resultData, outputOptions)
fmt.Fprintf(cmd.OutOrStdout(), "%s", r)
return nil
Expand Down Expand Up @@ -765,6 +809,8 @@ func init() {
addProjectCmd.Flags().Bool("owner", false, "Add the user as an owner of the project")
addProjectCmd.Flags().StringP("organization-name", "O", "", "Name of the Organization to add the project to")
addProjectCmd.Flags().UintP("organization-id", "", 0, "ID of the Organization to add the project to")
addProjectCmd.Flags().Bool("interactive", false, "Set Interactive mode for the project creation wizard. Requires 'experimental' flag to be set in .lagoon.yml")
addProjectCmd.Flags().Bool("generate-command", false, "Displays the generated command from the project creation wizard. Requires Interactive mode to be enabled")

listCmd.AddCommand(listProjectByMetadata)
listProjectByMetadata.Flags().StringP("key", "K", "", "The key name of the metadata value you are querying on")
Expand Down
2 changes: 2 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ var userPath string
var configFilePath string
var updateDocURL = "https://uselagoon.github.io/lagoon-cli"
var verboseOutput bool
var experimentalEnabled bool

var skipUpdateCheck bool

Expand Down Expand Up @@ -262,6 +263,7 @@ func initConfig() {
if cmdProject.Environment != "" && cmdProjectEnvironment == "" {
cmdProjectEnvironment = cmdProject.Environment
}
experimentalEnabled = lagoonCLIConfig.IsFlagSet("experimental")
}

func yesNo(message string) bool {
Expand Down
1 change: 1 addition & 0 deletions docs/commands/lagoon_add_project.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ lagoon add project [flags]
-L, --development-environments-limit uint How many environments can be deployed at one time
-g, --git-url string GitURL of the project
-h, --help help for project
--interactive Set Interactive mode for the project creation wizard.
-j, --json string JSON string to patch
--organization-id uint ID of the Organization to add the project to
-O, --organization-name string Name of the Organization to add the project to
Expand Down
43 changes: 34 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,46 +1,71 @@
module github.com/uselagoon/lagoon-cli

go 1.24.0
go 1.24.2

toolchain go1.24.1
toolchain go1.24.4

require (
github.com/Masterminds/semver/v3 v3.4.0
github.com/charmbracelet/huh v0.7.0
github.com/charmbracelet/lipgloss v1.1.0
github.com/golang-jwt/jwt v3.2.2+incompatible
github.com/google/go-github/v66 v66.0.0
github.com/guregu/null v4.0.0+incompatible
github.com/integralist/go-findroot v0.0.0-20160518114804-ac90681525dc
github.com/jedib0t/go-pretty/v6 v6.6.8
github.com/jedib0t/go-pretty/v6 v6.7.1
github.com/logrusorgru/aurora v2.0.3+incompatible
github.com/manifoldco/promptui v0.9.0
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c
github.com/skeema/knownhosts v1.3.1
github.com/skeema/knownhosts v1.3.2
github.com/spf13/cobra v1.10.1
github.com/spf13/pflag v1.0.10
github.com/stretchr/testify v1.11.1
github.com/uselagoon/machinery v0.0.34
golang.org/x/crypto v0.42.0
golang.org/x/term v0.35.0
golang.org/x/crypto v0.43.0
golang.org/x/term v0.36.0
gopkg.in/yaml.v3 v3.0.1
)

require (
github.com/atotto/clipboard v0.1.4 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/catppuccin/go v0.3.0 // indirect
github.com/charmbracelet/bubbles v0.21.0 // indirect
github.com/charmbracelet/bubbletea v1.3.5 // indirect
github.com/charmbracelet/colorprofile v0.3.1 // indirect
github.com/charmbracelet/x/ansi v0.8.0 // indirect
github.com/charmbracelet/x/cellbuf v0.0.13 // indirect
github.com/charmbracelet/x/exp/strings v0.0.0-20251109135125-8916d276318f // indirect
github.com/charmbracelet/x/term v0.2.2 // indirect
github.com/chzyer/readline v1.5.1 // indirect
github.com/clipperhouse/stringish v0.1.1 // indirect
github.com/clipperhouse/uax29/v2 v2.3.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.7 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/hashicorp/go-version v1.7.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/kr/pretty v0.3.0 // indirect
github.com/lucasb-eyer/go-colorful v1.3.0 // indirect
github.com/machinebox/graphql v0.2.3-0.20181106130121-3a9253180225 // indirect
github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect
github.com/mattn/go-runewidth v0.0.19 // indirect
github.com/mitchellh/hashstructure/v2 v2.0.2 // indirect
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/muesli/termenv v0.16.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/rogpeppe/go-internal v1.9.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
golang.org/x/sys v0.36.0 // indirect
golang.org/x/text v0.29.0 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
golang.org/x/sync v0.17.0 // indirect
golang.org/x/sys v0.38.0 // indirect
golang.org/x/text v0.30.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
)
Loading
Loading