1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
Description: Handle no-subcommand better
If there's no subcommand detected, print out help instead of crashing.
Author: Phil Dibowitz <phil@ipom.com>
Origin: upstream, https://github.com/jaymzh/sugarjar/pull/125
Bug: https://github.com/jaymzh/sugarjar/issues/123
Applied-Upstream: https://github.com/jaymzh/sugarjar/commit/33533662da9ef9ee270cd247105831a40838ba78
Last-Update: 2022-10-14
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
--- a/bin/sj
+++ b/bin/sj
@@ -246,7 +246,9 @@ else
end
end
-if ARGV.empty?
+subcommand = argv_copy.reject { |x| x.start_with?('-') }.first
+
+if ARGV.empty? || !subcommand
puts parser
exit
end
@@ -257,7 +259,6 @@ options = config.merge(options)
SugarJar::Log.level = options['log_level'].to_sym if options['log_level']
sj = SugarJar::Commands.new(options)
-subcommand = argv_copy.reject { |x| x.start_with?('-') }.first
is_valid_command = valid_commands.include?(subcommand.to_sym)
argv_copy.delete(subcommand)
SugarJar::Log.debug("subcommand is #{subcommand}")
|