Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change: Refactored get project command, adds deploymentsDisabled & updated to use bools instead of int bools #297

Merged
merged 7 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from 6 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
90 changes: 71 additions & 19 deletions cmd/get.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package cmd

import (
"context"
"encoding/json"
"fmt"
"os"

"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/uselagoon/lagoon-cli/pkg/api"
"github.com/uselagoon/lagoon-cli/pkg/output"
"os"
"strconv"

l "github.com/uselagoon/machinery/api/lagoon"
lclient "github.com/uselagoon/machinery/api/lagoon/client"
)

// GetFlags .
Expand Down Expand Up @@ -44,30 +48,78 @@ var getProjectCmd = &cobra.Command{
Use: "project",
Aliases: []string{"p"},
Short: "Get details about a project",
Run: func(cmd *cobra.Command, args []string) {
getProjectFlags := parseGetFlags(*cmd.Flags())
if getProjectFlags.Project == "" {
PreRunE: func(_ *cobra.Command, _ []string) error {
return validateTokenE(lagoonCLIConfig.Current)
},
RunE: func(cmd *cobra.Command, args []string) error {
debug, err := cmd.Flags().GetBool("debug")
if err != nil {
return err
}
if cmdProjectName == "" {
fmt.Println("Missing arguments: Project name is not defined")
cmd.Help()
os.Exit(1)
return nil
}
returnedJSON, err := pClient.GetProjectInfo(getProjectFlags.Project)
current := lagoonCLIConfig.Current
token := lagoonCLIConfig.Lagoons[current].Token
lc := lclient.New(
lagoonCLIConfig.Lagoons[current].GraphQL,
lagoonCLIVersion,
&token,
debug)

project, err := l.GetProjectByName(context.TODO(), cmdProjectName, lc)
if err != nil {
output.RenderError(err.Error(), outputOptions)
os.Exit(1)
return err
}
var dataMain output.Table
err = json.Unmarshal([]byte(returnedJSON), &dataMain)
if err != nil {
output.RenderError(err.Error(), outputOptions)
os.Exit(1)

if project == nil {
output.RenderInfo(fmt.Sprintf("No details for project '%s'", cmdProjectName), outputOptions)
return nil
}
if len(dataMain.Data) == 0 {
output.RenderInfo(fmt.Sprintf("No details for project '%s'", getProjectFlags.Project), outputOptions)
os.Exit(0)

DevEnvironments := 0
productionRoute := "none"
deploymentsDisabled, err := strconv.ParseBool(strconv.Itoa(int(project.DeploymentsDisabled)))
handleError(err)
autoIdle, err := strconv.ParseBool(strconv.Itoa(int(project.AutoIdle)))
handleError(err)
factsUI, err := strconv.ParseBool(strconv.Itoa(int(project.FactsUI)))
handleError(err)
problemsUI, err := strconv.ParseBool(strconv.Itoa(int(project.ProblemsUI)))
handleError(err)
for _, environment := range project.Environments {
if environment.EnvironmentType == "development" {
DevEnvironments++
}
if environment.EnvironmentType == "production" {
productionRoute = environment.Route
}
}
output.RenderOutput(dataMain, outputOptions)

data := []output.Data{}
data = append(data, []string{
returnNonEmptyString(fmt.Sprintf("%d", project.ID)),
returnNonEmptyString(fmt.Sprintf("%v", project.Name)),
returnNonEmptyString(fmt.Sprintf("%v", project.GitURL)),
returnNonEmptyString(fmt.Sprintf("%v", project.Branches)),
returnNonEmptyString(fmt.Sprintf("%v", project.PullRequests)),
returnNonEmptyString(fmt.Sprintf("%v", productionRoute)),
returnNonEmptyString(fmt.Sprintf("%v/%v", DevEnvironments, project.DevelopmentEnvironmentsLimit)),
returnNonEmptyString(fmt.Sprintf("%v", project.DevelopmentEnvironmentsLimit)),
returnNonEmptyString(fmt.Sprintf("%v", project.ProductionEnvironment)),
returnNonEmptyString(fmt.Sprintf("%v", project.RouterPattern)),
returnNonEmptyString(fmt.Sprintf("%v", autoIdle)),
returnNonEmptyString(fmt.Sprintf("%v", factsUI)),
returnNonEmptyString(fmt.Sprintf("%v", problemsUI)),
returnNonEmptyString(fmt.Sprintf("%v", deploymentsDisabled)),
})
dataMain := output.Table{
Header: []string{"ID", "ProjectName", "GitURL", "Branches", "PullRequests", "ProductionRoute", "DevEnvironments", "DevEnvLimit", "ProductionEnv", "RouterPattern", "AutoIdle", "FactsUI", "ProblemsUI", "DeploymentsDisabled"},
Data: data,
}
output.RenderOutput(dataMain, outputOptions)
return nil
},
}

Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ require (
github.com/guregu/null v4.0.0+incompatible
// workaround for https://github.com/manifoldco/promptui/issues/98
github.com/nicksnyder/go-i18n v1.10.1 // indirect
github.com/uselagoon/machinery v0.0.11
github.com/uselagoon/machinery v0.0.13
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3 // indirect
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad // indirect
gopkg.in/alecthomas/kingpin.v3-unstable v3.0.0-20191105091915-95d230a53780 // indirect
Expand All @@ -39,6 +39,6 @@ require (
// use this version for fixes to formatting of end header
replace github.com/olekukonko/tablewriter => github.com/shreddedbacon/tablewriter v0.0.2-0.20200114082015-d810c4a558bf

// replace github.com/machinebox/graphql => ../../shreddedbacon/graphql
//replace github.com/uselagoon/machinery => ../machinery

// replace github.com/olekukonko/tablewriter => ../../shreddedbacon/tablewriter
// replace github.com/olekukonko/tablewriter => ../../shreddedbacon/tablewriter
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZm
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/go-bindata/go-bindata v3.1.2+incompatible h1:5vjJMVhowQdPzjE1LdxyFF7YFTXg5IgGVW4gBr5IbvE=
github.com/go-bindata/go-bindata v3.1.2+incompatible/go.mod h1:xK8Dsgwmeed+BBsSy2XTopBn/8uK2HWuGSnA11C3Joo=
github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
github.com/golang/lint v0.0.0-20181026193005-c67002cb31c3 h1:I4BOK3PBMjhWfQM2zPJKK7lOBGsrsvOB7kBELP33hiE=
github.com/golang/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:tluoj9z5200jBnyusfRPU2LqT6J+DAorxEvtC7LHB+E=
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
Expand Down Expand Up @@ -107,6 +108,11 @@ github.com/tsenart/deadcode v0.0.0-20160724212837-210d2dc333e9/go.mod h1:q+QjxYv
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
github.com/uselagoon/machinery v0.0.11 h1:s6EhyU/pj1+C4FdS0EqmR6C0dLsoeCd9n+5xHL1YDag=
github.com/uselagoon/machinery v0.0.11/go.mod h1:IXLxlkahEAEgpCmu9Xa/Wmjo6ja4Aoq7tf8G7VrileE=
github.com/uselagoon/machinery v0.0.12/go.mod h1:h/qeMWQR4Qqu33x+8AulNDeolEwvb/G+aIsn/jyUtwk=
github.com/uselagoon/machinery v0.0.13-0.20231026060810-4d4dad35f450 h1:0logAfG1vfMm9fYkQ6vJGXPGxJ0FfB0V3IYYEi+lI7I=
github.com/uselagoon/machinery v0.0.13-0.20231026060810-4d4dad35f450/go.mod h1:h/qeMWQR4Qqu33x+8AulNDeolEwvb/G+aIsn/jyUtwk=
github.com/uselagoon/machinery v0.0.13 h1:ZCLBNWJmDr3wikaHs3pWhQ1j8MprhIqRuChgSqmLyZc=
github.com/uselagoon/machinery v0.0.13/go.mod h1:h/qeMWQR4Qqu33x+8AulNDeolEwvb/G+aIsn/jyUtwk=
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
Expand Down
Loading