|
| 1 | +// +build !test |
| 2 | + |
| 3 | +package cmd |
| 4 | + |
| 5 | +import ( |
| 6 | + "context" |
| 7 | + "fmt" |
| 8 | + |
| 9 | + "github.com/argoproj-labs/argo-cloudops/cli/internal/api" |
| 10 | + |
| 11 | + "github.com/spf13/cobra" |
| 12 | +) |
| 13 | + |
| 14 | +// syncCmd represents the sync command |
| 15 | +var syncCmd = &cobra.Command{ |
| 16 | + Use: "sync", |
| 17 | + Short: "Syncs a project target using a manifest in git", |
| 18 | + Long: "Syncs a project target using a manifest in git", |
| 19 | + Run: func(cmd *cobra.Command, args []string) { |
| 20 | + token, err := argoCloudOpsUserToken() |
| 21 | + if err != nil { |
| 22 | + cobra.CheckErr(err) |
| 23 | + } |
| 24 | + |
| 25 | + apiCl := api.NewClient(argoCloudOpsServiceAddr(), token) |
| 26 | + |
| 27 | + resp, err := apiCl.Sync(context.Background(), projectName, targetName, gitSHA, gitPath) |
| 28 | + if err != nil { |
| 29 | + cobra.CheckErr(err) |
| 30 | + } |
| 31 | + |
| 32 | + // Our current contract is to output only the name. |
| 33 | + fmt.Print(resp.WorkflowName) |
| 34 | + }, |
| 35 | +} |
| 36 | + |
| 37 | +func init() { |
| 38 | + rootCmd.AddCommand(syncCmd) |
| 39 | + |
| 40 | + // TODO these should be '-' separated. |
| 41 | + syncCmd.Flags().StringVarP(&gitPath, "path", "p", "", "Path to manifest within git repository") |
| 42 | + syncCmd.Flags().StringVarP(&gitSHA, "sha", "s", "", "Commit sha to use when creating workflow through git") |
| 43 | + syncCmd.Flags().StringVarP(&projectName, "project_name", "n", "", "Name of project") |
| 44 | + // TODO inconsistent |
| 45 | + syncCmd.Flags().StringVarP(&targetName, "target", "t", "", "Name of target") |
| 46 | + |
| 47 | + syncCmd.MarkFlagRequired("path") |
| 48 | + syncCmd.MarkFlagRequired("sha") |
| 49 | + syncCmd.MarkFlagRequired("project_name") |
| 50 | + syncCmd.MarkFlagRequired("target_name") |
| 51 | +} |
0 commit comments