Skip to content

Commit 243afa7

Browse files
Japstypsergee
authored andcommitted
clean: make output more compact
The tt clean output where cumbersome, so it was made more compact. Now, without the tt -V flag, the output will be compact and clear.
1 parent ba846d8 commit 243afa7

File tree

2 files changed

+22
-26
lines changed

2 files changed

+22
-26
lines changed

cli/cmd/clean.go

+9-14
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package cmd
22

33
import (
4-
"fmt"
4+
"errors"
55
"os"
66
"path/filepath"
77

@@ -16,6 +16,7 @@ import (
1616
)
1717

1818
var forceRemove bool
19+
var ErrCanceledByUser = errors.New("canceled by user")
1920

2021
// NewCleanCmd creates clean command.
2122
func NewCleanCmd() *cobra.Command {
@@ -74,16 +75,6 @@ func clean(run *running.InstanceCtx) error {
7475
}
7576
}
7677

77-
if len(removeFiles) == 0 {
78-
log.Infof("Already cleaned.\n")
79-
return nil
80-
}
81-
82-
log.Infof("List of files to delete:\n")
83-
for file, _ := range removeFiles {
84-
log.Infof("%s", file)
85-
}
86-
8778
if !forceRemove {
8879
confirm, err = util.AskConfirm(os.Stdin, "\nConfirm")
8980
if err != nil {
@@ -97,12 +88,13 @@ func clean(run *running.InstanceCtx) error {
9788
if err != nil {
9889
return err
9990
}
91+
log.Debugf("removed %q", file)
10092
}
10193

10294
return nil
10395
}
10496

105-
return fmt.Errorf("canceled by user")
97+
return ErrCanceledByUser
10698
}
10799

108100
// internalCleanModule is a default clean module.
@@ -122,13 +114,16 @@ func internalCleanModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
122114
var statusMsg string
123115

124116
err := clean(&run)
125-
if err != nil {
117+
if errors.Is(err, ErrCanceledByUser) {
118+
statusMsg = ErrCanceledByUser.Error()
119+
} else if err != nil {
126120
statusMsg = "[ERR] " + err.Error()
127121
} else {
128122
statusMsg = "[OK]"
129123
}
130124

131-
log.Infof("%s: cleaning...\t%s", run.InstName, statusMsg)
125+
log.Infof("%s%c%s...\t%s", run.AppName, running.InstanceDelimiter, run.InstName,
126+
statusMsg)
132127
} else {
133128
log.Infof("instance `%s` must be stopped", run.InstName)
134129
}

test/integration/running/test_running.py

+13-12
Original file line numberDiff line numberDiff line change
@@ -175,19 +175,20 @@ def test_logrotate(tt_cmd, tmpdir_with_cfg):
175175
assert instance_process_rc == 0
176176

177177

178-
def assert_file_cleaned(filepath, cmd_out):
178+
def assert_file_cleaned(filepath, instance_name, cmd_out):
179179
# https://github.com/tarantool/tt/issues/735
180-
assert len(re.findall(r"• " + str(filepath), cmd_out)) == 1
180+
assert len(re.findall(r"• " + instance_name, cmd_out)) == 1
181181
assert os.path.exists(filepath) is False
182182

183183

184184
def test_clean(tt_cmd, tmpdir_with_cfg):
185185
tmpdir = tmpdir_with_cfg
186-
test_app_path = os.path.join(os.path.dirname(__file__), "test_data_app", "test_data_app.lua")
186+
app_name = "test_data_app"
187+
test_app_path = os.path.join(os.path.dirname(__file__), app_name, "test_data_app.lua")
187188
shutil.copy(test_app_path, tmpdir)
188189

189190
# Start an instance.
190-
start_cmd = [tt_cmd, "start", "test_data_app"]
191+
start_cmd = [tt_cmd, "start", app_name]
191192
instance_process = subprocess.Popen(
192193
start_cmd,
193194
cwd=tmpdir,
@@ -199,9 +200,9 @@ def test_clean(tt_cmd, tmpdir_with_cfg):
199200
assert re.search(r"Starting an instance", start_output)
200201

201202
# Wait until application is ready.
202-
lib_dir = os.path.join(tmpdir, "test_data_app", lib_path, "test_data_app")
203-
run_dir = os.path.join(tmpdir, "test_data_app", run_path, "test_data_app")
204-
log_dir = os.path.join(tmpdir, "test_data_app", log_path, "test_data_app")
203+
lib_dir = os.path.join(tmpdir, app_name, lib_path, app_name)
204+
run_dir = os.path.join(tmpdir, app_name, run_path, app_name)
205+
log_dir = os.path.join(tmpdir, app_name, log_path, app_name)
205206

206207
file = wait_file(lib_dir, initial_snap, [])
207208
assert file != ""
@@ -216,13 +217,13 @@ def test_clean(tt_cmd, tmpdir_with_cfg):
216217
assert file != ""
217218

218219
# Check that clean warns about application is running.
219-
clean_cmd = [tt_cmd, "clean", "test_data_app", "--force"]
220+
clean_cmd = [tt_cmd, "clean", app_name, "--force"]
220221
clean_rc, clean_out = run_command_and_get_output(clean_cmd, cwd=tmpdir)
221222
assert clean_rc == 0
222223
assert re.search(r"instance `test_data_app` must be stopped", clean_out)
223224

224225
# Stop the Instance.
225-
stop_cmd = [tt_cmd, "stop", "-y", "test_data_app"]
226+
stop_cmd = [tt_cmd, "stop", "-y", app_name]
226227
stop_rc, stop_out = run_command_and_get_output(stop_cmd, cwd=tmpdir)
227228
assert stop_rc == 0
228229
assert re.search(r"The Instance test_data_app \(PID = \d+\) has been terminated\.", stop_out)
@@ -236,9 +237,9 @@ def test_clean(tt_cmd, tmpdir_with_cfg):
236237
assert clean_rc == 0
237238
assert re.search(r"\[ERR\]", clean_out) is None
238239

239-
assert_file_cleaned(os.path.join(log_dir, log_file), clean_out)
240-
assert_file_cleaned(os.path.join(lib_dir, initial_snap), clean_out)
241-
assert_file_cleaned(os.path.join(lib_dir, initial_xlog), clean_out)
240+
assert_file_cleaned(os.path.join(log_dir, log_file), app_name, clean_out)
241+
assert_file_cleaned(os.path.join(lib_dir, initial_snap), app_name, clean_out)
242+
assert_file_cleaned(os.path.join(lib_dir, initial_xlog), app_name, clean_out)
242243

243244

244245
def test_running_base_functionality_working_dir_app(tt_cmd):

0 commit comments

Comments
 (0)