Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions bin/ws_go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

if [ "$#" -eq 0 ]; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Command line parsing should be improved - looks brittle to me. Also, should (optionally) allow -F as all other ws_* tools

echo "Usage: ws_go workspace [file-system]"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

usage info should go into separate function usage()

return
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use exit instead of return

Suggested change
return
exit 1

fi

WS_OPT=
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you wanne WS_OPT to be later?

Suggested change
WS_OPT=
WS_OPT=""

or

Suggested change
WS_OPT=
WS_OPT=()

if [ "$#" -lt 2 ]; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Command line parsing should be improved - looks brittle to me. Second place.

NUMWS=`ws_find $1 | wc -l`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assign command line arguments to variables - what is $1 here in this scope?

if [[ ${NUMWS} -gt 1 ]]; then
NUMFS=`ws_list | grep "^ filesystem name : " | cut -d ":" -f2 | cut -d" " -f2 | sort -h | uniq | wc -l`
FSNAMES=`ws_list | grep "^ filesystem name : " | cut -d ":" -f2 | cut -d" " -f2 | sort -h | uniq | tr '\n' ' '`
Comment on lines +12 to +13
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

calling ws_list multiple times - use cached output.
The parsing also looks complex, involving many pipes and different commands.

echo ${NUMFS} "filesystems are available:" ${FSNAMES}
echo "Please run this command with the file-system name"
return;
fi
else
WS_OPT+=" -F "
WS_OPT+=`echo ${2}`
Comment on lines +19 to +20
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not simply

Suggested change
WS_OPT+=" -F "
WS_OPT+=`echo ${2}`
WS_OPT+=" -F $2"

fi

if ws_list ${WS_OPT} | grep "^id: " | cut -d":" -f2 | cut -d" " -f2 | grep -q $1; then
cd `ws_find ${WS_OPT} $1`
else
Comment on lines +23 to +25
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why so over complicated. Rel on ws_find and do not call ws_list again...

Suggested change
if ws_list ${WS_OPT} | grep "^id: " | cut -d":" -f2 | cut -d" " -f2 | grep -q $1; then
cd `ws_find ${WS_OPT} $1`
else
ws_dir=$(ws_find ${WS_OPT} $1)
if [[ -d $ws_dir ]]; then
cd "$ws_dir"
else

echo "Workspace $1 not found! Available workspaces are:"
ws_list ${WS_OPT} | grep "^id: " | cut -d":" -f2
fi
Comment on lines +27 to +28
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was obviously an error

Suggested change
ws_list ${WS_OPT} | grep "^id: " | cut -d":" -f2
fi
ws_list ${WS_OPT} | grep "^id: " | cut -d":" -f2
exit 1
fi