2022-01-04 12:21:08 +03:00
|
|
|
// Copyright (c) 2019-2022 Alexander Medvednikov. All rights reserved.
|
2020-12-06 13:42:56 +03:00
|
|
|
// Use of this source code is governed by an MIT license
|
|
|
|
// that can be found in the LICENSE file.
|
|
|
|
module os
|
|
|
|
|
|
|
|
// args_after returns all os.args, located *after* a specified `cut_word`.
|
|
|
|
// When `cut_word` is NOT found, os.args is returned unmodified.
|
|
|
|
pub fn args_after(cut_word string) []string {
|
|
|
|
if args.len == 0 {
|
|
|
|
return []string{}
|
|
|
|
}
|
|
|
|
mut cargs := []string{}
|
|
|
|
if cut_word !in args {
|
2020-12-20 12:42:46 +03:00
|
|
|
cargs = args.clone()
|
2020-12-06 13:42:56 +03:00
|
|
|
} else {
|
|
|
|
mut found := false
|
|
|
|
cargs << args[0]
|
|
|
|
for a in args[1..] {
|
|
|
|
if a == cut_word {
|
|
|
|
found = true
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if !found {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
cargs << a
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return cargs
|
|
|
|
}
|
|
|
|
|
2021-09-17 20:55:16 +03:00
|
|
|
// args_before returns all os.args, located *before* a specified `cut_word`.
|
2020-12-06 13:42:56 +03:00
|
|
|
// When `cut_word` is NOT found, os.args is returned unmodified.
|
|
|
|
pub fn args_before(cut_word string) []string {
|
|
|
|
if args.len == 0 {
|
|
|
|
return []string{}
|
|
|
|
}
|
|
|
|
mut cargs := []string{}
|
|
|
|
if cut_word !in args {
|
2020-12-20 12:42:46 +03:00
|
|
|
cargs = args.clone()
|
2020-12-06 13:42:56 +03:00
|
|
|
} else {
|
|
|
|
cargs << args[0]
|
|
|
|
for a in args[1..] {
|
|
|
|
if a == cut_word {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
cargs << a
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return cargs
|
|
|
|
}
|