From a229763ef1d338c5ab1615d8fc0f970ed1f01225 Mon Sep 17 00:00:00 2001 From: "ashish.alex10@gmail.com" Date: Mon, 24 Jun 2024 20:20:15 +0100 Subject: [PATCH] fix: migrate to use file as argument instead of table --- README.md | 23 ++++++++++++++--------- cmd/table_ops/table_ops.go | 12 +++++------- justfile | 2 +- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index e233f3c..b93a7f9 100644 --- a/README.md +++ b/README.md @@ -34,21 +34,22 @@ Cost of of running all tables in Dataform project ```bash dj --json-file table-ops cost --all ``` -OR (using stdin as input ) +**OR** (using stdin as input ) ```bash dataform compile --json | dj table-ops cost --all -` +``` + +Cost of of running a file -Cost of of running a table ```bash -dj --json-file table-ops cost --table +dj --json-file table-ops cost --file ``` -Compiled query for a table +Compiled query for a file ```bash -dj --json-file table-ops query --table +dj --json-file table-ops query --file ``` List unique tags in Dataform project @@ -73,13 +74,17 @@ curl -sSfL https://raw.githubusercontent.com/ashish10alex/dj/main/install_latest ```bash go install github.com/ashish10alex/dj@latest ``` -This instals the binary `dj` to $GOBIN, which defaults to $GOPATH/bin. +This installs the binary `dj` to $GOBIN, which defaults to $GOPATH/bin. -Or you can manually clone the repository and build the cli and add the cli to your system path +**OR** + +Manually clone the repository and build the cli and add the cli to your system path ```bash git clone -just build # this assumes that you have a ~/bin directory which is in your PATH and just cli is installed +go build -o dj +mv dj /usr/local/bin/dj + ``` ### [To BigQuery](#to-bigquery) diff --git a/cmd/table_ops/table_ops.go b/cmd/table_ops/table_ops.go index 900e224..9885498 100644 --- a/cmd/table_ops/table_ops.go +++ b/cmd/table_ops/table_ops.go @@ -61,10 +61,8 @@ var tableOpsCostCmd = &cobra.Command{ projectId := jsonData.GetTargetGcpProjectId() jsonData.GetDryRunForAllTables(projectId, keyFile, location, includeAssertions, compact) - } else if cmd.Flag("table").Value.String() != "" { - // NOTE: Neovim front end is passing the file name not the table name. - // Which is why we have the logic to infer the table name from file name - fileName := cmd.Flag("table").Value.String() + } else if cmd.Flag("file").Value.String() != "" { + fileName := cmd.Flag("file").Value.String() jsonData, err := readJson(jsonFile) if err != nil { log.Fatal("Error parsing json: ", err.Error()) @@ -100,10 +98,10 @@ var tableOpsCostCmd = &cobra.Command{ func init() { cmd.RootCmd.AddCommand(tableopsCmd) - tableOpsCostCmd.Flags().BoolP("all", "a", false, "Get cost for all tables") - tableOpsCostCmd.Flags().BoolP("compact", "c", true, "compact af") + tableOpsCostCmd.Flags().BoolP("all", "a", false, "Cost for all tables") + tableOpsCostCmd.Flags().BoolP("compact", "c", true, "Compact JSON response. Excludes compiled query") tableOpsCostCmd.Flags().BoolP("include-assertions", "i", false, "Include assertions in the cost") - tableOpsCostCmd.Flags().StringP("table", "t", "", "Get cost for a specific table") + tableOpsCostCmd.Flags().StringP("file", "f", "", "Get cost for a specific file, file name should be passed without the extension") tableopsCmd.Flags().BoolP("list-tables", "u", false, "List all tables in the project") tableopsCmd.AddCommand(tableOpsCostCmd) } diff --git a/justfile b/justfile index b62aab9..c45774d 100644 --- a/justfile +++ b/justfile @@ -17,7 +17,7 @@ test_tag_ops: go run . --json-file test/op.json tag-ops cost --all test_single_table_ops_cost: - go run . --json-file test/dpr.json table-ops cost --table=table_name + go run . --json-file test/dpr.json table-ops cost --file=0400_WIP_HISTORY debug: dlv debug -- -j test/dpr.json tag-ops -u