File: handle-no-subcommand.diff

package info (click to toggle)
sugarjar 0.0.11-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 392 kB
  • sloc: ruby: 1,266; sh: 75; makefile: 4
file content (30 lines) | stat: -rw-r--r-- 1,041 bytes parent folder | download
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}")