aboutsummaryrefslogtreecommitdiff
path: root/v_windows/v/vlib/os/args.v
blob: 597637c4e4039148be593fe667e6b7ed6e5f6848 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright (c) 2019-2021 Alexander Medvednikov. All rights reserved.
// 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 {
		cargs = args.clone()
	} 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
}

// args_after returns all os.args, located *before* a specified `cut_word`.
// 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 {
		cargs = args.clone()
	} else {
		cargs << args[0]
		for a in args[1..] {
			if a == cut_word {
				break
			}
			cargs << a
		}
	}
	return cargs
}