diff options
author | Indrajith K L | 2022-12-03 17:00:20 +0530 |
---|---|---|
committer | Indrajith K L | 2022-12-03 17:00:20 +0530 |
commit | f5c4671bfbad96bf346bd7e9a21fc4317b4959df (patch) | |
tree | 2764fc62da58f2ba8da7ed341643fc359873142f /v_windows/v/vlib/os/args.v | |
download | cli-tools-windows-master.tar.gz cli-tools-windows-master.tar.bz2 cli-tools-windows-master.zip |
Diffstat (limited to 'v_windows/v/vlib/os/args.v')
-rw-r--r-- | v_windows/v/vlib/os/args.v | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/v_windows/v/vlib/os/args.v b/v_windows/v/vlib/os/args.v new file mode 100644 index 0000000..597637c --- /dev/null +++ b/v_windows/v/vlib/os/args.v @@ -0,0 +1,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 +} |