structurizr / cli

A command line utility for Structurizr.
https://docs.structurizr.com/cli
Apache License 2.0
491 stars 75 forks source link

Support running as symlink? #43

Closed jean closed 2 years ago

jean commented 3 years ago

I like to do e.g. jean@X1:~/.local/bin$ ln -s ~/Downloads/structurizr/structurizr.sh so that the command is on my path. This fails with the current script. The following works, but I don't know if it works in all the same places as BASH_SOURCE:

diff --git a/etc/structurizr.sh b/etc/structurizr.sh
index a87c6e8..317fdd8 100755
--- a/etc/structurizr.sh
+++ b/etc/structurizr.sh
@@ -1,3 +1,3 @@
 #!/bin/bash
-SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
+SCRIPT_DIR="$( cd "$( dirname "$(readlink -f "$0")" )" >/dev/null 2>&1 && pwd )"
 java -jar $SCRIPT_DIR/structurizr-cli-1.11.0.jar "$@"

(I'd actually prefer to do stow structurizr (ref) but that works best if the zip contents look like structurizr/{bin,doc,...}.)

MLNW commented 2 years ago

I have been running into the same issue a few times in the past so I would welcome a change that allows symlinking the .sh script out of the box.

simonbrowndotje commented 2 years ago

I'm not a *nix expert I'm afraid, and have tried a few things, but didn't find anything that worked across multiple platforms (e.g. readlink -f doesn't work on my Mac, but readlink does). If you have an example of something that works, please do share. Otherwise, it might be easier to create your own script ... all you need to do is start a named Java application (com.structurizr.cli.StructurizrCliApplication) with parameters.