Skip to content

Commit

Permalink
Add reference command
Browse files Browse the repository at this point in the history
Signed-off-by: Rohit Nayak <[email protected]>
  • Loading branch information
rohit-nayak-ps committed Nov 16, 2024
1 parent 0c8576f commit 997dff3
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 0 deletions.
51 changes: 51 additions & 0 deletions go/cmd/reference.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
Copyright 2024 The Vitess Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package cmd

import (
"github.com/spf13/cobra"
"github.com/vitessio/vt/go/reference"
)

func referenceCmd() *cobra.Command {
var inputType string

cmd := &cobra.Command{
Use: "reference ",
Short: "Suggests potential reference tables based on query logs and database schema",
Example: "vt reference file.test <mysql-connection-string>",
Args: cobra.ExactArgs(2),
RunE: func(_ *cobra.Command, args []string) error {
cfg := reference.Config{
FileName: args[0],
ConnectionString: args[1],
}

loader, err := configureLoader(inputType, false)
if err != nil {
return err
}
cfg.Loader = loader

return reference.Run(cfg)
},
}

addInputTypeFlag(cmd, &inputType)

return cmd
}
1 change: 1 addition & 0 deletions go/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func Execute() {
root.AddCommand(testerCmd())
root.AddCommand(tracerCmd())
root.AddCommand(keysCmd())
root.AddCommand(referenceCmd())

err := root.Execute()
if err != nil {
Expand Down
41 changes: 41 additions & 0 deletions go/reference/reference.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
Copyright 2024 The Vitess Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package reference

import (
"github.com/vitessio/vt/go/data"
"io"
"os"
)

type Config struct {
FileName string
ConnectionString string

Loader data.Loader
}

func Run(cfg Config) error {
return run(os.Stdout, cfg)
}

func run(out io.Writer, cfg Config) error {
if _, err := out.Write([]byte("Placeholder for reference output\n")); err != nil {
return err
}
return nil
}

0 comments on commit 997dff3

Please sign in to comment.