From 9c2a72f70c811218124a54cbce3dbabddcd1abaf Mon Sep 17 00:00:00 2001 From: Michael Angerman <1809991+stormasm@users.noreply.github.com> Date: Thu, 17 Feb 2022 12:56:46 -0800 Subject: [PATCH] update flag.nu with more details of how flags work and how to pass data to them (#154) --- engine-q/nu_101/flag.nu | 45 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/engine-q/nu_101/flag.nu b/engine-q/nu_101/flag.nu index 46f74bd..11ea9ce 100644 --- a/engine-q/nu_101/flag.nu +++ b/engine-q/nu_101/flag.nu @@ -27,3 +27,48 @@ def flag [ ] { echo $flag } + +# Write out the flags you entered +def flag_details [myint: int, mystring: string] { + echo "myint is " $myint | str collect + echo "mystring is " $mystring | str collect +} + +# Get the data passed into the flags +def get_flag [ + --test_int(-i): int # The test intlocation + --test_string(-s): string # The test string + ] { + let is_int_empty = ($test_int == $nothing) + let is_string_empty = ($test_string == $nothing) + + let no_int_no_string = ($is_int_empty == $true && $is_string_empty == $true) + let no_int_with_string = ($is_int_empty == $true && $is_string_empty == $false) + let with_int_no_string = ($is_int_empty == $false && $is_string_empty == $true) + let with_int_with_string = ($is_int_empty == $false && $is_string_empty == $false) + + echo 'no int and no string ' $no_int_no_string | str collect + echo 'no int with string ' $no_int_with_string | str collect + echo 'with int and no string ' $with_int_no_string | str collect + echo 'with int and with string ' $with_int_with_string | str collect + + if $no_int_no_string { + (flag_details 1 "blue") + } else if $no_int_with_string { + (flag_details 1 $test_string) + } else if $with_int_no_string { + (flag_details $test_int "blue") + } else if $with_int_with_string { + (flag_details $test_int $test_string) + } + + +} + +# To run this call +# > get_flag +# it will default to int 1 and string blue +# > get_flag -i 2 +# This changes to int 2 and string blue +# > get_flag -i 3 -s green +# This changes to int 3 and string green