Skip to content
Merged
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
6 changes: 3 additions & 3 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ The CLI operates as a wrapper around a legacy PHP CLI:
- The `csv`, `tsv` and `plain` formats match the legacy output, with ANSI escape sequences removed
- The `table` format wraps cells to the terminal width (a port of the legacy `AdaptiveTable`), and supports ANSI-styled cells

**Project Initialization**: `internal/init/`
- AI-powered project configuration generation
- Integrates with whatsun library for codebase analysis
**Project Initialization**: `internal/init/` and `internal/platformify/`
- `init` generates a starter configuration with AI (`internal/init`, using the whatsun library for codebase analysis), or with a guided wizard (`internal/platformify`, formerly the Platformify project), which also supports Fixed configuration
- The wizard detects the stack, asks a few questions, and renders `internal/platformify/templates` (`flex` or `fixed`, by `project_config_flavor`). Runtime and service versions come from `pkg/registry`, and tests check the output with `pkg/lint`

### Build System

Expand Down
5 changes: 2 additions & 3 deletions commands/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"strings"
"testing"

"github.com/platformsh/platformify/vendorization"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand All @@ -26,7 +25,7 @@ func TestAuthCommands_Disabled(t *testing.T) {

func TestAuthCommands_LegacyGlobalFlags(t *testing.T) {
t.Setenv("TEST_GO_AUTH", "1")
root := newRootCommand(testConfig(), &vendorization.VendorAssets{})
root := newRootCommand(testConfig())
for _, args := range [][]string{
{"logout", "-n"},
{"auth:token", "-W", "--no-ansi"},
Expand All @@ -41,7 +40,7 @@ func TestAuthCommands_LegacyGlobalFlags(t *testing.T) {
func TestAuthCommands_GoAuthDisabled(t *testing.T) {
t.Setenv("TEST_GO_AUTH", "")
assert.Empty(t, authCommands(testConfig()))
root := newRootCommand(testConfig(), &vendorization.VendorAssets{})
root := newRootCommand(testConfig())
c, _, err := root.Find([]string{"auth:internal"})
require.NoError(t, err)
assert.Equal(t, root, c, "auth:internal must not be registered")
Expand Down
3 changes: 1 addition & 2 deletions commands/completion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"strings"
"testing"

"github.com/platformsh/platformify/vendorization"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -77,7 +76,7 @@ func TestCompleteCommandPassesArgsThrough(t *testing.T) {
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
cnf := testConfig()
root := newRootCommand(cnf, &vendorization.VendorAssets{Binary: cnf.Application.Executable})
root := newRootCommand(cnf)
root.SetOut(io.Discard)
root.SetErr(io.Discard)

Expand Down
16 changes: 8 additions & 8 deletions commands/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ import (
"github.com/AlecAivazis/survey/v2"
"github.com/AlecAivazis/survey/v2/terminal"
"github.com/fatih/color"
"github.com/platformsh/platformify/commands"
"github.com/platformsh/platformify/vendorization"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/upsun/whatsun/pkg/digest"
"github.com/upsun/whatsun/pkg/files"
"gopkg.in/yaml.v3"

"github.com/upsun/cli/internal/platformify"

"github.com/upsun/cli/internal/legacy"

"github.com/upsun/cli/internal/api"
Expand All @@ -30,7 +30,7 @@ import (
_init "github.com/upsun/cli/internal/init"
)

func newInitCommand(cnf *config.Config, assets *vendorization.VendorAssets) *cobra.Command {
func newInitCommand(cnf *config.Config) *cobra.Command {
var (
useAI bool
initOptions = &_init.Options{}
Expand All @@ -48,7 +48,7 @@ func newInitCommand(cnf *config.Config, assets *vendorization.VendorAssets) *cob
" " + cnf.Application.Executable + " init --ai --context='Use PostgreSQL for the database'",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
return runInitCommand(cmd, args, useAI, initOptions, assets)
return runInitCommand(cmd, args, useAI, initOptions)
},
}

Expand Down Expand Up @@ -81,7 +81,7 @@ func initCommandHelp(cnf *config.Config, short bool) string {

// runInitCommand handles the main logic for the init command.
func runInitCommand(
cmd *cobra.Command, args []string, useAI bool, initOptions *_init.Options, assets *vendorization.VendorAssets,
cmd *cobra.Command, args []string, useAI bool, initOptions *_init.Options,
) error {
var path = "."
if len(args) > 0 {
Expand All @@ -104,12 +104,12 @@ func runInitCommand(
return yaml.NewEncoder(cmd.OutOrStdout()).Encode(dg)
}

cnf := config.FromContext(cmd.Context())

runNonAIConfig := func() error {
return commands.Platformify(cmd.Context(), cmd.OutOrStdout(), cmd.ErrOrStderr(), assets)
return platformify.Run(cnf, platformify.Options{Dir: gitRoot, Stdout: cmd.OutOrStdout(), Stderr: cmd.ErrOrStderr()})
}

cnf := config.FromContext(cmd.Context())

ia, err := newInitAuth(cmd, cnf)
if err != nil {
return err
Expand Down
3 changes: 1 addition & 2 deletions commands/lint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"testing"

"github.com/fatih/color"
"github.com/platformsh/platformify/vendorization"
"github.com/spf13/cobra"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -207,7 +206,7 @@ func TestLintCommand_Registration(t *testing.T) {
cnf := testConfig()
cnf.Service.ProjectConfigDir = c.configDir
cnf.Service.AppConfigFile = c.appFile
root := newRootCommand(cnf, &vendorization.VendorAssets{})
root := newRootCommand(cnf)
cmd, _, err := root.Find([]string{"lint"})
require.NoError(t, err)
assert.Equal(t, c.want, cmd != root)
Expand Down
2 changes: 1 addition & 1 deletion commands/list_models_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestHelpPageExamples(t *testing.T) {
},
{
name: "init",
cmd: commandFromCobra(cnf, newInitCommand(cnf, nil)),
cmd: commandFromCobra(cnf, newInitCommand(cnf)),
expected: `Examples:
Create the starter YAML file(s) for your project:
upsun init
Expand Down
18 changes: 4 additions & 14 deletions commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"time"

"github.com/fatih/color"
"github.com/platformsh/platformify/vendorization"
"github.com/spf13/cobra"
"github.com/spf13/viper"

Expand All @@ -26,17 +25,8 @@ import (

// Execute is the main entrypoint to run the CLI.
func Execute(cnf *config.Config) error {
assets := &vendorization.VendorAssets{
Use: "project:init",
Binary: cnf.Application.Executable,
ConfigFlavor: cnf.Service.ProjectConfigFlavor,
EnvPrefix: strings.TrimSuffix(cnf.Service.EnvPrefix, "_"),
ServiceName: cnf.Service.Name,
DocsBaseURL: cnf.Service.DocsURL,
}

ctx := vendorization.WithVendorAssets(config.ToContext(context.Background(), cnf), assets)
cmd := newRootCommand(cnf, assets)
ctx := config.ToContext(context.Background(), cnf)
cmd := newRootCommand(cnf)
if args, ok, err := expandAbbreviation(cmd, enabledLegacyCommands(cnf, legacy.Commands), os.Args[1:]); err != nil {
debugLogf("Failed to load the legacy command index: %s", err)
} else if ok {
Expand Down Expand Up @@ -71,7 +61,7 @@ func waitForUpdateCheck() {
updateCheck.Wait(updateCheckWait)
}

func newRootCommand(cnf *config.Config, assets *vendorization.VendorAssets) *cobra.Command {
func newRootCommand(cnf *config.Config) *cobra.Command {
versionCommand := newVersionCommand(cnf)
cmd := &cobra.Command{
Use: cnf.Application.Executable,
Expand Down Expand Up @@ -182,7 +172,7 @@ func newRootCommand(cnf *config.Config, assets *vendorization.VendorAssets) *cob
newConfigInstallCommand(),
newCompletionCommand(cnf),
newHelpCommand(cnf),
useLegacyStyleHelp(cnf, newInitCommand(cnf, assets)),
useLegacyStyleHelp(cnf, newInitCommand(cnf)),
newListCommand(cnf),
versionCommand,
)
Expand Down
7 changes: 3 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.27.1
require (
github.com/AlecAivazis/survey/v2 v2.3.7
github.com/Masterminds/semver/v3 v3.5.0
github.com/Masterminds/sprig/v3 v3.3.0
github.com/alecthomas/chroma/v2 v2.27.0
github.com/briandowns/spinner v1.23.2
github.com/charmbracelet/x/ansi v0.11.9
Expand All @@ -14,9 +15,10 @@ require (
github.com/go-playground/validator/v10 v10.30.5
github.com/godbus/dbus/v5 v5.2.3
github.com/gofrs/flock v0.13.1
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d
github.com/oklog/ulid/v2 v2.1.2
github.com/pelletier/go-toml/v2 v2.3.0
github.com/pkg/sftp v1.13.11
github.com/platformsh/platformify v0.5.0
github.com/spf13/cobra v1.10.2
github.com/spf13/pflag v1.0.10
github.com/spf13/viper v1.21.0
Expand All @@ -42,7 +44,6 @@ require (
github.com/BurntSushi/toml v1.6.0 // indirect
github.com/IGLOU-EU/go-wildcard/v2 v2.1.1 // indirect
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/sprig/v3 v3.3.0 // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/ProtonMail/go-crypto v1.4.1 // indirect
github.com/STARRY-S/zip v0.2.3 // indirect
Expand Down Expand Up @@ -95,15 +96,13 @@ require (
github.com/mattn/go-colorable v0.1.14 // indirect
github.com/mattn/go-isatty v0.0.22 // indirect
github.com/mattn/go-runewidth v0.0.27 // indirect
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
github.com/mholt/archives v0.1.5 // indirect
github.com/mikelolasagasti/xz v1.0.1 // indirect
github.com/minio/minlz v1.1.1 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/muesli/termenv v0.16.0 // indirect
github.com/nwaples/rardecode/v2 v2.2.2 // indirect
github.com/pelletier/go-toml/v2 v2.3.0 // indirect
github.com/pierrec/lz4/v4 v4.1.26 // indirect
github.com/pjbgf/sha1cd v0.7.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,6 @@ github.com/gofrs/flock v0.13.1 h1:jjREztyBeSKBZYAC+mgc1laB+xsgy4kYMf3FbKF2UBo=
github.com/gofrs/flock v0.13.1/go.mod h1:sf4BFiHwnvgxa25DlQoDqXQnwRMEOwqxRq37P6MzzmE=
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 h1:f+oWsMOmNPc8JmEHVZIycC7hBoQxHH9pNKQORJNozsQ=
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8/go.mod h1:wcDNUvekVysuuOpQKo3191zZyTpiI6se1N1ULghS0sw=
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
github.com/google/cel-go v0.31.0 h1:H0bhpFTqOvmHrBGrWKp7ZlhBm5Hh8PYUEXnwxT1LL7A=
github.com/google/cel-go v0.31.0/go.mod h1:X0bD6iVNR8pkROSOoHVdgTkzmRcosof7WQqCD6wcMc8=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
Expand Down Expand Up @@ -224,8 +222,6 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/sftp v1.13.11 h1:0N92SLTB8JqASJB14ZLHHzFnBV8mG9zw4K7jghEFWuE=
github.com/pkg/sftp v1.13.11/go.mod h1:uNkH9roSXglNJqM+glJJi+TQXQUm0fXFWqCFmT8hsN0=
github.com/platformsh/platformify v0.5.0 h1:i9cRbM0K1f14Yr0dJ6dhYq9BcmZb8fsx/mpYSnw8ssA=
github.com/platformsh/platformify v0.5.0/go.mod h1:fgmCcfQfHbhe1oXsIdIhpnniyZu8IdIMOlcBAa/ygic=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
Expand Down
35 changes: 35 additions & 0 deletions internal/platformify/colors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package platformify

import (
"os"

"github.com/AlecAivazis/survey/v2/core"
"github.com/mgutz/ansi"
)

// Colors, as names for survey templates and as ANSI codes.
var (
colorBrand = "210"
colorAccent = "33"
colorSecondary = "247"
colorError = "red"
colorDefault = "default"

brandCode = ansi.ColorCode(colorBrand)
accentCode = ansi.ColorCode(colorAccent)
greenCode = ansi.ColorCode("green")
warningCode = ansi.ColorCode("yellow")
resetCode = ansi.ColorCode("reset")
)

func init() {
if v := os.Getenv("NO_COLOR"); v != "" && v != "0" {
brandCode, accentCode, greenCode, warningCode, resetCode = "", "", "", "", ""
core.DisableColor = true
}
}

// colorize wraps s in the given ANSI color code.
func colorize(code, s string) string {
return code + s + resetCode
}
Loading
Loading