Skip to content

Commit c4a66fb

Browse files
authored
Deprecate --progress-format flag and remove progress logger types (#3820)
## Changes This change removes remaining references to the "progress logger". All terminal I/O now goes through a single type in `cmdio`. Builds on #3811, #3812, and #3818.
1 parent 12ecd2b commit c4a66fb

File tree

12 files changed

+17
-293
lines changed

12 files changed

+17
-293
lines changed

NEXT_CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
### CLI
99
* Remove `inplace` mode for the `--progress-format` flag. ([#3811](https://github.com/databricks/cli/pull/3811))
1010
* Remove `json` mode for the `--progress-format` flag. ([#3812](https://github.com/databricks/cli/pull/3812))
11+
* Deprecate the `--progress-format` flag. ([#3819](https://github.com/databricks/cli/pull/3819))
1112

1213
### Dependency updates
1314

Lines changed: 3 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,12 @@
1-
// Copied from cmd/root/progress_logger.go and adapted for pipelines use.
21
package root
32

43
import (
5-
"context"
6-
7-
"github.com/databricks/cli/libs/cmdio"
8-
"github.com/databricks/cli/libs/env"
9-
"github.com/databricks/cli/libs/flags"
104
"github.com/spf13/cobra"
115
)
126

13-
const envProgressFormat = "DATABRICKS_CLI_PROGRESS_FORMAT"
14-
15-
type progressLoggerFlag struct {
16-
flags.ProgressLogFormat
17-
}
18-
19-
func (f *progressLoggerFlag) initializeContext(ctx context.Context) (context.Context, error) {
20-
// No need to initialize the logger if it's already set in the context. This
21-
// happens in unit tests where the logger is setup as a fixture.
22-
if _, ok := cmdio.FromContext(ctx); ok {
23-
return ctx, nil
24-
}
25-
26-
format := f.ProgressLogFormat
27-
if format == flags.ModeDefault {
28-
format = flags.ModeAppend
29-
}
30-
31-
progressLogger := cmdio.NewLogger(format)
32-
return cmdio.NewContext(ctx, progressLogger), nil
33-
}
34-
35-
func initProgressLoggerFlag(cmd *cobra.Command, logFlags *logFlags) *progressLoggerFlag {
36-
f := progressLoggerFlag{
37-
ProgressLogFormat: flags.NewProgressLogFormat(),
38-
}
39-
40-
// Configure defaults from environment, if applicable.
41-
// If the provided value is invalid it is ignored.
42-
if v, ok := env.Lookup(cmd.Context(), envProgressFormat); ok {
43-
_ = f.Set(v)
44-
}
45-
7+
func initProgressLoggerFlag(cmd *cobra.Command, logFlags *logFlags) {
468
flags := cmd.PersistentFlags()
47-
flags.Var(&f.ProgressLogFormat, "progress-format", "format for progress logs (append)")
9+
_ = flags.String("progress-format", "", "format for progress logs")
4810
flags.MarkHidden("progress-format")
49-
cmd.RegisterFlagCompletionFunc("progress-format", f.Complete)
50-
return &f
11+
flags.MarkDeprecated("progress-format", "this flag is no longer functional")
5112
}

cmd/pipelines/root/root.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,13 @@ func New(ctx context.Context) *cobra.Command {
3636

3737
// Initialize flags
3838
logFlags := initLogFlags(cmd)
39-
progressLoggerFlag := initProgressLoggerFlag(cmd, logFlags)
4039
outputFlag := initOutputFlag(cmd)
4140
initProfileFlag(cmd)
4241
initTargetFlag(cmd)
4342

43+
// Deprecated flag. Warn if it is specified.
44+
initProgressLoggerFlag(cmd, logFlags)
45+
4446
cmd.PersistentPreRunE = func(cmd *cobra.Command, args []string) error {
4547
ctx := cmd.Context()
4648

@@ -55,11 +57,6 @@ func New(ctx context.Context) *cobra.Command {
5557
slog.String("version", build.GetInfo().Version),
5658
slog.String("args", strings.Join(os.Args, ", ")))
5759

58-
// Configure progress logger
59-
ctx, err = progressLoggerFlag.initializeContext(ctx)
60-
if err != nil {
61-
return err
62-
}
6360
// set context, so that initializeIO can have the current context
6461
cmd.SetContext(ctx)
6562

cmd/root/progress_logger.go

Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,12 @@
11
package root
22

33
import (
4-
"context"
5-
6-
"github.com/databricks/cli/libs/cmdio"
7-
"github.com/databricks/cli/libs/env"
8-
"github.com/databricks/cli/libs/flags"
94
"github.com/spf13/cobra"
105
)
116

12-
const envProgressFormat = "DATABRICKS_CLI_PROGRESS_FORMAT"
13-
14-
type progressLoggerFlag struct {
15-
flags.ProgressLogFormat
16-
}
17-
18-
func (f *progressLoggerFlag) initializeContext(ctx context.Context) (context.Context, error) {
19-
// No need to initialize the logger if it's already set in the context. This
20-
// happens in unit tests where the logger is setup as a fixture.
21-
if _, ok := cmdio.FromContext(ctx); ok {
22-
return ctx, nil
23-
}
24-
25-
format := f.ProgressLogFormat
26-
if format == flags.ModeDefault {
27-
format = flags.ModeAppend
28-
}
29-
30-
progressLogger := cmdio.NewLogger(format)
31-
return cmdio.NewContext(ctx, progressLogger), nil
32-
}
33-
34-
func initProgressLoggerFlag(cmd *cobra.Command, logFlags *logFlags) *progressLoggerFlag {
35-
f := progressLoggerFlag{
36-
ProgressLogFormat: flags.NewProgressLogFormat(),
37-
}
38-
39-
// Configure defaults from environment, if applicable.
40-
// If the provided value is invalid it is ignored.
41-
if v, ok := env.Lookup(cmd.Context(), envProgressFormat); ok {
42-
_ = f.Set(v)
43-
}
44-
7+
func initProgressLoggerFlag(cmd *cobra.Command, logFlags *logFlags) {
458
flags := cmd.PersistentFlags()
46-
flags.Var(&f.ProgressLogFormat, "progress-format", "format for progress logs (append)")
9+
_ = flags.String("progress-format", "", "format for progress logs")
4710
flags.MarkHidden("progress-format")
48-
cmd.RegisterFlagCompletionFunc("progress-format", f.Complete)
49-
return &f
11+
flags.MarkDeprecated("progress-format", "this flag is no longer functional")
5012
}

cmd/root/progress_logger_test.go

Lines changed: 0 additions & 40 deletions
This file was deleted.

cmd/root/root.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,14 @@ func New(ctx context.Context) *cobra.Command {
4242

4343
// Initialize flags
4444
logFlags := initLogFlags(cmd)
45-
progressLoggerFlag := initProgressLoggerFlag(cmd, logFlags)
4645
outputFlag := initOutputFlag(cmd)
4746
initProfileFlag(cmd)
4847
initEnvironmentFlag(cmd)
4948
initTargetFlag(cmd)
5049

50+
// Deprecated flag. Warn if it is specified.
51+
initProgressLoggerFlag(cmd, logFlags)
52+
5153
cmd.PersistentPreRunE = func(cmd *cobra.Command, args []string) error {
5254
ctx := cmd.Context()
5355

@@ -62,11 +64,6 @@ func New(ctx context.Context) *cobra.Command {
6264
slog.String("version", build.GetInfo().Version),
6365
slog.String("args", strings.Join(os.Args, ", ")))
6466

65-
// Configure progress logger
66-
ctx, err = progressLoggerFlag.initializeContext(ctx)
67-
if err != nil {
68-
return err
69-
}
7067
// set context, so that initializeIO can have the current context
7168
cmd.SetContext(ctx)
7269

integration/bundle/helpers_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,6 @@ func deployBundle(t testutil.TestingT, ctx context.Context, path string) {
6969

7070
func runResource(t testutil.TestingT, ctx context.Context, path, key string) (string, error) {
7171
ctx = env.Set(ctx, "BUNDLE_ROOT", path)
72-
ctx = cmdio.NewContext(ctx, cmdio.Default())
73-
7472
c := testcli.NewRunner(t, ctx, "bundle", "run", key)
7573
stdout, _, err := c.Run()
7674
return stdout.String(), err

internal/testcli/runner.go

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616
"github.com/databricks/cli/cmd/root"
1717
"github.com/databricks/cli/internal/testutil"
1818
"github.com/databricks/cli/libs/cmdio"
19-
"github.com/databricks/cli/libs/flags"
2019
)
2120

2221
// Helper for running the root command in the background.
@@ -101,13 +100,8 @@ func (r *Runner) RunBackground() {
101100
var stdoutW, stderrW io.WriteCloser
102101
stdoutR, stdoutW = io.Pipe()
103102
stderrR, stderrW = io.Pipe()
104-
ctx := cmdio.NewContext(r.ctx, &cmdio.Logger{
105-
Mode: flags.ModeAppend,
106-
Reader: bufio.Reader{},
107-
Writer: stderrW,
108-
})
109103

110-
cli := cmd.New(ctx)
104+
cli := cmd.New(r.ctx)
111105
cli.SetOut(stdoutW)
112106
cli.SetErr(stderrW)
113107
cli.SetArgs(r.args)
@@ -116,7 +110,7 @@ func (r *Runner) RunBackground() {
116110
}
117111

118112
errch := make(chan error)
119-
ctx, cancel := context.WithCancel(ctx)
113+
ctx, cancel := context.WithCancel(r.ctx)
120114

121115
// Tee stdout/stderr to buffers.
122116
stdoutR = io.TeeReader(stdoutR, &r.stdout)
@@ -183,13 +177,8 @@ func (r *Runner) RunBackground() {
183177
func (r *Runner) Run() (bytes.Buffer, bytes.Buffer, error) {
184178
r.Helper()
185179
var stdout, stderr bytes.Buffer
186-
ctx := cmdio.NewContext(r.ctx, &cmdio.Logger{
187-
Mode: flags.ModeAppend,
188-
Reader: bufio.Reader{},
189-
Writer: &stderr,
190-
})
191180

192-
cli := cmd.New(ctx)
181+
cli := cmd.New(r.ctx)
193182
cli.SetOut(&stdout)
194183
cli.SetErr(&stderr)
195184
cli.SetArgs(r.args)
@@ -198,7 +187,7 @@ func (r *Runner) Run() (bytes.Buffer, bytes.Buffer, error) {
198187
r.Logf(" args: %s", strings.Join(r.args, ", "))
199188
}
200189

201-
err := root.Execute(ctx, cli)
190+
err := root.Execute(r.ctx, cli)
202191
if err != nil {
203192
if r.Verbose {
204193
r.Logf(" error: %s", err)

libs/cmdio/context.go

Lines changed: 0 additions & 20 deletions
This file was deleted.

libs/cmdio/logger.go

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)