vitess.io/vitess@v0.16.2/go/cmd/vtctldclient/command/workflows.go (about)

     1  /*
     2  Copyright 2021 The Vitess Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8  	http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package command
    18  
    19  import (
    20  	"fmt"
    21  
    22  	"github.com/spf13/cobra"
    23  
    24  	"vitess.io/vitess/go/cmd/vtctldclient/cli"
    25  
    26  	vtctldatapb "vitess.io/vitess/go/vt/proto/vtctldata"
    27  )
    28  
    29  var (
    30  	// GetWorkflows makes a GetWorkflows gRPC call to a vtctld.
    31  	GetWorkflows = &cobra.Command{
    32  		Use:                   "GetWorkflows <keyspace>",
    33  		Short:                 "Gets all vreplication workflows (Reshard, MoveTables, etc) in the given keyspace.",
    34  		DisableFlagsInUseLine: true,
    35  		Args:                  cobra.ExactArgs(1),
    36  		RunE:                  commandGetWorkflows,
    37  	}
    38  )
    39  
    40  var getWorkflowsOptions = struct {
    41  	ShowAll bool
    42  }{}
    43  
    44  func commandGetWorkflows(cmd *cobra.Command, args []string) error {
    45  	cli.FinishedParsing(cmd)
    46  
    47  	ks := cmd.Flags().Arg(0)
    48  
    49  	resp, err := client.GetWorkflows(commandCtx, &vtctldatapb.GetWorkflowsRequest{
    50  		Keyspace:   ks,
    51  		ActiveOnly: !getWorkflowsOptions.ShowAll,
    52  	})
    53  
    54  	if err != nil {
    55  		return err
    56  	}
    57  
    58  	data, err := cli.MarshalJSON(resp)
    59  	if err != nil {
    60  		return err
    61  	}
    62  
    63  	fmt.Printf("%s\n", data)
    64  
    65  	return nil
    66  }
    67  
    68  func init() {
    69  	GetWorkflows.Flags().BoolVarP(&getWorkflowsOptions.ShowAll, "show-all", "a", false, "Show all workflows instead of just active workflows.")
    70  	Root.AddCommand(GetWorkflows)
    71  }