Nathanial
Nathanial

Reputation: 2257

How to run lein from another directory (without cd to project dir)?

Supposing my lein project is located in /some/location/project and my current location is /another/location/ how can I run lein build without changing to project location cd /some/location/project?

For example, in maven

mvn -f /path/to/pom.xml

Upvotes: 3

Views: 1220

Answers (1)

Mars
Mars

Reputation: 8854

As far as I can tell lein doesn't have an option like this. You have to be in the directory. (Perhaps someone else will correct me.) However, you could write a shell script that does what you want. For example, in a unix that provides the getopts utility, you could use the following script, which might be called "leinthere":

#!/bin/sh

if getopts f: option; then
    # user supplied -f
    if [ -d "$OPTARG" ]; then
        # user also supplied name of a real dir, now in $OPTARG
        cd "$OPTARG"
        shift 2 # get rid of -f and the dir name
    else
        # user supplied -f, but not a real dir name
        echo "usage: $0 [-f project-dir] [lein args]"
        exit 1
    fi
fi

# now just run lein in the normal way:
lein "$@"

Upvotes: 1

Related Questions