github.com/actions-on-google/gactions@v3.2.0+incompatible/cmd/gactions/cli/push/push.go (about)

     1  // Copyright 2020 Google LLC
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     https://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  // Package push provides an implementation of "gactions push" command.
    16  package push
    17  
    18  import (
    19  	"context"
    20  	"errors"
    21  	"fmt"
    22  
    23  	"github.com/actions-on-google/gactions/api/sdk"
    24  	"github.com/actions-on-google/gactions/log"
    25  	"github.com/actions-on-google/gactions/project"
    26  	"github.com/actions-on-google/gactions/project/studio"
    27  	"github.com/spf13/cobra"
    28  )
    29  
    30  // AddCommand adds the push sub-command to the passed in root command.
    31  func AddCommand(ctx context.Context, root *cobra.Command, proj project.Project) {
    32  	push := &cobra.Command{
    33  		Use:   "push",
    34  		Short: "This command pushes changes in the local files to Actions Console.",
    35  		Long:  "This command pushes changes in the local files to Actions Console.",
    36  		RunE: func(cmd *cobra.Command, args []string) error {
    37  			if proj.ProjectRoot() == "" {
    38  				log.Errorf(`Can't find a project root. This may be because (1) %q was not found in this or any of the parent folders, or (2) if %q was found, but the key "sdkPath" was missing, or (3) if %q and manifest.yaml were both not found.`, project.ConfigName, project.ConfigName, project.ConfigName)
    39  				return errors.New("can not determine project root")
    40  			}
    41  			studioProj, ok := proj.(studio.Studio)
    42  			if !ok {
    43  				return fmt.Errorf("can not convert %T to %T", proj, studio.Studio{})
    44  			}
    45  			if err := (&studioProj).SetProjectID(""); err != nil {
    46  				return err
    47  			}
    48  			return doPush(ctx, cmd, args, studioProj)
    49  		},
    50  		Args: cobra.NoArgs,
    51  	}
    52  	root.AddCommand(push)
    53  }
    54  
    55  var doPush = func(ctx context.Context, cmd *cobra.Command, args []string, proj project.Project) error {
    56  	return sdk.WriteDraftJSON(ctx, proj)
    57  }