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

Vendorize ify command and expose the validate/app:config-validate command #114

Merged
merged 1 commit into from
Sep 20, 2023
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
26 changes: 0 additions & 26 deletions commands/project_init.go

This file was deleted.

26 changes: 22 additions & 4 deletions commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"strings"

"github.com/fatih/color"
"github.com/platformsh/platformify/commands"
"github.com/platformsh/platformify/vendorization"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"golang.org/x/exp/slices"
Expand All @@ -23,11 +25,20 @@ import (

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

ctx := vendorization.WithVendorAssets(config.ToContext(context.Background(), cnf), assets)
return newRootCommand(cnf, assets).ExecuteContext(ctx)
}

func newRootCommand(cnf *config.Config) *cobra.Command {
func newRootCommand(cnf *config.Config, assets *vendorization.VendorAssets) *cobra.Command {
var (
updateMessageChan = make(chan *internal.ReleaseInfo, 1)
versionCommand = newVersionCommand(cnf)
Expand All @@ -38,6 +49,8 @@ func newRootCommand(cnf *config.Config) *cobra.Command {
Args: cobra.ArbitraryArgs,
DisableFlagParsing: false,
FParseErrWhitelist: cobra.FParseErrWhitelist{UnknownFlags: true},
SilenceUsage: true,
SilenceErrors: true,
PersistentPreRun: func(cmd *cobra.Command, args []string) {
if viper.GetBool("version") {
versionCommand.Run(cmd, []string{})
Expand Down Expand Up @@ -104,12 +117,17 @@ func newRootCommand(cnf *config.Config) *cobra.Command {
)
cmd.PersistentFlags().Bool("debug", false, "Enable debug logging")

validateCmd := commands.NewValidateCommand(assets)
validateCmd.Use = "app:config-validate"
validateCmd.Aliases = []string{"validate"}

// Add subcommands.
cmd.AddCommand(
newCompletionCommand(cnf),
newHelpCommand(cnf),
newListCommand(cnf),
newProjectInitCommand(cnf),
commands.NewPlatformifyCmd(assets),
validateCmd,
versionCommand,
)

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/go-playground/validator/v10 v10.14.1
github.com/gofrs/flock v0.8.1
github.com/mattn/go-isatty v0.0.16
github.com/platformsh/platformify v0.1.2
github.com/platformsh/platformify v0.2.1
github.com/spf13/cobra v1.6.1
github.com/spf13/viper v1.15.0
github.com/stretchr/testify v1.8.4
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ github.com/pelletier/go-toml/v2 v2.0.6 h1:nrzqCb7j9cDFj2coyLNLaZuJTLjWjlaz6nvTvI
github.com/pelletier/go-toml/v2 v2.0.6/go.mod h1:eumQOmlWiOPt5WriQQqoM5y18pDHwha2N+QD+EUNTek=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg=
github.com/platformsh/platformify v0.1.2 h1:7fSGL3v/YrTvEeMSaped55vyiTtq5sKxq8P0YMKXLVM=
github.com/platformsh/platformify v0.1.2/go.mod h1:OTcTo+D6DJXQswy7D2yfzgx4v3wUai3fU5BGAXr2FjI=
github.com/platformsh/platformify v0.2.1 h1:pSxJUGZbtd76HFRNqX7Hy+kyM+wH21E2EWHhnQYpPQw=
github.com/platformsh/platformify v0.2.1/go.mod h1:OTcTo+D6DJXQswy7D2yfzgx4v3wUai3fU5BGAXr2FjI=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
Expand Down
1 change: 1 addition & 0 deletions internal/config/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,6 @@ type Config struct {
EnvPrefix string `validate:"required" yaml:"env_prefix"` // e.g. "PLATFORM_"
ProjectConfigDir string `validate:"required" yaml:"project_config_dir"` // e.g. ".platform"
ConsoleURL string `validate:"omitempty,url" yaml:"console_url"` // e.g. "https://console.platform.sh"
DocsURL string `validate:"omitempty,url" yaml:"docs_url"` // e.g. "https://docs.platform.sh"
} `validate:"required,dive"`
}
2 changes: 2 additions & 0 deletions internal/config/test-data/valid-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ service:

console_url: 'https://console.example.com'

docs_url: 'https://docs.example.com'

api:
base_url: 'https://api.example.com'
auth_url: 'https://auth.example.com'
Expand Down