From 5dba5cfea384c9583555c00346a796885d41e8ec Mon Sep 17 00:00:00 2001 From: Chris Fontenot Date: Mon, 7 Mar 2016 19:17:03 -0600 Subject: [PATCH 1/7] Fixes jamesob/desk#56 adding support for displaying exported environment variables in deskfiles --- desk | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/desk b/desk index 8f25232..0442767 100755 --- a/desk +++ b/desk @@ -185,7 +185,7 @@ cmd_list() { # Usage: desk [options] # Description: List the current desk and any associated aliases. If no desk is being used, display available desks -# --no-format: Use ' - ' to separate alias/function names from their descriptions +# --no-format: Use ' - ' to separate alias/export/function names from their descriptions cmd_current() { if [ -z "$DESK_ENV" ]; then printf "No desk activated.\n\n%s" "$(cmd_list)" @@ -214,7 +214,7 @@ cmd_current() { (( len > longest )) && longest=$len local DOCLINE=$( grep -B 1 -E \ - "^(alias ${NAME}=|(function )?${NAME}( )?\()|function $NAME" "$DESKPATH" \ + "^(alias ${NAME}=|export ${NAME}=|(function )?${NAME}( )?\()|function $NAME" "$DESKPATH" \ | grep "#") if [ -z "$DOCLINE" ]; then @@ -262,11 +262,12 @@ echo_description() { echo "${descline##*Description: }" } -# Echo a list of aliases and functions for a given desk +# Echo a list of aliases, exports, and functions for a given desk get_callables() { local DESKPATH=$1 - grep -E "^(alias |(function )?${FNAME_CHARS}+ ?\()|function $NAME" "$DESKPATH" \ + grep -E "^(alias |export |(function )?${FNAME_CHARS}+ ?\()|function $NAME" "$DESKPATH" \ | sed 's/alias \([^= ]*\)=.*/\1/' \ + | sed 's/export \([^= ]*\)=.*/\1/' \ | sed -E "s/(function )?(${FNAME_CHARS}+) ?\(\).*/\2/" \ | sed -E "s/function (${FNAME_CHARS}+).*/\1/" } From 0e364e8291a340945aaf716b9b5e295a78333660 Mon Sep 17 00:00:00 2001 From: Chris Fontenot Date: Tue, 15 Mar 2016 11:07:19 -0500 Subject: [PATCH 2/7] Adding test scenarios for displaying exported variables This commit includes two file updates for testing the new feature as requested in jamesob/desk#56. The example hello deskfile now has a variable set called MyName with a value "James" and the runtests shell script includes a test to echo the value of that variable. This test proves that the variable is exported as expected from the deskfile and is retrievable as expected. Still #todo includes a test that lists the description of the deskfile and looks for that variable to be listed along with the aliases and functions. --- examples/hello.sh | 3 +++ test/run_tests.sh | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/examples/hello.sh b/examples/hello.sh index 9083a8f..b7ce5ae 100644 --- a/examples/hello.sh +++ b/examples/hello.sh @@ -9,3 +9,6 @@ hi() { # Use if you're from Texas. alias howdy="echo howdy y\'all" +# Why should I always type my name +export MyName="James" + diff --git a/test/run_tests.sh b/test/run_tests.sh index 4013e9e..9ca70c4 100755 --- a/test/run_tests.sh +++ b/test/run_tests.sh @@ -129,6 +129,10 @@ RAN=$(desk run hello 'hi j') echo "$RAN" | grep 'hi, j!' >/dev/null ensure $? "Run in desk 'hello' didn't work with hi function" +RAN=$(desk run hello 'echo $MyName') +echo "$RAN" | grep 'James' >/dev/null +ensure $? "Run in desk 'hello' didn't work with MyName exported variable" + ## `desk go` RAN=$(desk go example-project/Deskfile -c 'desk ; exit') From ea2da724f4c2d1e353f0b8017d5c279e63907435 Mon Sep 17 00:00:00 2001 From: Chris Fontenot Date: Tue, 15 Mar 2016 16:21:59 -0500 Subject: [PATCH 3/7] Added test for displaying exported variable in current desk file I've added a test to make sure the MyName variable in the newly modified hello Deskfile is listed in the output when just issuing the desk command (list current desk and any associated aliases) --- test/run_tests.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/run_tests.sh b/test/run_tests.sh index 9ca70c4..f7db56d 100755 --- a/test/run_tests.sh +++ b/test/run_tests.sh @@ -121,6 +121,12 @@ ensure $? "Desk current terraform missing apply" echo "$CURRENT" | grep 'config - Set up terraform config: ' >/dev/null ensure $? "Desk current terraform missing config" +# testing for exported variables +CURRENT=$(DESK_ENV=$HOME/.desk/desks/hello.sh desk) +echo "$CURRENT" | grep 'MyName Why should I always type my name' >/dev/null +ensure $? "Desk current hello missing exported environment variable" + + RAN=$(desk run hello 'howdy james!') echo "$RAN" | grep 'howdy y'"'"'all james!' >/dev/null ensure $? "Run in desk 'hello' didn't work with howdy alias" From 95e3d0c2f1311329d4c0e50458a6685897658ffd Mon Sep 17 00:00:00 2001 From: Chris Fontenot Date: Tue, 15 Mar 2016 17:10:22 -0500 Subject: [PATCH 4/7] added a new line to see and troubleshoot the test --- test/run_tests.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/run_tests.sh b/test/run_tests.sh index f7db56d..cbf8368 100755 --- a/test/run_tests.sh +++ b/test/run_tests.sh @@ -122,6 +122,9 @@ echo "$CURRENT" | grep 'config - Set up terraform config: ' >/dev/nu ensure $? "Desk current terraform missing config" # testing for exported variables +ISITTHERE=$(less $HOME/.desk/desks/hello.sh) +echo "$ISITTHERE" | grep -B 1 export + CURRENT=$(DESK_ENV=$HOME/.desk/desks/hello.sh desk) echo "$CURRENT" | grep 'MyName Why should I always type my name' >/dev/null ensure $? "Desk current hello missing exported environment variable" From 415e701eacf8f9d5ab9da05358b5f81ddc0358ac Mon Sep 17 00:00:00 2001 From: Chris Fontenot Date: Tue, 15 Mar 2016 17:18:38 -0500 Subject: [PATCH 5/7] echoing to stdout to track down my failed test in TravisCI --- test/run_tests.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/test/run_tests.sh b/test/run_tests.sh index cbf8368..75a019c 100755 --- a/test/run_tests.sh +++ b/test/run_tests.sh @@ -126,6 +126,7 @@ ISITTHERE=$(less $HOME/.desk/desks/hello.sh) echo "$ISITTHERE" | grep -B 1 export CURRENT=$(DESK_ENV=$HOME/.desk/desks/hello.sh desk) +echo "$CURRENT" echo "$CURRENT" | grep 'MyName Why should I always type my name' >/dev/null ensure $? "Desk current hello missing exported environment variable" From 8a10885e5578a7f63c2feb427d45c257ce4710eb Mon Sep 17 00:00:00 2001 From: Chris Fontenot Date: Tue, 15 Mar 2016 17:22:29 -0500 Subject: [PATCH 6/7] reduced number of space characters in test string --- test/run_tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/run_tests.sh b/test/run_tests.sh index 75a019c..391e152 100755 --- a/test/run_tests.sh +++ b/test/run_tests.sh @@ -127,7 +127,7 @@ echo "$ISITTHERE" | grep -B 1 export CURRENT=$(DESK_ENV=$HOME/.desk/desks/hello.sh desk) echo "$CURRENT" -echo "$CURRENT" | grep 'MyName Why should I always type my name' >/dev/null +echo "$CURRENT" | grep 'MyName Why should I always type my name' >/dev/null ensure $? "Desk current hello missing exported environment variable" From 2e00f5cf44ca64dddec0e3940f5f7c3bb2d33e43 Mon Sep 17 00:00:00 2001 From: Chris Fontenot Date: Wed, 16 Mar 2016 14:52:45 -0500 Subject: [PATCH 7/7] removed cruft from test code for exported variable --- test/run_tests.sh | 4 ---- 1 file changed, 4 deletions(-) diff --git a/test/run_tests.sh b/test/run_tests.sh index 391e152..a2c531e 100755 --- a/test/run_tests.sh +++ b/test/run_tests.sh @@ -122,11 +122,7 @@ echo "$CURRENT" | grep 'config - Set up terraform config: ' >/dev/nu ensure $? "Desk current terraform missing config" # testing for exported variables -ISITTHERE=$(less $HOME/.desk/desks/hello.sh) -echo "$ISITTHERE" | grep -B 1 export - CURRENT=$(DESK_ENV=$HOME/.desk/desks/hello.sh desk) -echo "$CURRENT" echo "$CURRENT" | grep 'MyName Why should I always type my name' >/dev/null ensure $? "Desk current hello missing exported environment variable"