Skip to content

Commit

Permalink
lakectl: add --no-progress flag (#8093)
Browse files Browse the repository at this point in the history
* lakectl: add --no-progress flag

* Gen docs

* CR Fixes

* goimports
  • Loading branch information
N-o-Z authored Aug 22, 2024
1 parent d42763c commit eb19cdd
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 5 deletions.
26 changes: 22 additions & 4 deletions cmd/lakectl/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/treeverse/lakefs/pkg/uri"
"github.com/treeverse/lakefs/pkg/version"
"golang.org/x/exp/slices"
"golang.org/x/term"
)

const (
Expand Down Expand Up @@ -144,13 +145,15 @@ var (
)

const (
recursiveFlagName = "recursive"
recursiveFlagShort = "r"
presignFlagName = "pre-sign"
parallelismFlagName = "parallelism"
recursiveFlagName = "recursive"
recursiveFlagShort = "r"
presignFlagName = "pre-sign"
parallelismFlagName = "parallelism"
noProgressBarFlagName = "no-progress"

defaultSyncParallelism = 25
defaultSyncPresign = true
defaultNoProgress = false

myRepoExample = "lakefs://my-repo"
myBucketExample = "s3://my-bucket"
Expand Down Expand Up @@ -182,9 +185,15 @@ func withPresignFlag(cmd *cobra.Command) {
"Use pre-signed URLs when downloading/uploading data (recommended)")
}

func withNoProgress(cmd *cobra.Command) {
cmd.Flags().Bool(noProgressBarFlagName, defaultNoProgress,
"Disable progress bar animation for IO operations")
}

func withSyncFlags(cmd *cobra.Command) {
withParallelismFlag(cmd)
withPresignFlag(cmd)
withNoProgress(cmd)
}

type PresignMode struct {
Expand Down Expand Up @@ -221,6 +230,14 @@ func getPresignMode(cmd *cobra.Command, client *apigen.ClientWithResponses) Pres
return presignMode
}

func getNoProgressMode(cmd *cobra.Command) bool {
// Disable progress bar if stdout is not tty
if !term.IsTerminal(int(os.Stdout.Fd())) {
return true
}
return Must(cmd.Flags().GetBool(noProgressBarFlagName))
}

func getSyncFlags(cmd *cobra.Command, client *apigen.ClientWithResponses) local.SyncFlags {
parallelism := Must(cmd.Flags().GetInt(parallelismFlagName))
if parallelism < 1 {
Expand All @@ -232,6 +249,7 @@ func getSyncFlags(cmd *cobra.Command, client *apigen.ClientWithResponses) local.
Parallelism: parallelism,
Presign: presignMode.Enabled,
PresignMultipart: presignMode.Multipart,
NoProgress: getNoProgressMode(cmd),
}
}

Expand Down
6 changes: 6 additions & 0 deletions docs/reference/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -2156,6 +2156,7 @@ lakectl fs download <path URI> [<destination path>] [flags]

```
-h, --help help for download
--no-progress Disable progress bar animation for IO operations
-p, --parallelism int Max concurrent operations to perform (default 25)
--part-size int part size in bytes for multipart download (default 8388608)
--pre-sign Use pre-signed URLs when downloading/uploading data (recommended) (default true)
Expand Down Expand Up @@ -2305,6 +2306,7 @@ lakectl fs upload <path URI> [flags]
```
--content-type string MIME type of contents
-h, --help help for upload
--no-progress Disable progress bar animation for IO operations
-p, --parallelism int Max concurrent operations to perform (default 25)
--pre-sign Use pre-signed URLs when downloading/uploading data (recommended) (default true)
-r, --recursive recursively copy all files under local source
Expand Down Expand Up @@ -2538,6 +2540,7 @@ lakectl local checkout [directory] [flags]
```
--all Checkout given source branch or reference for all linked directories
-h, --help help for checkout
--no-progress Disable progress bar animation for IO operations
-p, --parallelism int Max concurrent operations to perform (default 25)
--pre-sign Use pre-signed URLs when downloading/uploading data (recommended) (default true)
-r, --ref string Checkout the given reference
Expand All @@ -2560,6 +2563,7 @@ lakectl local clone <path URI> [directory] [flags]
```
--gitignore Update .gitignore file when working in a git repository context (default true)
-h, --help help for clone
--no-progress Disable progress bar animation for IO operations
-p, --parallelism int Max concurrent operations to perform (default 25)
--pre-sign Use pre-signed URLs when downloading/uploading data (recommended) (default true)
```
Expand All @@ -2583,6 +2587,7 @@ lakectl local commit [directory] [flags]
-h, --help help for commit
-m, --message string commit message
--meta strings key value pair in the form of key=value
--no-progress Disable progress bar animation for IO operations
-p, --parallelism int Max concurrent operations to perform (default 25)
--pre-sign Use pre-signed URLs when downloading/uploading data (recommended) (default true)
```
Expand Down Expand Up @@ -2662,6 +2667,7 @@ lakectl local pull [directory] [flags]
```
--force Reset any uncommitted local change
-h, --help help for pull
--no-progress Disable progress bar animation for IO operations
-p, --parallelism int Max concurrent operations to perform (default 25)
--pre-sign Use pre-signed URLs when downloading/uploading data (recommended) (default true)
```
Expand Down
7 changes: 7 additions & 0 deletions pkg/fileutil/fs_case.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ func IsCaseInsensitiveLocation(fs FS, dirPath string, warnFunc func(string)) (bo
if err != nil {
return false, fmt.Errorf("generate random name: %w", err)
}
exists, err := fs.Exists(dirPath)
if err != nil {
return false, fmt.Errorf("check path exists: %w", err)
}
if !exists { // Folder can be created by the command itself - go back one dir
dirPath = filepath.Dir(dirPath)
}
path := filepath.Join(dirPath, caseSensitiveNamePrefix+id)
err = fs.Touch(path)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions pkg/local/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type SyncFlags struct {
Parallelism int
Presign bool
PresignMultipart bool
NoProgress bool
}

type Config struct {
Expand Down
7 changes: 6 additions & 1 deletion pkg/local/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"time"

"github.com/go-openapi/swag"
"github.com/jedib0t/go-pretty/v6/progress"
"github.com/treeverse/lakefs/pkg/api/apigen"
"github.com/treeverse/lakefs/pkg/api/helpers"
"github.com/treeverse/lakefs/pkg/fileutil"
Expand Down Expand Up @@ -52,13 +53,17 @@ type SyncManager struct {
}

func NewSyncManager(ctx context.Context, client *apigen.ClientWithResponses, httpClient *http.Client, cfg Config) *SyncManager {
return &SyncManager{
sm := &SyncManager{
ctx: ctx,
client: client,
httpClient: httpClient,
progressBar: NewProgressPool(),
cfg: cfg,
}
if cfg.NoProgress {
sm.progressBar.pw.Style().Visibility = progress.StyleVisibility{}
}
return sm
}

// Sync - sync changes between remote and local directory given the Changes channel.
Expand Down

0 comments on commit eb19cdd

Please sign in to comment.