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
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func NewRootCommand(ctx *pkg.AppContext) *cobra.Command {
rootCmd.AddCommand(NewPublishGatewayCmd(ctx))
rootCmd.AddCommand(NewPublishCmd(ctx))
rootCmd.AddCommand(NewGetCmd(ctx, nil))
rootCmd.AddCommand(NewApplyCmd(ctx))
rootCmd.AddCommand(NewSyncCmd(ctx))
rootCmd.AddCommand(NewGenerateConfigCmd(ctx))
rootCmd.AddCommand(NewLoginCmd(ctx))
rootCmd.AddCommand(NewNamespaceCmd(ctx))
Expand Down
24 changes: 12 additions & 12 deletions cmd/apply.go → cmd/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ type Skipped struct {
}

// Input struct
type ApplyOptions struct {
type SyncOptions struct {
cwd string
input string
output []interface{}
}

// Takes a dir to locate the input file and returns a slice of each doc contained in the YAML file
func (o *ApplyOptions) Parse() error {
func (o *SyncOptions) Parse() error {
var gatewayService = GatewayService{}

filePath := filepath.Join(o.cwd, o.input)
Expand Down Expand Up @@ -125,17 +125,17 @@ func (p *PublishCounter) Print() string {
return fmt.Sprintf("%d/%d Published, %d Skipped", p.Success, total, p.Skipped)
}

func NewApplyCmd(ctx *pkg.AppContext) *cobra.Command {
opts := &ApplyOptions{
func NewSyncCmd(ctx *pkg.AppContext) *cobra.Command {
opts := &SyncOptions{
cwd: ctx.Cwd,
}
var applyCmd = &cobra.Command{
Use: "apply",
Short: "Apply gateway resources",
Long: "Apply your GatewayService, CredentialIssuer, DraftDataset, and Product resources. Use the `generate-config` command to see examples of these resources.",
var syncCmd = &cobra.Command{
Use: "sync",
Short: "Sync gateway resources",
Long: "Sync your GatewayService, CredentialIssuer, DraftDataset, and Product resources. Use the `generate-config` command to see examples of these resources.",
Args: cobra.OnlyValidArgs,
Example: heredoc.Doc(`
$ gwa apply --input gw-config.yaml
$ gwa sync --input gw-config.yaml
`),
RunE: func(_ *cobra.Command, _ []string) error {
err := opts.Parse()
Expand Down Expand Up @@ -193,10 +193,10 @@ $ gwa apply --input gw-config.yaml
},
}

applyCmd.Flags().StringVarP(&opts.input, "input", "i", "gw-config.yml", "YAML file containing your configuration")
applyCmd.MarkFlagRequired("input")
syncCmd.Flags().StringVarP(&opts.input, "input", "i", "gw-config.yml", "YAML file containing your configuration")
syncCmd.MarkFlagRequired("input")

return applyCmd
return syncCmd
}

type PutResponse struct {
Expand Down
12 changes: 6 additions & 6 deletions cmd/apply_test.go → cmd/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ kind: Product
name: my-service API
`

func TestApplyOptions(t *testing.T) {
func TestSyncOptions(t *testing.T) {
fileName := "gw-config.yaml"
dir := t.TempDir()
config, err := os.Create(filepath.Join(dir, fileName))
Expand All @@ -51,7 +51,7 @@ func TestApplyOptions(t *testing.T) {
if err != nil {
t.Fatal(err)
}
o := &ApplyOptions{
o := &SyncOptions{
cwd: dir,
input: fileName,
}
Expand Down Expand Up @@ -88,7 +88,7 @@ func TestNonYamlFile(t *testing.T) {
if err != nil {
t.Fatal(err)
}
o := &ApplyOptions{
o := &SyncOptions{
cwd: dir,
input: fileName,
}
Expand Down Expand Up @@ -246,7 +246,7 @@ func TestPublishGatewayService(t *testing.T) {
assert.Equal(t, "", res.Results, "returns a successful gateway service resposne like in publish-gateway")
}

func TestApplyStdout(t *testing.T) {
func TestSynSyncStdout(t *testing.T) {
tests := []struct {
name string
responseCode int
Expand Down Expand Up @@ -321,12 +321,12 @@ func TestApplyStdout(t *testing.T) {
filename := "gw-config.yaml"
os.WriteFile(filepath.Join(cwd, filename), []byte(input), 0644)

args := []string{"apply", "--input", filename}
args := []string{"sync", "--input", filename}

mainCmd := &cobra.Command{
Use: "gwa",
}
mainCmd.AddCommand(NewApplyCmd(ctx))
mainCmd.AddCommand(NewSyncCmd(ctx))
mainCmd.SetArgs(args)
out := capturer.CaptureOutput(func() {
mainCmd.Execute()
Expand Down