Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

split lakectl cmds - part 2 #6272

Merged
merged 3 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ linters:
- gofmt
- goimports
- gomnd
# temporary disable for Fmt until we remove this func
#- goprintffuncname
- goprintffuncname
- gosec
- gosimple
- govet
Expand Down
25 changes: 0 additions & 25 deletions cmd/lakectl/cmd/abuse.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package cmd

import (
"bufio"
"fmt"

"github.com/spf13/cobra"
)

Expand All @@ -18,28 +15,6 @@ var abuseCmd = &cobra.Command{
Hidden: true,
}

func readLines(path string) (lines []string, err error) {
reader := Must(OpenByPath(path))
defer func() {
if closeErr := reader.Close(); closeErr != nil {
if err == nil {
err = closeErr
} else {
err = fmt.Errorf("%w, and while closing %s", err, closeErr)
}
}
}()
scanner := bufio.NewScanner(reader)
lines = make([]string, 0)
for scanner.Scan() {
lines = append(lines, scanner.Text())
}
if err = scanner.Err(); err != nil {
return nil, err
}
return lines, nil
}

//nolint:gochecknoinits
func init() {
rootCmd.AddCommand(abuseCmd)
Expand Down
3 changes: 2 additions & 1 deletion cmd/lakectl/cmd/abuse_commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ var abuseCommitCmd = &cobra.Command{
amount := Must(cmd.Flags().GetInt("amount"))
gapDuration := Must(cmd.Flags().GetDuration("gap"))

fmt.Printf("Source branch: %s\n", u.String())
fmt.Println("Source branch:", u)

generator := stress.NewGenerator("commit", 1, stress.WithSignalHandlersFor(os.Interrupt, syscall.SIGTERM))

// generate randomly selected keys as input
Expand Down
2 changes: 1 addition & 1 deletion cmd/lakectl/cmd/abuse_create_branches.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var abuseCreateBranchesCmd = &cobra.Command{

client := getClient()

fmt.Printf("Source ref: %s\n", u.String())
fmt.Println("Source ref:", u)
deleteGen := stress.NewGenerator("delete branch", parallelism)

const paginationAmount = 1000
Expand Down
4 changes: 2 additions & 2 deletions cmd/lakectl/cmd/abuse_link_same_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ var abuseLinkSameObjectCmd = &cobra.Command{
parallelism := Must(cmd.Flags().GetInt("parallelism"))
key := Must(cmd.Flags().GetString("key"))

fmt.Printf("Source ref: %s\n", u.String())
fmt.Printf("Object key: %s\n", key)
fmt.Println("Source ref:", u)
fmt.Println("Object key:", key)

generator := stress.NewGenerator("get-and-link", parallelism, stress.WithSignalHandlersFor(os.Interrupt, syscall.SIGTERM))

Expand Down
25 changes: 24 additions & 1 deletion cmd/lakectl/cmd/abuse_random_read.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"bufio"
"fmt"
"math/rand"
"net/http"
Expand All @@ -26,7 +27,7 @@ var abuseRandomReadsCmd = &cobra.Command{
parallelism := Must(cmd.Flags().GetInt("parallelism"))
fromFile := Must(cmd.Flags().GetString("from-file"))

fmt.Printf("Source ref: %s\n", u.String())
fmt.Println("Source ref:", u)
// read the input file
keys, err := readLines(fromFile)
if err != nil {
Expand Down Expand Up @@ -66,6 +67,28 @@ var abuseRandomReadsCmd = &cobra.Command{
},
}

func readLines(path string) (lines []string, err error) {
reader := Must(OpenByPath(path))
defer func() {
if closeErr := reader.Close(); closeErr != nil {
if err == nil {
err = closeErr
} else {
err = fmt.Errorf("%w, and while closing %s", err, closeErr)
}
}
}()
scanner := bufio.NewScanner(reader)
lines = make([]string, 0)
for scanner.Scan() {
lines = append(lines, scanner.Text())
}
if err = scanner.Err(); err != nil {
return nil, err
}
return lines, nil
}

//nolint:gochecknoinits
func init() {
abuseCmd.AddCommand(abuseRandomReadsCmd)
Expand Down
2 changes: 1 addition & 1 deletion cmd/lakectl/cmd/abuse_random_writes.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var abuseRandomWritesCmd = &cobra.Command{
parallelism := Must(cmd.Flags().GetInt("parallelism"))
prefix := Must(cmd.Flags().GetString("prefix"))

fmt.Printf("Source branch: %s\n", u.String())
fmt.Println("Source branch:", u)
generator := stress.NewGenerator("stage object", parallelism, stress.WithSignalHandlersFor(os.Interrupt, syscall.SIGTERM))

// generate randomly selected keys as input
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"context"
"fmt"
"net/http"

"github.com/jedib0t/go-pretty/v6/text"
Expand All @@ -17,7 +18,7 @@ const actionTaskResultTemplate = `{{ $r := . }}{{ range $idx, $val := .Hooks }}{

const runsShowRequiredArgs = 2

var runsDescribeCmd = &cobra.Command{
var actionsRunsDescribeCmd = &cobra.Command{
Use: "describe",
Short: "Describe run results",
Long: `Show information about the run and all the hooks that were executed as part of the run`,
Expand All @@ -30,7 +31,7 @@ var runsDescribeCmd = &cobra.Command{
u := MustParseRepoURI("repository", args[0])
pagination := api.Pagination{HasMore: true}

Fmt("Repository: %s\n", u.String())
fmt.Println("Repository:", u)
runID := args[1]

client := getClient()
Expand Down Expand Up @@ -139,7 +140,8 @@ func convertHookResultsTables(results []api.HookRun) []*Table {

//nolint:gochecknoinits
func init() {
actionsRunsCmd.AddCommand(runsDescribeCmd)
runsDescribeCmd.Flags().Int("amount", 0, "number of results to return. By default, all results are returned.")
runsDescribeCmd.Flags().String("after", "", "show results after this value (used for pagination)")
actionsRunsDescribeCmd.Flags().Int("amount", 0, "number of results to return. By default, all results are returned.")
actionsRunsDescribeCmd.Flags().String("after", "", "show results after this value (used for pagination)")

actionsRunsCmd.AddCommand(actionsRunsDescribeCmd)
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const actionsRunsListTemplate = `{{.ActionsRunsTable | table -}}
{{.Pagination | paginate }}
`

var runsListCmd = &cobra.Command{
var actionsRunsListCmd = &cobra.Command{
Use: "list",
Short: "List runs",
Long: `List all runs on a repository optional filter by branch or commit`,
Expand Down Expand Up @@ -98,9 +98,9 @@ var runsListCmd = &cobra.Command{

//nolint:gochecknoinits
func init() {
actionsRunsCmd.AddCommand(runsListCmd)
runsListCmd.Flags().Int("amount", defaultAmountArgumentValue, "number of results to return")
runsListCmd.Flags().String("after", "", "show results after this value (used for pagination)")
runsListCmd.Flags().String("branch", "", "show results for specific branch")
runsListCmd.Flags().String("commit", "", "show results for specific commit ID")
actionsRunsCmd.AddCommand(actionsRunsListCmd)
actionsRunsListCmd.Flags().Int("amount", defaultAmountArgumentValue, "number of results to return")
actionsRunsListCmd.Flags().String("after", "", "show results after this value (used for pagination)")
actionsRunsListCmd.Flags().String("branch", "", "show results for specific branch")
actionsRunsListCmd.Flags().String("commit", "", "show results for specific commit ID")
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"fmt"
"io"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -29,7 +30,7 @@ var actionsValidateCmd = &cobra.Command{
if _, err := actions.ParseAction(bytes); err != nil {
DieErr(err)
}
Fmt("File validated successfully: '%s'\n", file)
fmt.Printf("File validated successfully: '%s'\n", file)
},
}

Expand Down
Loading
Loading