Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix binstub #541

Merged
merged 1 commit into from
Apr 25, 2022
Merged
Show file tree
Hide file tree
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
22 changes: 15 additions & 7 deletions lib/steep/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ def process_vendor

def process_binstub
path = Pathname("bin/steep")
root_path = Pathname.pwd
force = false

OptionParser.new do |opts|
Expand All @@ -227,21 +228,28 @@ def process_binstub
path = Pathname(v)
end

opts.on("--root=PATH", "The repository root path (defaults to `.`)") do |v|
root_path = (Pathname.pwd + v).cleanpath
end

opts.on("--[no-]force", "Overwrite file (defaults to false)") do
force = true
end
end.parse!(argv)

path.parent.mkpath
binstub_path = (Pathname.pwd + path).cleanpath
bindir_path = binstub_path.parent

bindir_path.mkpath

gemfile_path =
if defined?(Bundler)
Bundler.default_gemfile.relative_path_from(Pathname.pwd + path.parent)
Bundler.default_gemfile.relative_path_from(bindir_path)
else
Pathname("../Gemfile")
end

if path.file?
if binstub_path.file?
if force
stdout.puts Rainbow("#{path} already exists. Overwriting...").yellow
else
Expand All @@ -255,23 +263,23 @@ def process_binstub

BINSTUB_DIR=$(cd $(dirname $0); pwd)
GEMFILE=$(readlink -f ${BINSTUB_DIR}/#{gemfile_path})
GEMFILE_DIR=$(dirname ${GEMFILE})
ROOT_DIR=$(readlink -f ${BINSTUB_DIR}/#{root_path.relative_path_from(bindir_path)})

STEEP="bundle exec --gemfile=${GEMFILE} steep"

if type "rbenv" > /dev/null 2>&1; then
STEEP="rbenv exec ${STEEP}"
else
if type "rvm" > /dev/null 2>&1; then
STEEP="rvm ${GEMFILE_DIR} do ${STEEP}"
STEEP="rvm ${ROOT_DIR} do ${STEEP}"
fi
fi

exec $STEEP $@
TEMPLATE

path.write(template)
path.chmod(0755)
binstub_path.write(template)
binstub_path.chmod(0755)

stdout.puts Rainbow("Successfully generated executable #{path} 🎉").blue

Expand Down
8 changes: 6 additions & 2 deletions test/cli_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -558,20 +558,24 @@ def test_binstub_generate

BINSTUB_DIR=$(cd $(dirname $0); pwd)
GEMFILE=$(readlink -f ${BINSTUB_DIR}/../Gemfile)
GEMFILE_DIR=$(dirname ${GEMFILE})
ROOT_DIR=$(readlink -f ${BINSTUB_DIR}/..)

STEEP="bundle exec --gemfile=${GEMFILE} steep"

if type "rbenv" > /dev/null 2>&1; then
STEEP="rbenv exec ${STEEP}"
else
if type "rvm" > /dev/null 2>&1; then
STEEP="rvm ${GEMFILE_DIR} do ${STEEP}"
STEEP="rvm ${ROOT_DIR} do ${STEEP}"
fi
fi

exec $STEEP $@
EOF

assert_equal <<EOM, sh!("bin/steep", "version")
#{Steep::VERSION}
EOM
end
end
end
Expand Down