Skip to content

Commit

Permalink
Topology cmd option cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Lord <mattalord@gmail.com>
  • Loading branch information
mattlord committed Jan 1, 2025
1 parent 6021859 commit d1be3df
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions go/cmd/vtctldclient/command/topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ var (
Args: cobra.ExactArgs(1),
RunE: commandGetTopologyPath,
}
// The version of the key/path to get. If not specified, the latest/current
// version is returned.
version int64 = 0
// If true, only the data is output and it is in JSON format rather than prototext.
dataAsJSON bool = false

// WriteTopologyPath writes the contents of a local file to a path
// in the topology server.
Expand All @@ -60,25 +55,34 @@ var (
},
RunE: commandWriteTopologyPath,
}
// The cell to use for the copy. Defaults to the global cell.
cell string
)

var getTopologyPathOptions = struct {
// The version of the key/path to get. If not specified, the latest/current
// version is returned.
version int64
// If true, only the data is output and it is in JSON format rather than prototext.
dataAsJSON bool
}{
version: 0,
dataAsJSON: false,
}

func commandGetTopologyPath(cmd *cobra.Command, args []string) error {
path := cmd.Flags().Arg(0)

cli.FinishedParsing(cmd)

resp, err := client.GetTopologyPath(commandCtx, &vtctldatapb.GetTopologyPathRequest{
Path: path,
Version: version,
AsJson: dataAsJSON,
Version: getTopologyPathOptions.version,
AsJson: getTopologyPathOptions.dataAsJSON,
})
if err != nil {
return err
}

if dataAsJSON {
if getTopologyPathOptions.dataAsJSON {
if resp.GetCell() == nil || resp.GetCell().GetData() == "" {
return fmt.Errorf("no data found for path %s", path)
}
Expand All @@ -96,6 +100,11 @@ func commandGetTopologyPath(cmd *cobra.Command, args []string) error {
return nil
}

var writeTopologyPathOptions = struct {
// The cell to use for the copy. Defaults to the global cell.
cell string
}{}

func commandWriteTopologyPath(cmd *cobra.Command, args []string) error {
path := cmd.Flags().Arg(0)
file := cmd.Flags().Arg(1)
Expand All @@ -105,7 +114,7 @@ func commandWriteTopologyPath(cmd *cobra.Command, args []string) error {
}
cli.FinishedParsing(cmd)

conn, err := ts.ConnForCell(cmd.Context(), cell)
conn, err := ts.ConnForCell(cmd.Context(), writeTopologyPathOptions.cell)
if err != nil {
return fmt.Errorf("failed to connect to the topology server: %v", err)
}
Expand All @@ -122,10 +131,10 @@ func commandWriteTopologyPath(cmd *cobra.Command, args []string) error {
}

func init() {
GetTopologyPath.Flags().Int64Var(&version, "version", version, "The version of the path's key to get. If not specified, the latest version is returned.")
GetTopologyPath.Flags().BoolVar(&dataAsJSON, "data-as-json", dataAsJSON, "If true, only the data is output and it is in JSON format rather than prototext.")
GetTopologyPath.Flags().Int64Var(&getTopologyPathOptions.version, "version", getTopologyPathOptions.version, "The version of the path's key to get. If not specified, the latest version is returned.")
GetTopologyPath.Flags().BoolVar(&getTopologyPathOptions.dataAsJSON, "data-as-json", getTopologyPathOptions.dataAsJSON, "If true, only the data is output and it is in JSON format rather than prototext.")
Root.AddCommand(GetTopologyPath)

WriteTopologyPath.Flags().StringVar(&cell, "cell", topo.GlobalCell, "Topology server cell to copy the file to.")
WriteTopologyPath.Flags().StringVar(&writeTopologyPathOptions.cell, "cell", topo.GlobalCell, "Topology server cell to copy the file to.")
Root.AddCommand(WriteTopologyPath)
}

0 comments on commit d1be3df

Please sign in to comment.