Skip to content

Commit

Permalink
Update deprecated (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
ttytm authored Apr 6, 2024
1 parent 710c589 commit f9f0f11
Show file tree
Hide file tree
Showing 23 changed files with 52 additions and 48 deletions.
2 changes: 1 addition & 1 deletion common/common.v
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pub fn (app CoreutilInfo) quit(detail CoreutilExitDetail) {
// ("<msg>; code: <code>") away from a POSIX and Win32 error to make
// it match what GNU coreutils return
pub fn strip_error_code_from_msg(msg string) string {
j := msg.index_last('; code: ') or { -1 }
j := msg.last_index('; code: ') or { -1 }
if j > 0 {
return msg[0..j]
} else {
Expand Down
12 changes: 6 additions & 6 deletions src/base32/helper.v
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ fn decode_and_output(file os.File, wrap int) {
mut i := u64(0)
for {
num := file.read_bytes_into(i, mut groups) or {
common.exit_with_error_message(name, err.msg)
common.exit_with_error_message(name, err.msg())
}
if num == 0 || (num == 1 && groups[0] == `\n`) {
break
} else if num < groups.len {
common.exit_with_error_message(name, invalid)
}
i += u64(num)
builder.write(get_blocks(groups)) or { common.exit_with_error_message(name, err.msg) }
builder.write(get_blocks(groups)) or { common.exit_with_error_message(name, err.msg()) }
}
print(builder.str())
}
Expand Down Expand Up @@ -81,7 +81,7 @@ fn encode_and_output(file os.File, wrap int) {
0
}
else {
common.exit_with_error_message(name, err.msg)
common.exit_with_error_message(name, err.msg())
}
}
}
Expand All @@ -104,7 +104,7 @@ fn encode_and_output(file os.File, wrap int) {
}
groups := get_groups(block, u8(num_equal))
mut result := strings.new_builder(groups.len)
result.write(groups) or { common.exit_with_error_message(name, err.msg) }
result.write(groups) or { common.exit_with_error_message(name, err.msg()) }
print(result.str())
}
println('')
Expand All @@ -114,7 +114,7 @@ fn get_file(file_arg []string) os.File {
if file_arg.len == 0 || file_arg[0] == '-' {
return os.stdin()
} else {
return os.open(file_arg[0]) or { common.exit_with_error_message(name, err.msg) }
return os.open(file_arg[0]) or { common.exit_with_error_message(name, err.msg()) }
}
}

Expand All @@ -136,7 +136,7 @@ fn run_base32(args []string) {
if version {
success_exit('${name} ${common.coreutils_version()}')
}
file_arg := fp.finalize() or { common.exit_with_error_message(name, err.msg) }
file_arg := fp.finalize() or { common.exit_with_error_message(name, err.msg()) }

if file_arg.len > 1 {
common.exit_with_error_message(name, 'only one file should be provided')
Expand Down
2 changes: 1 addition & 1 deletion src/basename/basename.v
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fn basename(name string, suffix string, is_zero bool) {
if name_noslash == '' {
out = '/'
} else {
if idx := name_noslash.index_last('/') {
if idx := name_noslash.last_index('/') {
out = name_noslash[idx + 1..]
} else {
out = name_noslash
Expand Down
2 changes: 1 addition & 1 deletion src/cp/CpCommand.v
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fn (c CpCommand) run(source string, dest string) {
eprintln(not_recursive(source))
return
}
os.cp(source, dest) or { error_exit(name, err.msg) }
os.cp(source, dest) or { error_exit(name, err.msg()) }
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/cp/helper.v
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ fn success_exit(messages ...string) {
fn setup_cp_command(args []string) ?(CpCommand, []string, string) {
mut fp := common.flag_parser(args)
fp.application('cp')
fp.limit_free_args_to_at_least(1) or { common.exit_with_error_message(name, err.msg) }
fp.limit_free_args_to_at_least(1) or { common.exit_with_error_message(name, err.msg()) }

force := fp.bool('force', `f`, false, 'ignore interactive and no-clobber')
interactive := fp.bool('interactive', `i`, false, 'ask for each overwrite')
Expand Down Expand Up @@ -143,7 +143,9 @@ fn setup_cp_command(args []string) ?(CpCommand, []string, string) {
}

pub fn run_cp(args []string) {
cp, sources, dest := setup_cp_command(args) or { common.exit_with_error_message(name, err.msg) }
cp, sources, dest := setup_cp_command(args) or {
common.exit_with_error_message(name, err.msg())
}
if sources.len > 1 && !os.is_dir(dest) {
common.exit_with_error_message(name, target_not_dir(dest))
}
Expand Down
4 changes: 2 additions & 2 deletions src/factor/factor.v
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ fn main() {
for {
println(output_of(os.input_opt('') or { common.exit_on_errors(errors) }) or {
errors++
eprintln(err.msg)
eprintln(err.msg())
continue
})
}
} else {
for arg in args {
println(output_of(arg) or {
errors++
eprintln(err.msg)
eprintln(err.msg())
continue
})
}
Expand Down
2 changes: 1 addition & 1 deletion src/fold/fold.v
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ fn run_fold(args []string) {
success_exit('${name} ${common.coreutils_version()}')
}

file_args := fp.finalize() or { common.exit_with_error_message(name, err.msg) }
file_args := fp.finalize() or { common.exit_with_error_message(name, err.msg()) }

cmd := FoldCommand{
max_col_width: width
Expand Down
4 changes: 2 additions & 2 deletions src/head/head.v
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ fn setup_command(args []string) ?(HeadCommand, []InputFile) {
success_exit('${name} ${common.coreutils_version()}')
}

file_args := fp.finalize() or { common.exit_with_error_message(name, err.msg) }
file_args := fp.finalize() or { common.exit_with_error_message(name, err.msg()) }

return HeadCommand{
bytes_to_read: bytes
Expand All @@ -330,7 +330,7 @@ fn setup_command(args []string) ?(HeadCommand, []InputFile) {
}

fn run_head(args []string) {
head, mut files := setup_command(args) or { common.exit_with_error_message(name, err.msg) }
head, mut files := setup_command(args) or { common.exit_with_error_message(name, err.msg()) }

head.run(mut files)
}
Expand Down
6 changes: 3 additions & 3 deletions src/ln/Linker.v
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,18 @@ fn (ln Linker) link_to_dir() {
fn (ln Linker) link(source_path string, target_path string) {
if os.exists(target_path) {
if ln.force {
os.rm(target_path) or { common.exit_with_error_message(name, err.msg) }
os.rm(target_path) or { common.exit_with_error_message(name, err.msg()) }
} else {
common.exit_with_error_message(name, '${target_path} already exists')
}
}
if ln.symbolic {
os.symlink(source_path, target_path) or { common.exit_with_error_message(name, err.msg) }
os.symlink(source_path, target_path) or { common.exit_with_error_message(name, err.msg()) }
} else {
if os.is_dir(source_path) {
common.exit_with_error_message(name, 'only symbolic links are supported for directories')
}
os.link(source_path, target_path) or { common.exit_with_error_message(name, err.msg) }
os.link(source_path, target_path) or { common.exit_with_error_message(name, err.msg()) }
}
println('${target_path} -> ${source_path}')
}
Expand Down
4 changes: 2 additions & 2 deletions src/ln/helper.v
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fn success_exit(messages ...string) {
fn run_ln(args []string) {
mut fp := common.flag_parser(args)
fp.application(name)
fp.limit_free_args_to_at_least(2) or { common.exit_with_error_message(name, err.msg) }
fp.limit_free_args_to_at_least(2) or { common.exit_with_error_message(name, err.msg()) }

force := fp.bool('', `f`, false, 'Force existing destination pathnames to be removed to allow the link.')
follow_symbolic := fp.bool('', `L`, false, 'For each source_file operand that names a file of type symbolic link, create a (hard) link to the file referenced by the symbolic link.')
Expand All @@ -29,7 +29,7 @@ fn run_ln(args []string) {
success_exit('${name} ${common.coreutils_version()}')
}

files := fp.finalize() or { common.exit_with_error_message(name, err.msg) }
files := fp.finalize() or { common.exit_with_error_message(name, err.msg()) }

mut ln := Linker{
force: force
Expand Down
2 changes: 1 addition & 1 deletion src/mkdir/mkdir.v
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ fn run_mkdir(args []string) {
success_exit('${name} ${common.coreutils_version()}')
}

file_args := fp.finalize() or { common.exit_with_error_message(name, err.msg) }
file_args := fp.finalize() or { common.exit_with_error_message(name, err.msg()) }
if file_args.len == 0 {
eprintln('${name}: missing operand')
eprintln("Try '${name} --help' for more information")
Expand Down
2 changes: 1 addition & 1 deletion src/mv/MvCommand.v
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn (m MvCommand) run(source string, dest string) {
if m.verbose || m.overwrite != .force {
m.move(source, dest)
} else {
os.mv(source, dest) or { error_exit(name, err.msg) }
os.mv(source, dest) or { error_exit(name, err.msg()) }
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/mv/helper.v
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ fn int_yes(prompt string) bool {
}

pub fn run_mv(args []string) {
mv, sources, dest := setup_mv_command(args) or { common.exit_with_error_message(name, err.msg) }
mv, sources, dest := setup_mv_command(args) or {
common.exit_with_error_message(name, err.msg())
}
if sources.len > 1 && !os.is_dir(dest) {
common.exit_with_error_message(name, target_not_dir(dest))
}
Expand All @@ -60,7 +62,7 @@ pub fn run_mv(args []string) {
fn setup_mv_command(args []string) ?(MvCommand, []string, string) {
mut fp := common.flag_parser(args)
fp.application('mv')
fp.limit_free_args_to_at_least(1) or { common.exit_with_error_message(name, err.msg) }
fp.limit_free_args_to_at_least(1) or { common.exit_with_error_message(name, err.msg()) }

force := fp.bool('force', `f`, false, 'ignore interactive and no-clobber')
interactive := fp.bool('interactive', `i`, false, 'ask for each overwrite')
Expand Down
18 changes: 9 additions & 9 deletions src/nl/nl.v
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ fn open_stream(args_fn []string) []os.File {
// handle stdin like files
streams << os.stdin()
} else {
streams << os.open(fname) or { common.exit_with_error_message(app_name, err.msg) }
streams << os.open(fname) or { common.exit_with_error_message(app_name, err.msg()) }
}
}

Expand Down Expand Up @@ -238,11 +238,11 @@ fn args() ?(Settings, []string) {
// -b
b_style := fp.string('body-numbering', `b`, 't', 'Select the numbering style for lines in the body section (a:all, n:none, t:only no blank, pRE: match for the regular expression)')
settings.styles[Section.body] = get_style(b_style) or {
common.exit_with_error_message(app_name, err.msg)
common.exit_with_error_message(app_name, err.msg())
}
if settings.styles[Section.body] == .regex {
settings.res[Section.body] = get_style_regex(b_style) or {
common.exit_with_error_message(app_name, err.msg)
common.exit_with_error_message(app_name, err.msg())
}
}

Expand All @@ -267,22 +267,22 @@ fn args() ?(Settings, []string) {
// -f
f_style := fp.string('footer-numbering', `f`, 'n', 'Select the numbering style for lines in the footer section')
settings.styles[Section.footer] = get_style(f_style) or {
common.exit_with_error_message(app_name, err.msg)
common.exit_with_error_message(app_name, err.msg())
}
if settings.styles[Section.footer] == .regex {
settings.res[Section.footer] = get_style_regex(f_style) or {
common.exit_with_error_message(app_name, err.msg)
common.exit_with_error_message(app_name, err.msg())
}
}

// -h
h_style := fp.string('header-numbering', `h`, 'n', 'Select the numbering style for lines in the header section')
settings.styles[Section.header] = get_style(h_style) or {
common.exit_with_error_message(app_name, err.msg)
common.exit_with_error_message(app_name, err.msg())
}
if settings.styles[Section.header] == .regex {
settings.res[Section.header] = get_style_regex(h_style) or {
common.exit_with_error_message(app_name, err.msg)
common.exit_with_error_message(app_name, err.msg())
}
}

Expand All @@ -294,7 +294,7 @@ fn args() ?(Settings, []string) {

// -n
format := fp.string('number-format', `n`, 'rn', 'Select the line numbering format (ln:left-justified, rn:right-justified, rz:leading-zeros)')
settings.format = get_format(format) or { common.exit_with_error_message(app_name, err.msg) }
settings.format = get_format(format) or { common.exit_with_error_message(app_name, err.msg()) }

// -p
no_renumber := fp.bool('no-renumber', `p`, false, 'Do not reset the line number at the start of each logical page')
Expand All @@ -310,7 +310,7 @@ fn args() ?(Settings, []string) {
settings.width = fp.int('number-width', `w`, 6, 'Set number digits for line numbers')

// files
fnames = fp.finalize() or { common.exit_with_error_message(app_name, err.msg) }
fnames = fp.finalize() or { common.exit_with_error_message(app_name, err.msg()) }

return settings, fnames
}
Expand Down
4 changes: 2 additions & 2 deletions src/nohup/nohup.v
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ fn main() {
}
if stdout_is_tty == 1 {
mut f := os.stdout()
open_nohup_out(mut f, true) or { common.exit_with_error_message(tool_name, err.msg) }
open_nohup_out(mut f, true) or { common.exit_with_error_message(tool_name, err.msg()) }
}
if os.is_atty(os.stderr().fd) == 1 {
if os.stdout().is_opened == false {
mut f := os.stderr()
open_nohup_out(mut f, false) or { common.exit_with_error_message(tool_name, err.msg) }
open_nohup_out(mut f, false) or { common.exit_with_error_message(tool_name, err.msg()) }
} else {
// couldn't find a v equilavent of this
C.dup2(os.stdout().fd, os.stderr().fd)
Expand Down
4 changes: 2 additions & 2 deletions src/rm/RmCommand.v
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fn (r RmCommand) rm_dir(path string) {
return
}

os.rmdir(path) or { eprintln(err.msg) }
os.rmdir(path) or { eprintln(err.msg()) }
return
}

Expand Down Expand Up @@ -123,7 +123,7 @@ fn (r RmCommand) rm_path(path string) {
return
}
if r.int_yes(prompt_file(path)) {
os.rm(path) or { error_message(name, err.msg) }
os.rm(path) or { error_message(name, err.msg()) }
if r.verbose {
println(rem(path))
}
Expand Down
4 changes: 2 additions & 2 deletions src/rm/helper.v
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ fn check_interactive(interactive string) !Interactive {
fn setup_rm_command(args []string) !(RmCommand, []string) {
mut fp := common.flag_parser(args)
fp.application('rm')
fp.limit_free_args_to_at_least(1) or { common.exit_with_error_message(name, err.msg) }
fp.limit_free_args_to_at_least(1) or { common.exit_with_error_message(name, err.msg()) }

dir := fp.bool('dir', `d`, false, 'dir')
force := fp.bool('force', `f`, false, 'force')
Expand Down Expand Up @@ -155,7 +155,7 @@ fn setup_rm_command(args []string) !(RmCommand, []string) {
// Entry point for all logic. Must be called from main
pub fn run_rm(args []string) {
// Create command struct and accept flags and files
rm, files := setup_rm_command(args) or { common.exit_with_error_message(name, err.msg) }
rm, files := setup_rm_command(args) or { common.exit_with_error_message(name, err.msg()) }

// Take confirmation if necessary
if rm.confirm_int_once(files.len) {
Expand Down
2 changes: 1 addition & 1 deletion src/rmdir/RmdirCommand.v
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fn (r RmdirCommand) remove_dir(dir string) {
if r.verbose {
println("rmdir: removing directory, '${dir}'")
}
os.rmdir(dir) or { eprintln(err.msg) }
os.rmdir(dir) or { eprintln(err.msg()) }
if r.parents {
mut temp := if dir[dir.len - 1] == `/` { dir[0..dir.len - 1] } else { dir }
temp = os.dir(temp)
Expand Down
2 changes: 1 addition & 1 deletion src/rmdir/helper.v
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fn setup_rmdir_command(args []string) !(RmdirCommand, []string) {
}

fn run_rmdir(args []string) {
rmdir, dirs := setup_rmdir_command(args) or { common.exit_with_error_message(name, err.msg) }
rmdir, dirs := setup_rmdir_command(args) or { common.exit_with_error_message(name, err.msg()) }
for dir in dirs {
rmdir.remove_dir(dir)
}
Expand Down
4 changes: 2 additions & 2 deletions src/shuf/shuf.v
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ fn shuffle_lines(lines []string, settings Settings) []string {
for i in 0 .. new_lines.len {
tmp := new_lines[i]
random := rand.intn(new_lines.len) or {
common.exit_with_error_message(app_name, err.msg)
common.exit_with_error_message(app_name, err.msg())
}
new_lines[i] = new_lines[random]
new_lines[random] = tmp
Expand All @@ -109,7 +109,7 @@ fn shuffle_lines(lines []string, settings Settings) []string {
for i in 0 .. new_lines.len {
tmp := new_lines[i]
random := rand.intn(new_lines.len) or {
common.exit_with_error_message(app_name, err.msg)
common.exit_with_error_message(app_name, err.msg())
}
new_lines[i] = new_lines[random]
new_lines[random] = tmp
Expand Down
2 changes: 1 addition & 1 deletion src/sleep/sleep.v
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ fn main() {
if s := apply_unit(n, unit) {
seconds += s
} else {
eprintln(err.msg)
eprintln(err.msg())
ok = false
}
}
Expand Down
Loading

0 comments on commit f9f0f11

Please sign in to comment.