1 | // Copyright (c) 2019-2023 Alexander Medvednikov. All rights reserved. |
2 | // Use of this source code is governed by an MIT license |
3 | // that can be found in the LICENSE file. |
4 | module os |
5 | |
6 | // args_after returns all os.args, located *after* a specified `cut_word`. |
7 | // When `cut_word` is NOT found, os.args is returned unmodified. |
8 | pub fn args_after(cut_word string) []string { |
9 | if args.len == 0 { |
10 | return []string{} |
11 | } |
12 | mut cargs := []string{} |
13 | if cut_word !in args { |
14 | cargs = args.clone() |
15 | } else { |
16 | mut found := false |
17 | cargs << args[0] |
18 | for a in args[1..] { |
19 | if a == cut_word { |
20 | found = true |
21 | continue |
22 | } |
23 | if !found { |
24 | continue |
25 | } |
26 | cargs << a |
27 | } |
28 | } |
29 | return cargs |
30 | } |
31 | |
32 | // args_before returns all os.args, located *before* a specified `cut_word`. |
33 | // When `cut_word` is NOT found, os.args is returned unmodified. |
34 | pub fn args_before(cut_word string) []string { |
35 | if args.len == 0 { |
36 | return []string{} |
37 | } |
38 | mut cargs := []string{} |
39 | if cut_word !in args { |
40 | cargs = args.clone() |
41 | } else { |
42 | cargs << args[0] |
43 | for a in args[1..] { |
44 | if a == cut_word { |
45 | break |
46 | } |
47 | cargs << a |
48 | } |
49 | } |
50 | return cargs |
51 | } |