diff --git a/bin/asset b/bin/asset index 84b3938..a227db0 100755 --- a/bin/asset +++ b/bin/asset @@ -26,8 +26,42 @@ # https://github.com/alces-flight/alces-flight/flight-asset-cli #============================================================================== -# Adds the config onto the front of ARGV -ARGV.unshift File.expand_path('../etc/config.yaml', __dir__) +begin + # Reads the environment setup + ENV['BUNDLE_GEMFILE'] ||= File.join(__FILE__, '../../Gemfile') -load File.join(__dir__, 'asset-with-config') + require 'rubygems' + require 'bundler' + Bundler.setup(:default) + # Loads the config + require_relative '../lib/flight_asset/config' + + # Attempt to enable development mode if requested + if FlightAsset::Config::CACHE.development? + begin + Bundler.setup(:default, :development) + require 'pry' + require 'pry-byebug' + rescue StandardError, LoadError + Bundler.setup(:default) + $stderr.puts "An error occurred when enabling development mode!" + end + end + + # Builds and runs the CLI + require_relative '../lib/flight_asset/cli' + + # Runs the command within the original directory + Dir.chdir(ENV.fetch('FLIGHT_CWD', '.')) do + OpenFlight.set_standard_env rescue nil + FlightAsset::CLI.run!(*ARGV) + end +rescue Interrupt + if Kernel.const_defined?(:Paint) + $stderr.puts "\n#{Paint['WARNING', :underline, :yellow]}: Cancelled by user" + else + $stderr.puts "\nWARNING: Cancelled by user" + end + exit(130) +end diff --git a/bin/asset-with-config b/bin/asset-with-config deleted file mode 100755 index 4fac2a0..0000000 --- a/bin/asset-with-config +++ /dev/null @@ -1,56 +0,0 @@ -#!/usr/bin/env ruby -#============================================================================== -# Copyright (C) 2019-present Alces Flight Ltd. -# -# This file is part of Flight Asset. -# -# This program and the accompanying materials are made available under -# the terms of the Eclipse Public License 2.0 which is available at -# , or alternative license -# terms made available by Alces Flight Ltd - please direct inquiries -# about licensing to licensing@alces-flight.com. -# -# Flight Asset is distributed in the hope that it will be useful, but -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR -# IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS -# OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A -# PARTICULAR PURPOSE. See the Eclipse Public License 2.0 for more -# details. -# -# You should have received a copy of the Eclipse Public License 2.0 -# along with Flight Asset. If not, see: -# -# https://opensource.org/licenses/EPL-2.0 -# -# For more information on Flight Asset, please visit: -# https://github.com/alces-flight/alces-flight/flight-asset-cli -#============================================================================== - -# Sets up bundler -ENV['BUNDLE_GEMFILE'] ||= File.join(__dir__, '../Gemfile') -require 'rubygems' -require 'bundler' -Bundler.setup(:default) - -# Uses the first argument as the config path -args = ARGV.dup -module FlightAsset; end -FlightAsset.const_set('CONFIG_PATH', args.shift) -require_relative '../lib/flight_asset/config' - -# Enables the development mode -if FlightAsset::Config::CACHE.development? - begin - Bundler.setup(:default, :development) - require 'pry' - require 'pry-byebug' - rescue StandardError, LoadError - Bundler.setup(:default) - $stderr.puts "An error occurred when enabling development mode!" - end -end - -# Builds and runs the CLI -require_relative '../lib/flight_asset/cli' -FlightAsset::CLI.run!(*args) -