1
Fork 0
mirror of https://github.com/RGBCube/nu_scripts synced 2025-08-02 07:07:46 +00:00

update flag.nu with more details of how flags work and how to pass data to them (#154)

This commit is contained in:
Michael Angerman 2022-02-17 12:56:46 -08:00 committed by GitHub
parent f205b26156
commit 9c2a72f70c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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