Skip to content

Commit

Permalink
Refactor command groups (#529)
Browse files Browse the repository at this point in the history
* refactor: command groups

refactor

refactor

* move init

* refactor

* linter

* fix unit tests

* fix goreleaser
  • Loading branch information
zreigz authored Aug 14, 2024
1 parent 7ce540b commit a3b17d6
Show file tree
Hide file tree
Showing 81 changed files with 2,589 additions and 1,995 deletions.
87 changes: 0 additions & 87 deletions .github/workflows/e2e.yaml

This file was deleted.

1 change: 1 addition & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ before:

builds:
- id: plural-cli
main: ./cmd/plural
targets:
- linux_amd64
- linux_arm64
Expand Down
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ COPY go.sum go.sum
RUN go mod download

# Copy the go source
COPY main.go main.go
COPY cmd/ cmd/
COPY pkg/ pkg/

Expand All @@ -30,7 +29,7 @@ RUN CGO_ENABLED=0 GOOS=linux GOARCH=${TARGETARCH} \
-X "github.com/pluralsh/plural-cli/cmd/plural.Version=${APP_VSN}" \
-X "github.com/pluralsh/plural-cli/cmd/plural.Commit=${APP_COMMIT}" \
-X "github.com/pluralsh/plural-cli/cmd/plural.Date=${APP_DATE}"' \
-o plural .
-o plural ./cmd/plural

FROM golang:1.20-alpine3.17

Expand Down
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ git-push:

.PHONY: install
install:
go build -ldflags '$(LDFLAGS)' -o $(GOBIN)/plural .
go build -ldflags '$(LDFLAGS)' -o $(GOBIN)/plural ./cmd/plural

.PHONY: build-cli
build-cli: ## Build a CLI binary for the host architecture without embedded UI
go build -ldflags='$(LDFLAGS)' -o $(OUTFILE) .
go build -ldflags='$(LDFLAGS)' -o $(OUTFILE) ./cmd/plural

.PHONY: build-cli-ui
build-cli-ui: $(PRE) generate-bindings ## Build a CLI binary for the host architecture with embedded UI
CGO_LDFLAGS=$(CGO_LDFLAGS) go build -tags $(WAILS_TAGS) -ldflags='$(LDFLAGS)' -o $(OUTFILE) .
CGO_LDFLAGS=$(CGO_LDFLAGS) go build -tags $(WAILS_TAGS) -ldflags='$(LDFLAGS)' -o $(OUTFILE) ./cmd/plural

.PHONY: build-web
build-web: ## Build just the embedded UI
Expand All @@ -70,7 +70,7 @@ generate-bindings: build-web ## Generate backend bindings for the embedded UI

.PHONY: release
release:
GOOS=$(GOOS) GOARCH=$(GOARCH) go build -ldflags='$(LDFLAGS)' -o $(OUTFILE) .
GOOS=$(GOOS) GOARCH=$(GOARCH) go build -ldflags='$(LDFLAGS)' -o $(OUTFILE) ./cmd/plural

.PHONY: setup
setup: ## sets up your local env (for mac only)
Expand Down Expand Up @@ -159,7 +159,7 @@ setup-tests:

.PHONY: test
test: setup-tests
gotestsum --format testname -- -v -race ./pkg/... ./cmd/...
gotestsum --format testname -- -v -race ./pkg/... ./cmd/command/...

.PHONY: format
format: # formats all go code to prep for linting
Expand Down
20 changes: 19 additions & 1 deletion cmd/plural/help.go → cmd/command/ai/help.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package plural
package ai

import (
"fmt"
"time"

"github.com/pluralsh/plural-cli/pkg/client"

"github.com/briandowns/spinner"
"github.com/fatih/color"
"github.com/pluralsh/plural-cli/pkg/api"
Expand All @@ -13,6 +15,22 @@ import (

const intro = "What can we do to help you with Plural, using open source, or kubernetes?"

type Plural struct {
client.Plural
}

func Command(clients client.Plural) cli.Command {
p := Plural{
Plural: clients,
}
return cli.Command{
Name: "ai",
Usage: "utilize openai to get help with your setup",
Action: p.aiHelp,
Category: "Debugging",
}
}

func (p *Plural) aiHelp(c *cli.Context) error {
p.InitPluralClient()
chat := []*api.ChatMessage{{Role: "system", Content: intro}}
Expand Down
41 changes: 29 additions & 12 deletions cmd/plural/api.go → cmd/command/api/api.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,30 @@
package plural
package api

import (
"github.com/pluralsh/polly/algorithms"
"github.com/urfave/cli"

"github.com/pluralsh/plural-cli/pkg/api"
"github.com/pluralsh/plural-cli/pkg/client"
"github.com/pluralsh/plural-cli/pkg/common"
"github.com/pluralsh/plural-cli/pkg/utils"
"github.com/pluralsh/polly/algorithms"
"github.com/urfave/cli"
)

type Plural struct {
client.Plural
}

func Command(clients client.Plural) cli.Command {
plural := Plural{
Plural: clients,
}
return cli.Command{
Name: "api",
Usage: "inspect the plural api",
Subcommands: plural.apiCommands(),
Category: "API",
}
}

func (p *Plural) apiCommands() []cli.Command {
return []cli.Command{
{
Expand All @@ -18,45 +35,45 @@ func (p *Plural) apiCommands() []cli.Command {
Name: "installations",
Usage: "lists your installations",
ArgsUsage: "",
Action: latestVersion(p.handleInstallations),
Action: common.LatestVersion(p.handleInstallations),
},
{
Name: "charts",
Usage: "lists charts for a repository",
ArgsUsage: "REPO_ID",
Action: latestVersion(requireArgs(p.handleCharts, []string{"REPO_ID"})),
Action: common.LatestVersion(common.RequireArgs(p.handleCharts, []string{"REPO_ID"})),
},
{
Name: "terraform",
Usage: "lists terraform modules for a repository",
ArgsUsage: "REPO_ID",
Action: latestVersion(requireArgs(p.handleTerraforma, []string{"REPO_ID"})),
Action: common.LatestVersion(common.RequireArgs(p.handleTerraforma, []string{"REPO_ID"})),
},
{
Name: "versions",
Usage: "lists versions of a chart",
ArgsUsage: "CHART_ID",
Action: latestVersion(requireArgs(p.handleVersions, []string{"CHART_ID"})),
Action: common.LatestVersion(common.RequireArgs(p.handleVersions, []string{"CHART_ID"})),
},
{
Name: "chartinstallations",
Aliases: []string{"ci"},
Usage: "lists chart installations for a repository",
ArgsUsage: "REPO_ID",
Action: latestVersion(requireArgs(p.handleChartInstallations, []string{"REPO_ID"})),
Action: common.LatestVersion(common.RequireArgs(p.handleChartInstallations, []string{"REPO_ID"})),
},
{
Name: "terraforminstallations",
Aliases: []string{"ti"},
Usage: "lists terraform installations for a repository",
ArgsUsage: "REPO_ID",
Action: latestVersion(requireArgs(p.handleTerraformInstallations, []string{"REPO_ID"})),
Action: common.LatestVersion(common.RequireArgs(p.handleTerraformInstallations, []string{"REPO_ID"})),
},
{
Name: "artifacts",
Usage: "Lists artifacts for a repository",
ArgsUsage: "REPO_ID",
Action: latestVersion(requireArgs(p.handleArtifacts, []string{"REPO_ID"})),
Action: common.LatestVersion(common.RequireArgs(p.handleArtifacts, []string{"REPO_ID"})),
},
},
},
Expand All @@ -68,7 +85,7 @@ func (p *Plural) apiCommands() []cli.Command {
Name: "domain",
Usage: "creates a new domain for your account",
ArgsUsage: "DOMAIN",
Action: latestVersion(p.handleCreateDomain),
Action: common.LatestVersion(p.handleCreateDomain),
},
},
},
Expand Down
Loading

0 comments on commit a3b17d6

Please sign in to comment.