Skip to content

Commit 19e4f5e

Browse files
committed
tools: implement progres bar for v check-md .
1 parent 79284f0 commit 19e4f5e

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

cmd/tools/vcheck-md.v

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const (
1414
too_long_line_length = 100
1515
term_colors = term.can_show_color_on_stderr()
1616
hide_warnings = '-hide-warnings' in os.args || '-w' in os.args
17+
show_progress = os.getenv('GITHUB_JOB') == '' && '-silent' !in os.args
1718
non_option_args = cmdline.only_non_options(os.args[2..])
1819
)
1920

@@ -41,6 +42,10 @@ fn main() {
4142
println('´-all´ flag is deprecated. Please use ´v check-md .´ instead.')
4243
exit(1)
4344
}
45+
if show_progress {
46+
// this is intended to be replaced by the progress lines
47+
println('')
48+
}
4449
mut files_paths := non_option_args.clone()
4550
mut res := CheckResult{}
4651
if term_colors {
@@ -64,6 +69,9 @@ fn main() {
6469
}
6570
res += mdfile.check()
6671
}
72+
if res.errors == 0 && show_progress {
73+
term.clear_previous_line()
74+
}
6775
if res.warnings > 0 || res.errors > 0 || res.oks > 0 {
6876
println('\nWarnings: $res.warnings | Errors: $res.errors | OKs: $res.oks')
6977
}
@@ -145,9 +153,17 @@ mut:
145153
state MDFileParserState = .markdown
146154
}
147155

156+
fn (mut f MDFile) progress(message string) {
157+
if show_progress {
158+
term.clear_previous_line()
159+
println('File: ${f.path:-30s}, Lines: ${f.lines.len:5}, $message')
160+
}
161+
}
162+
148163
fn (mut f MDFile) check() CheckResult {
149164
mut res := CheckResult{}
150165
for j, line in f.lines {
166+
// f.progress('line: $j')
151167
if line.len > too_long_line_length {
152168
if f.state == .vexample {
153169
wprintln(wline(f.path, j, line.len, 'long V example line'))
@@ -265,6 +281,7 @@ fn (mut f MDFile) check_examples() CheckResult {
265281
mut acommands := e.command.split(' ')
266282
nofmt := 'nofmt' in acommands
267283
for command in acommands {
284+
f.progress('example from $e.sline to $e.eline, command: $command')
268285
fmt_res := if nofmt { 0 } else { get_fmt_exit_code(vfile, vexe) }
269286
match command {
270287
'compile' {

cmd/v/help/check-md.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Usage:
77
Note: You can also combine files and directories.
88

99
Flags:
10+
-silent Do not show a progress bar.
1011
-w, -hide-warnings Do not print warnings, only errors.
1112

1213
NB: There are several special keywords, which you can put after the code fences for v.

0 commit comments

Comments
 (0)