github.com/replicatedcom/ship@v0.50.0/pkg/cli/watch.go (about)

     1  package cli
     2  
     3  import (
     4  	"context"
     5  	"time"
     6  
     7  	"github.com/replicatedhq/ship/pkg/ship"
     8  	"github.com/spf13/cobra"
     9  	"github.com/spf13/viper"
    10  )
    11  
    12  func Watch() *cobra.Command {
    13  	v := viper.GetViper()
    14  	cmd := &cobra.Command{
    15  		Use:   "watch",
    16  		Short: "Watch an upstream for updates",
    17  		Long: `Watch will poll the upstream source for changes, and block until a
    18  change has been published. The watch command will return with an exit code
    19  of 0 when there's an update available.`,
    20  		PreRun: func(cmd *cobra.Command, args []string) {
    21  			viper.BindPFlags(cmd.Flags())
    22  			viper.BindPFlags(cmd.PersistentFlags())
    23  		},
    24  		RunE: func(cmd *cobra.Command, args []string) error {
    25  			s, err := ship.Get(v)
    26  			if err != nil {
    27  				return err
    28  			}
    29  
    30  			return s.WatchAndExit(context.Background())
    31  		},
    32  	}
    33  
    34  	cmd.Flags().DurationP("interval", "", time.Duration(time.Minute*15), "interval to wait between cycles polling for updates")
    35  	cmd.Flags().BoolP("exit", "", false, "exit immediately after first poll, regardless of whether an update is available")
    36  
    37  	return cmd
    38  }